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

File CssSkinExtensionPlugin.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
9
6
1
116
45
7
0.78
1.5
6
1.17

Classes

Class Line # Actions
CssSkinExtensionPlugin 33 9 0% 7 4
0.764705976.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.plugin.skinx;
21   
22    import org.xwiki.model.reference.DocumentReference;
23    import org.xwiki.model.reference.LocalDocumentReference;
24   
25    import com.xpn.xwiki.XWikiContext;
26   
27    /**
28    * Skin Extension plugin that allows pulling CSS code stored inside wiki documents as
29    * <code>XWiki.StyleSheetExtension</code> objects.
30    *
31    * @version $Id: 2741d0c07e72e0da66a59743567c8091a5308ee2 $
32    */
 
33    public class CssSkinExtensionPlugin extends AbstractDocumentSkinExtensionPlugin
34    {
35    /** The name of the XClass storing the code for this type of extensions. */
36    public static final String SSX_CLASS_NAME = "XWiki.StyleSheetExtension";
37   
38    /** The local reference of the XClass storing the code for this type of extensions. */
39    public static final LocalDocumentReference SSX_CLASS_REFERENCE = new LocalDocumentReference("XWiki",
40    "StyleSheetExtension");
41   
42    /**
43    * The identifier for this plugin; used for accessing the plugin from velocity, and as the action returning the
44    * extension content.
45    */
46    public static final String PLUGIN_NAME = "ssx";
47   
48    /**
49    * XWiki plugin constructor.
50    *
51    * @param name The name of the plugin, which can be used for retrieving the plugin API from velocity. Unused.
52    * @param className The canonical classname of the plugin. Unused.
53    * @param context The current request context.
54    * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
55    */
 
56  32 toggle public CssSkinExtensionPlugin(String name, String className, XWikiContext context)
57    {
58  32 super(PLUGIN_NAME, className, context);
59    }
60   
61    /**
62    * {@inheritDoc}
63    * <p>
64    * We must override this method since the plugin manager only calls it for classes that provide their own
65    * implementation, and not an inherited one.
66    * </p>
67    *
68    * @see com.xpn.xwiki.plugin.XWikiPluginInterface#virtualInit(com.xpn.xwiki.XWikiContext)
69    */
 
70  4 toggle @Override
71    public void virtualInit(XWikiContext context)
72    {
73  4 super.virtualInit(context);
74    }
75   
 
76  11195 toggle @Override
77    public String getLink(String documentName, XWikiContext context)
78    {
79  11195 DocumentReference documentReference = getCurrentDocumentReferenceResolver().resolve(documentName);
80  11195 if (!isAccessible(documentReference, context)) {
81    // No access to view the Skin Extension's document. Don`t generate any link to avoid a useless network
82    // request always leading to a 403 Error.
83  0 return "";
84    }
85   
86  11195 return String.format("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />",
87    getDocumentSkinExtensionURL(documentReference, documentName, PLUGIN_NAME, context));
88    }
89   
 
90  9074 toggle @Override
91    protected String getExtensionClassName()
92    {
93  9076 return SSX_CLASS_NAME;
94    }
95   
 
96  0 toggle @Override
97    protected String getExtensionName()
98    {
99  0 return "Stylesheet";
100    }
101   
102    /**
103    * {@inheritDoc}
104    * <p>
105    * We must override this method since the plugin manager only calls it for classes that provide their own
106    * implementation, and not an inherited one.
107    * </p>
108    *
109    * @see AbstractSkinExtensionPlugin#endParsing(String, XWikiContext)
110    */
 
111  6893 toggle @Override
112    public String endParsing(String content, XWikiContext context)
113    {
114  6893 return super.endParsing(content, context);
115    }
116    }