1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.filter.xar.internal.input

File ClassPropertyReader.java

 

Coverage histogram

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

Code metrics

6
15
2
2
92
52
5
0.33
7.5
1
2.5

Classes

Class Line # Actions
ClassPropertyReader 41 11 0% 4 2
0.888888988.9%
ClassPropertyReader.WikiClassProperty 43 4 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 33 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.filter.xar.internal.input;
21   
22    import java.util.LinkedHashMap;
23    import java.util.Map;
24   
25    import javax.inject.Singleton;
26    import javax.xml.stream.XMLStreamException;
27    import javax.xml.stream.XMLStreamReader;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.filter.FilterEventParameters;
31    import org.xwiki.filter.FilterException;
32    import org.xwiki.filter.xar.input.XARInputProperties;
33    import org.xwiki.filter.xar.internal.XARClassPropertyModel;
34   
35    /**
36    * @version $Id: 126f97bbc30cda68227f9f52fc9a870bd7283b0c $
37    * @since 6.2M1
38    */
39    @Component
40    @Singleton
 
41    public class ClassPropertyReader extends AbstractReader implements XARXMLReader<ClassPropertyReader.WikiClassProperty>
42    {
 
43    public static class WikiClassProperty
44    {
45    public String name;
46   
47    public String type;
48   
49    public FilterEventParameters parameters = new FilterEventParameters();
50   
51    public Map<String, String> fields = new LinkedHashMap<>();
52   
 
53  37555 toggle public void send(XARInputFilter proxyFilter) throws FilterException
54    {
55  37554 proxyFilter.beginWikiClassProperty(this.name, this.type, this.parameters);
56   
57  37558 for (Map.Entry<String, String> entry : this.fields.entrySet()) {
58  315949 proxyFilter.onWikiClassPropertyField(entry.getKey(), entry.getValue(), FilterEventParameters.EMPTY);
59    }
60   
61  37558 proxyFilter.endWikiClassProperty(this.name, this.type, this.parameters);
62   
63    }
64    }
65   
 
66  37503 toggle @Override
67    public WikiClassProperty read(XMLStreamReader xmlReader, XARInputProperties properties)
68    throws XMLStreamException, FilterException
69    {
70  37512 WikiClassProperty wikiClassProperty = new WikiClassProperty();
71   
72  37528 wikiClassProperty.name = xmlReader.getLocalName();
73   
74  390426 for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
75  352865 String elementName = xmlReader.getLocalName();
76  352891 String value = xmlReader.getElementText();
77   
78  352941 if (elementName.equals(XARClassPropertyModel.ELEMENT_CLASSTYPE)) {
79  37535 wikiClassProperty.type = value;
80    } else {
81  315404 wikiClassProperty.fields.put(elementName, value);
82    }
83    }
84   
85  37532 if (wikiClassProperty.type == null) {
86  0 throw new FilterException(
87    String.format("No <classType> element found for property [%s]", wikiClassProperty.name));
88    }
89   
90  37532 return wikiClassProperty;
91    }
92    }