1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.internal.renderer.xhtml.image

File DefaultXHTMLImageRenderer.java

 

Coverage histogram

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

Code metrics

0
9
4
1
94
51
5
0.56
2.25
4
1.25

Classes

Class Line # Actions
DefaultXHTMLImageRenderer 47 9 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 54 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.image;
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.xwiki.component.annotation.Component;
29    import org.xwiki.component.annotation.InstantiationStrategy;
30    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
31    import org.xwiki.component.manager.ComponentLookupException;
32    import org.xwiki.component.manager.ComponentManager;
33    import org.xwiki.filter.annotation.Default;
34    import org.xwiki.rendering.listener.reference.ResourceReference;
35    import org.xwiki.rendering.renderer.printer.XHTMLWikiPrinter;
36   
37    /**
38    * Default implementation for rendering images as XHTML. The implementation is pluggable in the sense that the
39    * implementation is done by {@link org.xwiki.rendering.internal.renderer.xhtml.image.XHTMLImageTypeRenderer}
40    * implementation, each in charge of handling a given {@link org.xwiki.rendering.listener.reference.ResourceType}.
41    *
42    * @version $Id: 2d10f1239988a5c6e76f2d9dd77dfd5c4af0a118 $
43    * @since 2.0M3
44    */
45    @Component
46    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
47    public class DefaultXHTMLImageRenderer implements XHTMLImageRenderer
48    {
49    @Inject
50    private XHTMLImageTypeRenderer defaultImageTypeRenderer;
51   
52    @Inject
53    @Named("context")
54    protected Provider<ComponentManager> componentManagerProvider;
55   
56    /**
57    * The XHTML printer to use to output images as XHTML.
58    */
59    private XHTMLWikiPrinter xhtmlPrinter;
60   
 
61  3099 toggle @Override
62    public void setXHTMLWikiPrinter(XHTMLWikiPrinter printer)
63    {
64  3099 this.xhtmlPrinter = printer;
65    }
66   
 
67  3151 toggle @Override
68    public XHTMLWikiPrinter getXHTMLWikiPrinter()
69    {
70  3151 return this.xhtmlPrinter;
71    }
72   
 
73  3099 toggle @Override
74    public void onImage(ResourceReference reference, boolean freestanding, @Default("") Map<String, String> parameters)
75    {
76  3099 getXHTMLImageTypeRenderer(reference).onImage(reference, freestanding, parameters);
77    }
78   
 
79  3099 toggle private XHTMLImageTypeRenderer getXHTMLImageTypeRenderer(ResourceReference reference)
80    {
81  3099 XHTMLImageTypeRenderer renderer;
82   
83    // TODO: This is probably not very performant since it's called at each onImage.
84  3099 try {
85  3099 renderer = this.componentManagerProvider.get().getInstance(XHTMLImageTypeRenderer.class,
86    reference.getType().getScheme());
87    } catch (ComponentLookupException e) {
88    // There's no specific XHTML Image Type Renderer for the passed link type, use the default renderer.
89  119 renderer = this.defaultImageTypeRenderer;
90    }
91  3099 renderer.setXHTMLWikiPrinter(getXHTMLWikiPrinter());
92  3099 return renderer;
93    }
94    }