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
23   103   10   5.75
12   62   0.43   4
4     2.5  
1    
 
  XWikiImageTagHandler       Line # 36 23 0% 10 1 97.4% 0.974359
 
  (219)
 
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.WikiParameters;
23    import org.xwiki.rendering.wikimodel.WikiParameter;
24    import org.xwiki.rendering.wikimodel.WikiReference;
25    import org.xwiki.rendering.wikimodel.xhtml.handler.ImgTagHandler;
26    import org.xwiki.rendering.wikimodel.xhtml.impl.XhtmlHandler.TagStack;
27    import org.xwiki.rendering.wikimodel.xhtml.impl.XhtmlHandler.TagStack.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: 6fe7922da9cfffd70970a23418543b19ee1a582a $
34    * @since 1.7M2
35    */
 
36    public class XWikiImageTagHandler extends ImgTagHandler
37    {
 
38  250 toggle @Override
39    public void initialize(TagStack stack)
40    {
41  250 stack.setStackParameter("isInImage", false);
42  250 stack.setStackParameter("isFreeStandingImage", false);
43  250 stack.setStackParameter("imageParameters", WikiParameters.EMPTY);
44    }
45   
 
46  31 toggle @Override
47    protected void begin(TagContext context)
48    {
49  31 boolean isInImage = (Boolean) context.getTagStack().getStackParameter("isInImage");
50   
51  31 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  15 if (isFreeStandingReference(context)) {
55  7 context.getTagStack().setStackParameter("isFreeStandingImage", 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  8 context.getTagStack().setStackParameter("imageParameters",
60    removeMeaningfulParameters(context.getParams()));
61    }
62    } else {
63  16 super.begin(context);
64    }
65    }
66   
 
67  31 toggle @Override
68    protected void end(TagContext context)
69    {
70  31 boolean isInImage = (Boolean) context.getTagStack().getStackParameter("isInImage");
71   
72  31 if (!isInImage) {
73  16 WikiParameter src = context.getParams().getParameter("src");
74   
75  16 if (src != null) {
76  16 WikiParameters parameters = context.getParams().remove("src");
77   
78  16 if (isFreeStandingReference(context)) {
79  12 context.getScannerContext().onImage(src.getValue());
80    } else {
81  4 WikiReference reference =
82    new WikiReference(src.getValue(), null, removeMeaningfulParameters(parameters));
83   
84  4 context.getScannerContext().onImage(reference);
85    }
86    }
87    }
88    }
89   
 
90  31 toggle @Override
91    protected WikiParameters removeMeaningfulParameters(WikiParameters parameters)
92    {
93  31 WikiParameter classParam = parameters.getParameter("class");
94  31 boolean isFreeStanding =
95    ((classParam != null) && classParam.getValue().equalsIgnoreCase("wikimodel-freestanding"));
96   
97  31 if (isFreeStanding) {
98  19 return removeFreestanding(parameters).remove("alt").remove("src");
99    } else {
100  12 return removeFreestanding(parameters).remove("src");
101    }
102    }
103    }