1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.web

File ViewAction.java

 

Coverage histogram

../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

4
19
3
1
87
44
7
0.37
6.33
3
2.33

Classes

Class Line # Actions
ViewAction 34 19 0% 7 8
0.692307769.2%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.web;
21   
22    import java.io.IOException;
23   
24    import com.xpn.xwiki.XWikiContext;
25    import com.xpn.xwiki.XWikiException;
26    import com.xpn.xwiki.doc.XWikiDocument;
27   
28    /**
29    * Action called when the request URL has the "/view/" string in its path (this is configured in
30    * <code>struts-config.xml</code>. It means the request is to display a page in view mode.
31    *
32    * @version $Id: d0676744681c2061e32c7c597e413f6782ff385b $
33    */
 
34    public class ViewAction extends XWikiAction
35    {
36    /**
37    * The identifier of the view action.
38    */
39    public static final String VIEW_ACTION = "view";
40   
41    /**
42    * Default constructor.
43    */
 
44  29 toggle public ViewAction()
45    {
46  29 this.waitForXWikiInitialization = false;
47  29 this.handleRedirectObject = true;
48    }
49   
 
50  604 toggle @Override
51    public boolean action(XWikiContext context) throws XWikiException
52    {
53  604 boolean shouldRender = true;
54   
55  604 context.put("action", VIEW_ACTION);
56   
57    // Redirect to the ViewrevAction is the URL has a rev parameter (when the user asks to
58    // view a specific revision of a document).
59  604 XWikiRequest request = context.getRequest();
60  604 String rev = request.getParameter("rev");
61  604 if (rev != null) {
62  0 String url = context.getDoc().getURL("viewrev", request.getQueryString(), context);
63  0 try {
64  0 context.getResponse().sendRedirect(url);
65    } catch (IOException e) {
66  0 e.printStackTrace();
67    }
68  0 shouldRender = false;
69    }
70   
71  604 return shouldRender;
72    }
73   
 
74  604 toggle @Override
75    public String render(XWikiContext context) throws XWikiException
76    {
77  604 handleRevision(context);
78  604 XWikiDocument doc = (XWikiDocument) context.get("doc");
79   
80  604 String defaultTemplate = doc.getDefaultTemplate();
81  604 if ((defaultTemplate != null) && (!defaultTemplate.equals(""))) {
82  0 return defaultTemplate;
83    } else {
84  604 return VIEW_ACTION;
85    }
86    }
87    }