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

File AttachmentXHTMLImageTypeRenderer.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
7
2
1
74
37
4
0.57
3.5
2
2

Classes

Class Line # Actions
AttachmentXHTMLImageTypeRenderer 44 7 0% 4 2
0.818181881.8%
 

Contributing tests

This file is covered by 20 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.Named;
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.phase.Initializable;
31    import org.xwiki.component.phase.InitializationException;
32    import org.xwiki.rendering.listener.reference.ResourceReference;
33    import org.xwiki.rendering.wiki.WikiModel;
34   
35    /**
36    * Handle XHTML rendering for images located in attachments.
37    *
38    * @version $Id: 940ca55d3238dd39c900ec8f924ae001d2be0ed9 $
39    * @since 5.4RC1
40    */
41    @Component
42    @Named("attach")
43    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
44    public class AttachmentXHTMLImageTypeRenderer extends AbstractXHTMLImageTypeRenderer implements Initializable
45    {
46    /**
47    * Use to resolve local image URL when the image is attached to a document.
48    */
49    private WikiModel wikiModel;
50   
 
51  317 toggle @Override
52    public void initialize() throws InitializationException
53    {
54    // Try to find a WikiModel implementation and set it if it can be found. If not it means we're in
55    // non wiki mode (i.e. no attachment in wiki documents and no links to documents for example).
56  317 try {
57  317 this.wikiModel = this.componentManager.getInstance(WikiModel.class);
58    } catch (ComponentLookupException e) {
59    // There's no WikiModel implementation available. this.wikiModel stays null.
60    }
61    }
62   
 
63  317 toggle @Override
64    protected String getImageSrcAttributeValue(ResourceReference reference, Map<String, String> parameters)
65    {
66  317 String imageSrcAttributeValue;
67  317 if (this.wikiModel != null) {
68  317 imageSrcAttributeValue = this.wikiModel.getImageURL(reference, parameters);
69    } else {
70  0 imageSrcAttributeValue = String.format("%s:%s", reference.getType().getScheme(), reference.getReference());
71    }
72  317 return imageSrcAttributeValue;
73    }
74    }