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

File JsResourceSkinExtensionPlugin.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

4
11
5
1
94
39
7
0.64
2.2
5
1.4

Classes

Class Line # Actions
JsResourceSkinExtensionPlugin 33 11 0% 7 20
0.00%
 

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.plugin.skinx;
21   
22    import org.apache.commons.lang3.BooleanUtils;
23    import org.apache.commons.lang3.StringUtils;
24   
25    import com.xpn.xwiki.XWikiContext;
26   
27    /**
28    * Skin Extension plugin that allows pulling javascript files from JAR resources.
29    *
30    * @version $Id: f75fe95b961bbf1e992c02593fa32f602bcfa221 $
31    * @since 1.3
32    */
 
33    public class JsResourceSkinExtensionPlugin extends AbstractResourceSkinExtensionPlugin
34    {
35    /**
36    * The name of the preference (in the configuration file) specifying what is the default value of the defer, in case
37    * nothing is specified in the parameters of this extension.
38    */
39    public static final String DEFER_DEFAULT_PARAM = "xwiki.plugins.skinx.deferred.default";
40   
41    /**
42    * XWiki plugin constructor.
43    *
44    * @param name The name of the plugin, which can be used for retrieving the plugin API from velocity. Unused.
45    * @param className The canonical classname of the plugin. Unused.
46    * @param context The current request context.
47    * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
48    */
 
49  0 toggle public JsResourceSkinExtensionPlugin(String name, String className, XWikiContext context)
50    {
51  0 super(name, className, context);
52    }
53   
 
54  0 toggle @Override
55    public String getName()
56    {
57  0 return "jsrx";
58    }
59   
 
60  0 toggle @Override
61    protected String getAction()
62    {
63  0 return "jsx";
64    }
65   
 
66  0 toggle @Override
67    protected String generateLink(String url, String resourceName, XWikiContext context)
68    {
69  0 StringBuilder result = new StringBuilder("<script type='text/javascript' src='").append(url).append("'");
70    // check if js should be deferred, defaults to the preference configured in the cfg file, which defaults to true
71  0 String defaultDeferString = context.getWiki().Param(DEFER_DEFAULT_PARAM);
72  0 Boolean defaultDefer = (!StringUtils.isEmpty(defaultDeferString)) ? Boolean.valueOf(defaultDeferString) : true;
73  0 if (BooleanUtils.toBooleanDefaultIfNull((Boolean) getParameter("defer", resourceName, context), defaultDefer)) {
74  0 result.append(" defer='defer'");
75    }
76  0 result.append("></script>\n");
77  0 return result.toString();
78    }
79   
80    /**
81    * {@inheritDoc}
82    * <p>
83    * We must override this method since the plugin manager only calls it for classes that provide their own
84    * implementation, and not an inherited one.
85    * </p>
86    *
87    * @see AbstractSkinExtensionPlugin#endParsing(String, XWikiContext)
88    */
 
89  0 toggle @Override
90    public String endParsing(String content, XWikiContext context)
91    {
92  0 return super.endParsing(content, context);
93    }
94    }