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

File PluginApi.java

 

Coverage histogram

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

Code metrics

2
7
4
1
91
28
5
0.71
1.75
4
1.25

Classes

Class Line # Actions
PluginApi 35 7 0% 5 11
0.1538461615.4%
 

Contributing tests

This file is covered by 4 tests. .

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.plugin;
21   
22    import com.xpn.xwiki.XWikiContext;
23    import com.xpn.xwiki.api.Api;
24   
25    /**
26    * Base class for all plugin APIs. API Objects are the Java Objects that can be manipulated from Velocity or Groovy
27    * scripts in XWiki documents. They wrap around a fully functional and privileged Plugin object, and forward safe calls
28    * to that object.
29    *
30    * @param <T> The type of the internal plugin.
31    * @version $Id: c559897b350c526e2b37836af79d90fa6071c9e5 $
32    * @deprecated the plugin technology is deprecated, consider rewriting as components
33    */
34    @Deprecated
 
35    public class PluginApi<T extends XWikiPluginInterface> extends Api
36    {
37    /**
38    * The inner plugin object. API calls are usually forwarded to this object.
39    */
40    private T plugin;
41   
42    /**
43    * API constructor. The API must know the plugin object it wraps, and the request context.
44    *
45    * @param plugin The wrapped plugin object.
46    * @param context Context of the request.
47    */
 
48  0 toggle public PluginApi(T plugin, XWikiContext context)
49    {
50  0 super(context);
51  0 setPlugin(plugin);
52    }
53   
54    /**
55    * Return the inner plugin object. This method is only for the plugin API's internal use, and should not be exposed
56    * to scripting languages. It is an XWiki practice to expose all the functionality using an API, and allow access to
57    * the internal objects only to users with Programming Rights.
58    *
59    * @return The wrapped plugin object.
60    * @since 1.3RC1
61    */
 
62  21731 toggle protected T getProtectedPlugin()
63    {
64  21731 return this.plugin;
65    }
66   
67    /**
68    * Return the inner plugin object, if the user has the required programming rights.
69    *
70    * @return The wrapped plugin object.
71    * @since 1.3RC1
72    */
 
73  0 toggle public T getInternalPlugin()
74    {
75  0 if (hasProgrammingRights()) {
76  0 return this.plugin;
77    }
78  0 return null;
79    }
80   
81    /**
82    * Set the inner plugin object.
83    *
84    * @param plugin The wrapped plugin object.
85    */
86    // TODO: Is this really needed? The inner plugin should not be changed.
 
87  0 toggle public void setPlugin(T plugin)
88    {
89  0 this.plugin = plugin;
90    }
91    }