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

File DefaultXHTMLLinkRenderer.java

 

Coverage histogram

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

Code metrics

2
14
6
1
120
69
8
0.57
2.33
6
1.33

Classes

Class Line # Actions
DefaultXHTMLLinkRenderer 47 14 0% 8 1
0.9545454495.5%
 

Contributing tests

This file is covered by 121 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    import javax.inject.Provider;
27   
28    import org.slf4j.Logger;
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.component.manager.ComponentLookupException;
33    import org.xwiki.component.manager.ComponentManager;
34    import org.xwiki.rendering.listener.reference.ResourceReference;
35    import org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter;
36   
37    /**
38    * Default implementation for rendering links as XHTML. The implementation is pluggable in the sense that the
39    * implementation is done by {@link org.xwiki.rendering.internal.renderer.xhtml.link.XHTMLLinkTypeRenderer}
40    * implementation, each in charge of handling a given {@link org.xwiki.rendering.listener.reference.ResourceType}.
41    *
42    * @version $Id: 35dafccd6f49d0cd1cef63fd2e7c1013f0614c16 $
43    * @since 2.0M3
44    */
45    @Component
46    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
47    public class DefaultXHTMLLinkRenderer implements XHTMLLinkRenderer
48    {
49    @Inject
50    private XHTMLLinkTypeRenderer defaultLinkTypeRenderer;
51   
52    @Inject
53    @Named("context")
54    protected Provider<ComponentManager> componentManagerProvider;
55   
56    @Inject
57    private Logger logger;
58   
59    /**
60    * The XHTML printer to use to output links as XHTML.
61    */
62    private XHTMLWikiPrinter xhtmlPrinter;
63   
64    /**
65    * @see #setHasLabel(boolean)
66    */
67    private boolean hasLabel;
68   
 
69  812 toggle @Override
70    public void setHasLabel(boolean hasLabel)
71    {
72  812 this.hasLabel = hasLabel;
73    }
74   
 
75  812 toggle @Override
76    public void setXHTMLWikiPrinter(XHTMLWikiPrinter printer)
77    {
78  812 this.xhtmlPrinter = printer;
79    }
80   
 
81  1738 toggle @Override
82    public XHTMLWikiPrinter getXHTMLWikiPrinter()
83    {
84  1738 return this.xhtmlPrinter;
85    }
86   
 
87  812 toggle @Override
88    public void beginLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
89    {
90  812 getXHTMLLinkTypeRenderer(reference).beginLink(reference, freestanding, parameters);
91    }
92   
 
93  812 toggle @Override
94    public void endLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters)
95    {
96  812 getXHTMLLinkTypeRenderer(reference).endLink(reference, freestanding, parameters);
97    }
98   
 
99  1624 toggle private XHTMLLinkTypeRenderer getXHTMLLinkTypeRenderer(ResourceReference reference)
100    {
101  1624 XHTMLLinkTypeRenderer renderer = this.defaultLinkTypeRenderer;
102   
103    // TODO: This is probably not very performant since it's called at each begin/endLink.
104  1624 ComponentManager componentManager = this.componentManagerProvider.get();
105  1624 if (componentManager.hasComponent(XHTMLLinkTypeRenderer.class, reference.getType().getScheme())) {
106  1434 try {
107  1434 renderer =
108    this.componentManagerProvider.get().getInstance(XHTMLLinkTypeRenderer.class,
109    reference.getType().getScheme());
110    } catch (ComponentLookupException e) {
111  0 this.logger.error("Failed to initialize XHTML link type renderer", e);
112    }
113    }
114   
115  1624 renderer.setHasLabel(this.hasLabel);
116  1624 renderer.setXHTMLWikiPrinter(getXHTMLWikiPrinter());
117   
118  1624 return renderer;
119    }
120    }