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

File LinkExtensionPlugin.java

 

Coverage histogram

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

Code metrics

0
14
5
1
118
44
5
0.36
2.8
5
1

Classes

Class Line # Actions
LinkExtensionPlugin 45 14 0% 5 0
1.0100%
 

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 java.util.Collections;
23    import java.util.Map;
24    import java.util.Map.Entry;
25    import java.util.Set;
26   
27    import org.apache.commons.lang3.StringEscapeUtils;
28   
29    import com.xpn.xwiki.XWikiContext;
30   
31    /**
32    * Skin eXtension that allows inserting generic links in the <tt>&lt;head&gt;</tt> section of the resulting XHTML.
33    * Unlike JavaScript or StyleSheet extensions, Link extensions don't pull XDocuments as scripting or styling resources
34    * for the current document, but register additional related resources. Examples include:
35    * <ul>
36    * <li>RSS/Atom feeds</li>
37    * <li>navigation links in a paged collection of pages (prev, next, index, glossary...)</li>
38    * <li>semantic/metadata links (DCMI, DOAP, FOAF, RDF, OWL...)</li>
39    * <li>generic links to other related resources or alternate views for the current document</li>
40    * </ul>
41    *
42    * @version $Id: 11626f69ba1d01852415c2e7a244951d70fe0a39 $
43    * @since 1.5
44    */
 
45    public class LinkExtensionPlugin extends AbstractSkinExtensionPlugin
46    {
47    /**
48    * XWiki plugin constructor.
49    *
50    * @param name The name of the plugin, which can be used for retrieving the plugin API from velocity. Unused.
51    * @param className The canonical classname of the plugin. Unused.
52    * @param context The current request context.
53    * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#XWikiDefaultPlugin(String,String,com.xpn.xwiki.XWikiContext)
54    */
 
55  32 toggle public LinkExtensionPlugin(String name, String className, XWikiContext context)
56    {
57  32 super("linkx", className, context);
58    }
59   
 
60  599 toggle @Override
61    public String getLink(String link, XWikiContext context)
62    {
63  599 Map<String, Object> params = getParametersForResource(link, context);
64  599 StringBuilder result = new StringBuilder("<link href=\"" + StringEscapeUtils.escapeXml(link) + "\"");
65  599 for (Entry<String, Object> entry : params.entrySet()) {
66  1195 result.append(" ");
67  1195 result.append(StringEscapeUtils.escapeXml(entry.getKey()));
68  1195 result.append("='");
69  1195 result.append(StringEscapeUtils.escapeXml(entry.getValue().toString()));
70  1195 result.append("'");
71    }
72  599 result.append("/>");
73  599 return result.toString();
74    }
75   
76    /**
77    * {@inheritDoc}
78    * <p>
79    * There is no support for always used link extensions yet.
80    * </p>
81    *
82    * @see AbstractSkinExtensionPlugin#getAlwaysUsedExtensions(XWikiContext)
83    */
 
84  6893 toggle @Override
85    public Set<String> getAlwaysUsedExtensions(XWikiContext context)
86    {
87  6891 return Collections.emptySet();
88    }
89   
90    /**
91    * {@inheritDoc}
92    * <p>
93    * Not supported for link extensions.
94    * </p>
95    *
96    * @see com.xpn.xwiki.plugin.skinx.AbstractSkinExtensionPlugin#hasPageExtensions(com.xpn.xwiki.XWikiContext)
97    */
 
98  6892 toggle @Override
99    public boolean hasPageExtensions(XWikiContext context)
100    {
101  6892 return false;
102    }
103   
104    /**
105    * {@inheritDoc}
106    * <p>
107    * We must override this method since the plugin manager only calls it for classes that provide their own
108    * implementation, and not an inherited one.
109    * </p>
110    *
111    * @see AbstractSkinExtensionPlugin#endParsing(String, XWikiContext)
112    */
 
113  6892 toggle @Override
114    public String endParsing(String content, XWikiContext context)
115    {
116  6891 return super.endParsing(content, context);
117    }
118    }