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

File ReferenceTagHandler.java

 

Coverage histogram

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

Code metrics

8
23
6
1
109
62
10
0.43
3.83
6
1.67

Classes

Class Line # Actions
ReferenceTagHandler 33 23 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 322 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.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.TagContext;
26   
27    /**
28    * Handles references.
29    *
30    * @version $Id: 4473d8ed96489e004c044fdb93a8366c9637efb6 $
31    * @since 4.0M1
32    */
 
33    public class ReferenceTagHandler extends TagHandler
34    {
 
35  1506 toggle public ReferenceTagHandler()
36    {
37  1506 super(true);
38    }
39   
 
40  29 toggle @Override
41    protected void begin(TagContext context)
42    {
43  29 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  167 toggle protected boolean isFreeStandingReference(TagContext context)
73    {
74  167 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  167 WikiParameter classParam = context.getParams().getParameter("class");
80   
81  167 boolean isFreeStanding = ((classParam != null) && classParam.getValue().equalsIgnoreCase(
82    "wikimodel-freestanding"));
83   
84  167 if (isFreeStanding) {
85  42 parameters = removeMeaningfulParameters(parameters);
86   
87  42 return parameters.getSize() == 0;
88    } else {
89  125 return false;
90    }
91    }
92   
 
93  131 toggle protected WikiParameters removeFreestanding(WikiParameters parameters)
94    {
95  131 WikiParameter classParam = parameters.getParameter("class");
96  131 boolean isFreeStanding = ((classParam != null) && classParam.getValue().equalsIgnoreCase(
97    "wikimodel-freestanding"));
98  131 if (isFreeStanding) {
99  44 parameters = parameters.remove("class");
100    }
101   
102  131 return parameters;
103    }
104   
 
105  85 toggle protected WikiParameters removeMeaningfulParameters(WikiParameters parameters)
106    {
107  85 return removeFreestanding(parameters).remove("href");
108    }
109    }