Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
9   98   5   1.8
0   50   0.56   5
5     1  
1    
 
  AnnotatedXHTMLLinkRenderer       Line # 44 9 0% 5 0 100% 1.0
 
  (28)
 
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: 91612a4ef3da6c6be230c1e86f0287f11d0ac314 $
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  44 toggle @Override
60    public void setXHTMLWikiPrinter(XHTMLWikiPrinter printer)
61    {
62  44 this.defaultLinkRenderer.setXHTMLWikiPrinter(printer);
63    }
64   
 
65  44 toggle @Override
66    public void setHasLabel(boolean hasLabel)
67    {
68  44 this.defaultLinkRenderer.setHasLabel(hasLabel);
69    }
70   
 
71  44 toggle @Override
72    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, 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  44 StringBuffer buffer = new StringBuffer("startwikilink:");
78  44 buffer.append(this.xhtmlMarkerSerializer.serialize(reference));
79   
80  44 getXHTMLWikiPrinter().printXMLComment(buffer.toString(), true);
81  44 this.defaultLinkRenderer.beginLink(reference, isFreeStandingURI, parameters);
82    }
83   
 
84  44 toggle @Override
85    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
86    {
87  44 this.defaultLinkRenderer.endLink(reference, isFreeStandingURI, parameters);
88   
89    // Add a XML comment to signify the end of the link.
90  44 getXHTMLWikiPrinter().printXMLComment("stopwikilink");
91    }
92   
 
93  88 toggle @Override
94    public XHTMLWikiPrinter getXHTMLWikiPrinter()
95    {
96  88 return this.defaultLinkRenderer.getXHTMLWikiPrinter();
97    }
98    }