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

File AbstractTagNotifier.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

22
48
11
1
163
113
23
0.48
4.36
11
2.09

Classes

Class Line # Actions
AbstractTagNotifier 37 48 0% 23 25
0.6913580369.1%
 

Contributing tests

This file is covered by 2 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.xml;
21   
22    import java.util.Collections;
23    import java.util.LinkedHashMap;
24    import java.util.List;
25    import java.util.Map;
26   
27    import org.xwiki.rendering.wikimodel.WikiFormat;
28    import org.xwiki.rendering.wikimodel.WikiParameter;
29    import org.xwiki.rendering.wikimodel.WikiParameters;
30    import org.xwiki.rendering.wikimodel.WikiReference;
31    import org.xwiki.rendering.wikimodel.WikiStyle;
32   
33    /**
34    * @version $Id: 041d42bf0e34224aae553d99c8360d507a584750 $
35    * @since 4.0M1
36    */
 
37    public class AbstractTagNotifier implements ISaxConst
38    {
39    protected static final Map<String, String> EMPTY_MAP = Collections
40    .emptyMap();
41   
42    protected ITagListener fListener;
43   
 
44  42 toggle public AbstractTagNotifier(ITagListener listener)
45    {
46  42 fListener = listener;
47    }
48   
49    /**
50    * @param map
51    * @param params
52    * @return
53    */
 
54  42 toggle private Map<String, String> addParams(
55    Map<String, String> map,
56    String... params)
57    {
58  156 for (int i = 0; i < params.length; i++) {
59  114 String key = params[i];
60  114 i++;
61  114 String value = i < params.length ? params[i] : null;
62  114 map.put(key, value);
63    }
64  42 return map;
65    }
66   
67    /**
68    * @param params
69    * @return
70    */
 
71  28 toggle private Map<String, String> getParamsMap(Iterable<WikiParameter> params)
72    {
73  28 Map<String, String> map = newParamMap();
74  28 for (WikiParameter param : params) {
75  12 String key = param.getKey();
76  12 String value = param.getValue();
77  12 map.put(key, value);
78    }
79  28 return map;
80    }
81   
82    /**
83    * @return
84    */
 
85  72 toggle protected Map<String, String> newParamMap()
86    {
87  72 return new LinkedHashMap<String, String>();
88    }
89   
 
90  0 toggle protected Map<String, String> tagParams(
91    Map<String, String> tagParams,
92    String... params)
93    {
94  0 if (tagParams == EMPTY_MAP) {
95  0 return tagParams(params);
96    }
97  0 return addParams(tagParams, params);
98    }
99   
 
100  54 toggle protected Map<String, String> tagParams(String... params)
101    {
102  54 if (params.length == 0) {
103  12 return EMPTY_MAP;
104    }
105  42 Map<String, String> map = newParamMap();
106  42 return addParams(map, params);
107    }
108   
 
109  22 toggle protected Map<String, String> tagParams(WikiFormat format)
110    {
111  22 if (format == null) {
112  0 return EMPTY_MAP;
113    }
114  22 List<WikiStyle> styles = format.getStyles();
115  22 if (styles.isEmpty()) {
116  20 return EMPTY_MAP;
117    }
118  2 Map<String, String> map = newParamMap();
119  2 StringBuffer buf = new StringBuffer();
120  2 for (WikiStyle style : styles) {
121  2 String name = style.toString();
122  2 if (buf.length() > 0) {
123  0 buf.append("; ");
124    }
125  2 buf.append(name);
126    }
127  2 map.put(STYLES, buf.toString());
128  2 return map;
129    }
130   
 
131  0 toggle protected Map<String, String> tagParams(WikiReference ref)
132    {
133  0 if (ref == null) {
134  0 return EMPTY_MAP;
135    }
136  0 return tagParams("label", ref.getLabel(), "href", ref.getLink());
137    }
138   
 
139  22 toggle protected Map<String, String> userParams(WikiFormat format)
140    {
141  22 if (format == null) {
142  0 return EMPTY_MAP;
143    }
144  22 List<WikiParameter> params = format.getParams();
145  22 return getParamsMap(params);
146    }
147   
 
148  64 toggle protected Map<String, String> userParams(WikiParameters params)
149    {
150  64 if (params == null || params.getSize() == 0) {
151  58 return EMPTY_MAP;
152    }
153  6 return getParamsMap(params);
154    }
155   
 
156  0 toggle protected Map<String, String> userParams(WikiReference ref)
157    {
158  0 if (ref == null) {
159  0 return EMPTY_MAP;
160    }
161  0 return userParams(ref.getParameters());
162    }
163    }