1. Project Clover database Sat Feb 2 2019 06:45:20 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

8
17
2
2
97
55
6
0.35
8.5
1
3

Classes

Class Line # Actions
ClassPropertyReader 41 13 0% 5 2
0.9090909490.9%
ClassPropertyReader.WikiClassProperty 43 4 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 37 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: 1485bbaee8e204bf0d0137f977b8cf194711722e $
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  89663 toggle public void send(XARInputFilter proxyFilter) throws FilterException
54    {
55  89663 proxyFilter.beginWikiClassProperty(this.name, this.type, this.parameters);
56   
57  89663 for (Map.Entry<String, String> entry : this.fields.entrySet()) {
58  869722 proxyFilter.onWikiClassPropertyField(entry.getKey(), entry.getValue(), FilterEventParameters.EMPTY);
59    }
60   
61  89662 proxyFilter.endWikiClassProperty(this.name, this.type, this.parameters);
62   
63    }
64    }
65   
 
66  89663 toggle @Override
67    public WikiClassProperty read(XMLStreamReader xmlReader, XARInputProperties properties)
68    throws XMLStreamException, FilterException
69    {
70  89663 WikiClassProperty wikiClassProperty = new WikiClassProperty();
71   
72  89663 wikiClassProperty.name = xmlReader.getLocalName();
73   
74  1049065 for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
75  959402 String elementName = xmlReader.getLocalName();
76  959402 String value = xmlReader.getElementText();
77   
78  959402 if (elementName.equals(XARClassPropertyModel.ELEMENT_CLASSTYPE)) {
79  89663 wikiClassProperty.type = value;
80    } else {
81  869739 wikiClassProperty.fields.put(elementName, value);
82   
83    // If a <name> is defined it has priority over parent element local name
84  869739 if (elementName.equals(XARClassPropertyModel.ELEMENT_NAME)) {
85  89645 wikiClassProperty.name = value;
86    }
87    }
88    }
89   
90  89663 if (wikiClassProperty.type == null) {
91  0 throw new FilterException(
92    String.format("No <classType> element found for property [%s]", wikiClassProperty.name));
93    }
94   
95  89663 return wikiClassProperty;
96    }
97    }