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

File RightsManagerRightsApi.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart2.png
81% of files have more coverage

Code metrics

0
10
3
1
106
37
4
0.4
3.33
3
1.33

Classes

Class Line # Actions
RightsManagerRightsApi 41 10 0% 4 11
0.1538461615.4%
 

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   
21    package com.xpn.xwiki.plugin.rightsmanager;
22   
23    import java.text.MessageFormat;
24   
25    import org.slf4j.Logger;
26    import org.slf4j.LoggerFactory;
27   
28    import com.xpn.xwiki.XWikiContext;
29    import com.xpn.xwiki.XWikiException;
30    import com.xpn.xwiki.api.Api;
31    import com.xpn.xwiki.api.Document;
32    import com.xpn.xwiki.doc.XWikiDocument;
33   
34    /**
35    * API for managing rights and inheritance.
36    *
37    * @version $Id: 932f82d0ca955da658412189293509a795f31a88 $
38    * @since 1.1.2
39    * @since 1.2M2
40    */
 
41    public class RightsManagerRightsApi extends Api
42    {
43    /**
44    * Field name of the last error code inserted in context.
45    */
46    public static final String CONTEXT_LASTERRORCODE = RightsManagerPluginApi.CONTEXT_LASTERRORCODE;
47   
48    /**
49    * Field name of the last api exception inserted in context.
50    */
51    public static final String CONTEXT_LASTEXCEPTION = RightsManagerPluginApi.CONTEXT_LASTEXCEPTION;
52   
53    /**
54    * The logging toolkit.
55    */
56    protected static final Logger LOGGER = LoggerFactory.getLogger(RightsManagerRightsApi.class);
57   
58    /**
59    * Create an instance of RightsManageRightsApi.
60    *
61    * @param context the XWiki context.
62    */
 
63  22 toggle public RightsManagerRightsApi(XWikiContext context)
64    {
65  22 super(context);
66    }
67   
68    /**
69    * Log error and register {@link #CONTEXT_LASTERRORCODE} and {@link #CONTEXT_LASTEXCEPTION}.
70    *
71    * @param comment the comment to use with {@link #LOGGER}.
72    * @param e the exception.
73    */
 
74  0 toggle private void logError(String comment, XWikiException e)
75    {
76  0 LOGGER.error(comment, e);
77   
78  0 this.context.put(CONTEXT_LASTERRORCODE, e.getCode());
79  0 this.context.put(CONTEXT_LASTEXCEPTION, e);
80    }
81   
82    // Inheritance
83   
84    /**
85    * Get the document containing inherited rights of provided document.
86    *
87    * @param spaceOrPage the space of page where to get XWikiRights. If null get wiki rights.
88    * @return the document containing inherited rights of provided document.
89    * @throws XWikiException error when browsing rights preferences.
90    */
 
91  0 toggle public Document getParentPreference(String spaceOrPage) throws XWikiException
92    {
93  0 Document parent = null;
94   
95  0 try {
96  0 XWikiDocument xdoc = RightsManager.getInstance().getParentPreference(spaceOrPage, this.context);
97   
98  0 parent = convert(xdoc);
99    } catch (RightsManagerException e) {
100  0 logError(
101    MessageFormat.format("Try to get parent rights preference for [{0}]", new Object[] { spaceOrPage }), e);
102    }
103   
104  0 return parent;
105    }
106    }