1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.web

File ViewAction.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
41% 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 3
0.8846153688.5%
 

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  38 toggle public ViewAction()
45    {
46  38 this.waitForXWikiInitialization = false;
47  38 this.handleRedirectObject = true;
48    }
49   
 
50  12005 toggle @Override
51    public boolean action(XWikiContext context) throws XWikiException
52    {
53  12005 boolean shouldRender = true;
54   
55  12005 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  12005 XWikiRequest request = context.getRequest();
60  12005 String rev = request.getParameter("rev");
61  12005 if (rev != null) {
62  3 String url = context.getDoc().getURL("viewrev", request.getQueryString(), context);
63  3 try {
64  3 context.getResponse().sendRedirect(url);
65    } catch (IOException e) {
66  0 e.printStackTrace();
67    }
68  3 shouldRender = false;
69    }
70   
71  12005 return shouldRender;
72    }
73   
 
74  12002 toggle @Override
75    public String render(XWikiContext context) throws XWikiException
76    {
77  12002 handleRevision(context);
78  12002 XWikiDocument doc = (XWikiDocument) context.get("doc");
79   
80  12002 String defaultTemplate = doc.getDefaultTemplate();
81  12002 if ((defaultTemplate != null) && (!defaultTemplate.equals(""))) {
82  0 return defaultTemplate;
83    } else {
84  12002 return VIEW_ACTION;
85    }
86    }
87    }