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

File AnnotatedXHTMLLinkRenderer.java

 

Coverage histogram

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

Code metrics

0
9
5
1
98
50
5
0.56
1.8
5
1

Classes

Class Line # Actions
AnnotatedXHTMLLinkRenderer 44 9 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 41 tests. .

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.rendering.internal.renderer.xhtml.link;
21   
22    import java.util.Map;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.component.annotation.InstantiationStrategy;
29    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
30    import org.xwiki.rendering.listener.reference.ResourceReference;
31    import org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter;
32    import org.xwiki.rendering.renderer.reference.ResourceReferenceSerializer;
33   
34    /**
35    * Render links as XHTML, using annotations (see
36    * {@link org.xwiki.rendering.internal.renderer.xhtml.AnnotatedXHTMLRenderer} for more details).
37    *
38    * @version $Id: a7ed31db9f1fbddd73c33d7205aabb50f63b1441 $
39    * @since 2.0M3
40    */
41    @Component
42    @Named("annotated")
43    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
44    public class AnnotatedXHTMLLinkRenderer implements XHTMLLinkRenderer
45    {
46    /**
47    * Used to print Image reference as XHTML comments.
48    */
49    @Inject
50    @Named("xhtmlmarker")
51    private ResourceReferenceSerializer xhtmlMarkerSerializer;
52   
53    /**
54    * The default XHTML Link Renderer that we're wrapping.
55    */
56    @Inject
57    private XHTMLLinkRenderer defaultLinkRenderer;
58   
 
59  57 toggle @Override
60    public void setXHTMLWikiPrinter(XHTMLWikiPrinter printer)
61    {
62  57 this.defaultLinkRenderer.setXHTMLWikiPrinter(printer);
63    }
64   
 
65  57 toggle @Override
66    public void setHasLabel(boolean hasLabel)
67    {
68  57 this.defaultLinkRenderer.setHasLabel(hasLabel);
69    }
70   
 
71  57 toggle @Override
72    public void beginLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
73    {
74    // Add an XML comment as a placeholder so that the XHTML parser can find the document name.
75    // Otherwise it would be too difficult to transform a URL into a document name especially since
76    // a link can refer to an external URL.
77  57 StringBuffer buffer = new StringBuffer("startwikilink:");
78  57 buffer.append(this.xhtmlMarkerSerializer.serialize(reference));
79   
80  57 getXHTMLWikiPrinter().printXMLComment(buffer.toString(), true);
81  57 this.defaultLinkRenderer.beginLink(reference, freestanding, parameters);
82    }
83   
 
84  57 toggle @Override
85    public void endLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
86    {
87  57 this.defaultLinkRenderer.endLink(reference, freestanding, parameters);
88   
89    // Add a XML comment to signify the end of the link.
90  57 getXHTMLWikiPrinter().printXMLComment("stopwikilink");
91    }
92   
 
93  114 toggle @Override
94    public XHTMLWikiPrinter getXHTMLWikiPrinter()
95    {
96  114 return this.defaultLinkRenderer.getXHTMLWikiPrinter();
97    }
98    }