1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.repository.internal.xhtml

File ExtensionXHTMLLinkTypeRenderer.java

 

Coverage histogram

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

Code metrics

10
17
1
1
94
51
7
0.41
17
1
7

Classes

Class Line # Actions
ExtensionXHTMLLinkTypeRenderer 50 17 0% 7 8
0.7142857371.4%
 

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 org.xwiki.repository.internal.xhtml;
21   
22    import java.net.URI;
23    import java.util.Map;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Provider;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.annotation.InstantiationStrategy;
31    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
32    import org.xwiki.rendering.internal.renderer.xhtml.link.AbstractXHTMLLinkTypeRenderer;
33    import org.xwiki.rendering.internal.renderer.xhtml.link.XHTMLLinkRenderer;
34    import org.xwiki.rendering.listener.reference.ResourceReference;
35    import org.xwiki.repository.Resources;
36    import org.xwiki.repository.UriBuilder;
37    import org.xwiki.repository.internal.reference.ExtensionResourceReference;
38   
39    import com.xpn.xwiki.XWikiContext;
40   
41    /**
42    * Handle XHTML rendering for links to extensions.
43    *
44    * @version $Id: 6958bde017de9f9e9bf6350d8b56ca61bada75b6 $
45    * @since 3.4RC1
46    */
47    @Component
48    @Named("extension")
49    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
50    public class ExtensionXHTMLLinkTypeRenderer extends AbstractXHTMLLinkTypeRenderer
51    {
52    /**
53    * Give access to current {@link XWikiContext}.
54    */
55    @Inject
56    private Provider<XWikiContext> xcontextProvider;
57   
 
58  2 toggle @Override
59    protected void beginLinkExtraAttributes(ResourceReference reference, Map<String, String> spanAttributes,
60    Map<String, String> anchorAttributes)
61    {
62  2 XWikiContext xcontext = this.xcontextProvider.get();
63   
64  2 String prefix = xcontext.getWiki().getWebAppPath(xcontext);
65  2 if (prefix.isEmpty() || prefix.charAt(0) != '/') {
66  2 prefix = '/' + prefix;
67    }
68  2 if (prefix.charAt(prefix.length() - 1) != '/') {
69  0 prefix += '/';
70    }
71    // FIXME: need a way to get the rest URL prefix instead of hardcoding it here
72  2 prefix += "rest";
73   
74    // Create an URI (because the API only produces URIs) with a stub context we will then remove since we actually
75    // want a relative HREF
76  2 UriBuilder builder = new UriBuilder("stubscheme:" + prefix, Resources.EXTENSION_VERSION_FILE);
77   
78  2 ExtensionResourceReference extensionReference = (ExtensionResourceReference) reference;
79   
80  2 if (extensionReference.getRepositoryId() != null) {
81  2 builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYID, extensionReference.getRepositoryId());
82    }
83  2 if (extensionReference.getRepositoryType() != null) {
84  0 builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYTYPE, extensionReference.getRepositoryType());
85    }
86  2 if (extensionReference.getRepositoryURI() != null) {
87  0 builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYURI, extensionReference.getRepositoryURI());
88    }
89   
90  2 URI uri = builder.build(extensionReference.getExtensionId(), extensionReference.getExtensionVersion());
91   
92  2 anchorAttributes.put(XHTMLLinkRenderer.HREF, uri.toString().substring("stubscheme://".length()));
93    }
94    }