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
12   107   7   2
0   58   0.58   6
6     1.17  
1    
 
  DefaultXHTMLLinkRenderer       Line # 44 12 0% 7 0 100% 1.0
 
  (59)
 
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   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.annotation.InstantiationStrategy;
28    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.rendering.listener.reference.ResourceReference;
32    import org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter;
33   
34    /**
35    * Default implementation for rendering links as XHTML. The implementation is pluggable in the sense that the
36    * implementation is done by {@link org.xwiki.rendering.internal.renderer.xhtml.link.XHTMLLinkTypeRenderer}
37    * implementation, each in charge of handling a given {@link org.xwiki.rendering.listener.reference.ResourceType}.
38    *
39    * @version $Id: 96528aa40f554ed6ade5c5a9e1edbd583f4f6802 $
40    * @since 2.0M3
41    */
42    @Component
43    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
44    public class DefaultXHTMLLinkRenderer implements XHTMLLinkRenderer
45    {
46    @Inject
47    private XHTMLLinkTypeRenderer defaultLinkTypeRenderer;
48   
49    @Inject
50    protected ComponentManager componentManager;
51   
52    /**
53    * The XHTML printer to use to output links as XHTML.
54    */
55    private XHTMLWikiPrinter xhtmlPrinter;
56   
57    /**
58    * @see #setHasLabel(boolean)
59    */
60    private boolean hasLabel;
61   
 
62  95 toggle @Override
63    public void setHasLabel(boolean hasLabel)
64    {
65  95 this.hasLabel = hasLabel;
66    }
67   
 
68  95 toggle @Override
69    public void setXHTMLWikiPrinter(XHTMLWikiPrinter printer)
70    {
71  95 this.xhtmlPrinter = printer;
72    }
73   
 
74  278 toggle @Override
75    public XHTMLWikiPrinter getXHTMLWikiPrinter()
76    {
77  278 return this.xhtmlPrinter;
78    }
79   
 
80  95 toggle @Override
81    public void beginLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
82    {
83  95 getXHTMLLinkTypeRenderer(reference).beginLink(reference, isFreeStandingURI, parameters);
84    }
85   
 
86  95 toggle @Override
87    public void endLink(ResourceReference reference, boolean isFreeStandingURI, Map<String, String> parameters)
88    {
89  95 getXHTMLLinkTypeRenderer(reference).endLink(reference, isFreeStandingURI, parameters);
90    }
91   
 
92  190 toggle private XHTMLLinkTypeRenderer getXHTMLLinkTypeRenderer(ResourceReference reference)
93    {
94  190 XHTMLLinkTypeRenderer renderer;
95   
96    // TODO: This is probably not very performant since it's called at each begin/endLink.
97  190 try {
98  190 renderer = this.componentManager.lookup(XHTMLLinkTypeRenderer.class, reference.getType().getScheme());
99    } catch (ComponentLookupException e) {
100    // There's no specific XHTML Link Type Renderer for the passed link type, use the default renderer.
101  62 renderer = this.defaultLinkTypeRenderer;
102    }
103  190 renderer.setHasLabel(this.hasLabel);
104  190 renderer.setXHTMLWikiPrinter(getXHTMLWikiPrinter());
105  190 return renderer;
106    }
107    }