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

File JsSkinFileExtensionPlugin.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
19
7
1
142
62
11
0.58
2.71
7
1.57

Classes

Class Line # Actions
JsSkinFileExtensionPlugin 39 19 0% 11 1
0.970588297.1%
 

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.skinx;
22   
23    import java.util.Collections;
24    import java.util.Set;
25   
26    import org.apache.commons.lang3.BooleanUtils;
27    import org.apache.commons.lang3.StringUtils;
28   
29    import com.xpn.xwiki.XWikiContext;
30    import com.xpn.xwiki.api.Api;
31    import com.xpn.xwiki.plugin.XWikiPluginInterface;
32   
33    /**
34    * Javascript Skin File Extension plugin to use js files from the skin.
35    *
36    * @version $Id: a0f812a51b5837bccbad37a095f92cbdee0def40 $
37    * @since 1.6
38    */
 
39    public class JsSkinFileExtensionPlugin extends AbstractSkinExtensionPlugin
40    {
41    /**
42    * The identifier for this plugin; used for accessing the plugin from velocity, and as the action returning the
43    * extension content.
44    */
45    public static final String PLUGIN_NAME = "jsfx";
46   
47    /**
48    * The name of the preference (in the configuration file) specifying what is the default value of the defer, in case
49    * nothing is specified in the parameters of this extension.
50    */
51    public static final String DEFER_DEFAULT_PARAM = "xwiki.plugins.skinx.deferred.default";
52   
53    /**
54    * XWiki plugin constructor.
55    *
56    * @param name The name of the plugin, which can be used for retrieving the plugin API from velocity. Unused.
57    * @param className The canonical classname of the plugin. Unused.
58    * @param context The current request context.
59    * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
60    */
 
61  32 toggle public JsSkinFileExtensionPlugin(String name, String className, XWikiContext context)
62    {
63  32 super(name, className, context);
64    }
65   
 
66  10589 toggle @Override
67    public String getName()
68    {
69  10588 return PLUGIN_NAME;
70    }
71   
 
72  10525 toggle @Override
73    public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context)
74    {
75  10525 return new SkinFileExtensionPluginApi((AbstractSkinExtensionPlugin) plugin, context);
76    }
77   
 
78  9444 toggle @Override
79    public String getLink(String filename, XWikiContext context)
80    {
81  9443 boolean forceSkinAction = BooleanUtils.toBoolean((Boolean) getParameter("forceSkinAction", filename, context));
82  9443 StringBuilder result = new StringBuilder("<script type='text/javascript' src='");
83  9446 result.append(context.getWiki().getSkinFile(filename, forceSkinAction, context));
84  9440 if (forceSkinAction) {
85  7263 String parameters = StringUtils.removeStart(parametersAsQueryString(filename, context), "&amp;");
86  7258 if (!StringUtils.isEmpty(parameters)) {
87  3426 result.append("?").append(parameters);
88    }
89    }
90    // check if js should be deferred, defaults to the preference configured in the cfg file, which defaults to true
91  9440 String defaultDeferString = context.getWiki().Param(DEFER_DEFAULT_PARAM);
92  9445 Boolean defaultDefer = (!StringUtils.isEmpty(defaultDeferString)) ? Boolean.valueOf(defaultDeferString) : true;
93  9446 if (BooleanUtils.toBooleanDefaultIfNull((Boolean) getParameter("defer", filename, context), defaultDefer)) {
94  7321 result.append("' defer='defer");
95    }
96  9444 result.append("'></script>\n");
97  9445 return result.toString();
98    }
99   
100    /**
101    * {@inheritDoc}
102    * <p>
103    * We must override this method since the plugin manager only calls it for classes that provide their own
104    * implementation, and not an inherited one.
105    * </p>
106    *
107    * @see AbstractSkinExtensionPlugin#endParsing(String, XWikiContext)
108    */
 
109  6891 toggle @Override
110    public String endParsing(String content, XWikiContext context)
111    {
112  6893 return super.endParsing(content, context);
113    }
114   
115    /**
116    * {@inheritDoc}
117    * <p>
118    * There is no support for always used skinfile-based extensions.
119    * </p>
120    *
121    * @see AbstractSkinExtensionPlugin#getAlwaysUsedExtensions(XWikiContext)
122    */
 
123  6893 toggle @Override
124    public Set<String> getAlwaysUsedExtensions(XWikiContext context)
125    {
126  6891 return Collections.emptySet();
127    }
128   
129    /**
130    * {@inheritDoc}
131    * <p>
132    * Not supported for skinfile-based extensions.
133    * </p>
134    *
135    * @see com.xpn.xwiki.plugin.skinx.AbstractSkinExtensionPlugin#hasPageExtensions(com.xpn.xwiki.XWikiContext)
136    */
 
137  6892 toggle @Override
138    public boolean hasPageExtensions(XWikiContext context)
139    {
140  6893 return false;
141    }
142    }