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   109   10   3.83
8   62   0.43   6
6     1.67  
1    
 
  ReferenceTagHandler       Line # 33 23 0% 10 0 100% 1.0
 
  (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.wikimodel.xhtml.handler;
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.impl.XhtmlHandler.TagStack.TagContext;
26   
27    /**
28    * Handles references.
29    *
30    * @version $Id: 71e8cad2693312f28328cc4ab7823d5d32b43ef1 $
31    * @since 4.0M1
32    */
 
33    public class ReferenceTagHandler extends TagHandler
34    {
 
35  1056 toggle public ReferenceTagHandler()
36    {
37  1056 super(false, false, true);
38    }
39   
 
40  26 toggle @Override
41    protected void begin(TagContext context)
42    {
43  26 setAccumulateContent(true);
44    }
45   
 
46  7 toggle @Override
47    protected void end(TagContext context)
48    {
49  7 WikiParameters parameters = context.getParams();
50   
51    // TODO: it should be replaced by a normal parameters
52  7 WikiParameter ref = parameters.getParameter("href");
53   
54  7 if (ref != null) {
55    // Check if there's a class attribute with a
56    // "wikimodel-freestanding" value.
57    // If so it means we have a free standing link.
58  5 if (isFreeStandingReference(context)) {
59  1 context.getScannerContext().onReference(ref.getValue());
60    } else {
61  4 String content = context.getContent();
62   
63  4 WikiReference reference = new WikiReference(
64    ref.getValue(),
65    content,
66    removeMeaningfulParameters(parameters));
67  4 context.getScannerContext().onReference(reference);
68    }
69    }
70    }
71   
 
72  114 toggle protected boolean isFreeStandingReference(TagContext context)
73    {
74  114 WikiParameters parameters = context.getParams();
75   
76    // Check if there's a class attribute with a "wikimodel-freestanding"
77    // value.
78    // If so it means we have a free standing link.
79  114 WikiParameter classParam = context.getParams().getParameter("class");
80   
81  114 boolean isFreeStanding = ((classParam != null) && classParam.getValue().equalsIgnoreCase(
82    "wikimodel-freestanding"));
83   
84  114 if (isFreeStanding) {
85  30 parameters = removeMeaningfulParameters(parameters);
86   
87  30 return parameters.getSize() == 0;
88    } else {
89  84 return false;
90    }
91    }
92   
 
93  93 toggle protected WikiParameters removeFreestanding(WikiParameters parameters)
94    {
95  93 WikiParameter classParam = parameters.getParameter("class");
96  93 boolean isFreeStanding = ((classParam != null) && classParam.getValue().equalsIgnoreCase(
97    "wikimodel-freestanding"));
98  93 if (isFreeStanding) {
99  32 parameters = parameters.remove("class");
100    }
101   
102  93 return parameters;
103    }
104   
 
105  58 toggle protected WikiParameters removeMeaningfulParameters(WikiParameters parameters)
106    {
107  58 return removeFreestanding(parameters).remove("href");
108    }
109    }