1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.xdomxml10.internal.parser.parameter

File CustomParametersParser.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

6
12
4
1
77
44
7
0.58
3
4
1.75

Classes

Class Line # Actions
CustomParametersParser 29 12 0% 7 3
0.863636486.4%
 

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.xdomxml10.internal.parser.parameter;
21   
22    import java.util.LinkedHashMap;
23    import java.util.Map;
24   
25    import org.xml.sax.Attributes;
26    import org.xml.sax.SAXException;
27    import org.xml.sax.helpers.DefaultHandler;
28   
 
29    public class CustomParametersParser extends DefaultHandler implements ValueParser<Map<String, String>>
30    {
31    private Map<String, String> parameters = new LinkedHashMap<String, String>();
32   
33    private StringBuffer value = new StringBuffer();
34   
35    private int level = 0;
36   
37    private String currentEntry;
38   
 
39  2 toggle @Override
40    public Map<String, String> getValue()
41    {
42  2 return this.parameters;
43    }
44   
45    // ContentHandler
46   
 
47  2 toggle @Override
48    public void characters(char[] ch, int start, int length) throws SAXException
49    {
50  2 this.value.append(ch, start, length);
51    }
52   
 
53  4 toggle @Override
54    public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
55    {
56  4 if (this.level > 0) {
57  2 this.currentEntry = qName;
58  2 String name = attributes.getValue("name");
59  2 if (name != null) {
60  0 this.currentEntry = name;
61    }
62    }
63   
64  4 ++this.level;
65    }
66   
 
67  2 toggle @Override
68    public void endElement(String uri, String localName, String qName) throws SAXException
69    {
70  2 --this.level;
71   
72  2 if (this.level > 0) {
73  2 this.parameters.put(this.currentEntry, this.value.toString());
74  2 this.value.setLength(0);
75    }
76    }
77    }