1. Project Clover database Sat Feb 2 2019 06:45:20 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 351 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: 0f906edd43b0e7e0fdd8b200542a7c1a47219a77 $
31    * @since 4.0M1
32    */
 
33    public class ReferenceTagHandler extends TagHandler
34    {
 
35  1534 toggle public ReferenceTagHandler()
36    {
37  1534 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  157 toggle protected boolean isFreeStandingReference(TagContext context)
73    {
74  157 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  157 WikiParameter classParam = context.getParams().getParameter("class");
80   
81  157 boolean isFreeStanding = ((classParam != null) && "wikimodel-freestanding".equalsIgnoreCase(
82    classParam.getValue()));
83   
84  157 if (isFreeStanding) {
85  42 parameters = removeMeaningfulParameters(parameters);
86   
87  42 return parameters.getSize() == 0;
88    } else {
89  115 return false;
90    }
91    }
92   
 
93  126 toggle protected WikiParameters removeFreestanding(WikiParameters parameters)
94    {
95  126 WikiParameter classParam = parameters.getParameter("class");
96  126 boolean isFreeStanding = ((classParam != null) && "wikimodel-freestanding".equalsIgnoreCase(
97    classParam.getValue()));
98  126 if (isFreeStanding) {
99  44 parameters = parameters.remove("class");
100    }
101   
102  126 return parameters;
103    }
104   
 
105  80 toggle protected WikiParameters removeMeaningfulParameters(WikiParameters parameters)
106    {
107  80 return removeFreestanding(parameters).remove("href");
108    }
109    }