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

File XWikiImageTagHandler.java

 

Coverage histogram

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

Code metrics

12
23
4
1
103
62
10
0.43
5.75
4
2.5

Classes

Class Line # Actions
XWikiImageTagHandler 36 23 0% 10 1
0.97435997.4%
 

Contributing tests

This file is covered by 282 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.parser.xhtml.wikimodel;
21   
22    import org.xwiki.rendering.wikimodel.WikiParameter;
23    import org.xwiki.rendering.wikimodel.WikiParameters;
24    import org.xwiki.rendering.wikimodel.WikiReference;
25    import org.xwiki.rendering.wikimodel.xhtml.handler.ImgTagHandler;
26    import org.xwiki.rendering.wikimodel.xhtml.impl.TagStack;
27    import org.xwiki.rendering.wikimodel.xhtml.impl.TagContext;
28   
29    /**
30    * Handle IMG tag since we're putting the original image reference into XHTML comments so that we can reconstruct the
31    * reference when moving back from XHTML to wiki syntax.
32    *
33    * @version $Id: b0058d153b6c0808f40bcfc50bd66d51881021d7 $
34    * @since 1.7M2
35    */
 
36    public class XWikiImageTagHandler extends ImgTagHandler implements XWikiWikiModelHandler
37    {
 
38  351 toggle @Override
39    public void initialize(TagStack stack)
40    {
41  351 stack.setStackParameter(IS_IN_IMAGE, false);
42  351 stack.setStackParameter(IS_FREE_STANDING_IMAGE, false);
43  351 stack.setStackParameter(IMAGE_PARAMETERS, WikiParameters.EMPTY);
44    }
45   
 
46  41 toggle @Override
47    protected void begin(TagContext context)
48    {
49  41 boolean isInImage = (Boolean) context.getTagStack().getStackParameter(IS_IN_IMAGE);
50   
51  41 if (isInImage) {
52    // Verify if it's a freestanding image uri and if so save the information so that we can get it in
53    // XWikiCommentHandler.
54  23 if (isFreeStandingReference(context)) {
55  13 context.getTagStack().setStackParameter(IS_FREE_STANDING_IMAGE, true);
56    } else {
57    // Save the parameters set on the IMG element so that we can generate the correct image
58    // in the XWiki Comment handler.
59  10 context.getTagStack().setStackParameter(IMAGE_PARAMETERS,
60    removeMeaningfulParameters(context.getParams()));
61    }
62    } else {
63  18 super.begin(context);
64    }
65    }
66   
 
67  41 toggle @Override
68    protected void end(TagContext context)
69    {
70  41 boolean isInImage = (Boolean) context.getTagStack().getStackParameter(IS_IN_IMAGE);
71   
72  41 if (!isInImage) {
73  18 WikiParameter src = context.getParams().getParameter("src");
74   
75  18 if (src != null) {
76  18 WikiParameters parameters = context.getParams().remove("src");
77   
78  18 if (isFreeStandingReference(context)) {
79  12 context.getScannerContext().onImage(src.getValue());
80    } else {
81  6 WikiReference reference =
82    new WikiReference(src.getValue(), null, removeMeaningfulParameters(parameters));
83   
84  6 context.getScannerContext().onImage(reference);
85    }
86    }
87    }
88    }
89   
 
90  41 toggle @Override
91    protected WikiParameters removeMeaningfulParameters(WikiParameters parameters)
92    {
93  41 WikiParameter classParam = parameters.getParameter("class");
94  41 boolean isFreeStanding =
95    ((classParam != null) && classParam.getValue().equalsIgnoreCase("wikimodel-freestanding"));
96   
97  41 if (isFreeStanding) {
98  25 return removeFreestanding(parameters).remove("alt").remove("src");
99    } else {
100  16 return removeFreestanding(parameters).remove("src");
101    }
102    }
103    }