1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.filter.xar.internal.input

File ClassReader.java

 

Coverage histogram

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

Code metrics

10
21
4
2
110
69
10
0.48
5.25
2
2.5

Classes

Class Line # Actions
ClassReader 45 15 0% 7 2
0.923076992.3%
ClassReader.WikiClass 50 6 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 61 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.Inject;
26    import javax.inject.Singleton;
27    import javax.xml.stream.XMLStreamException;
28    import javax.xml.stream.XMLStreamReader;
29   
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.filter.FilterEventParameters;
32    import org.xwiki.filter.FilterException;
33    import org.xwiki.filter.event.model.WikiClassFilter;
34    import org.xwiki.filter.xar.input.XARInputProperties;
35    import org.xwiki.filter.xar.internal.XARClassModel;
36    import org.xwiki.filter.xar.internal.XARFilterUtils.EventParameter;
37    import org.xwiki.filter.xar.internal.input.ClassPropertyReader.WikiClassProperty;
38   
39    /**
40    * @version $Id: 200570ce6e30daadfe92b133269012a707eaf18d $
41    * @since 6.2M1
42    */
43    @Component
44    @Singleton
 
45    public class ClassReader extends AbstractReader implements XARXMLReader<ClassReader.WikiClass>
46    {
47    @Inject
48    private XARXMLReader<ClassPropertyReader.WikiClassProperty> propertyReader;
49   
 
50    public static class WikiClass
51    {
52    public String name;
53   
54    public FilterEventParameters parameters = new FilterEventParameters();
55   
56    public Map<String, WikiClassProperty> properties = new LinkedHashMap<String, WikiClassProperty>();
57   
 
58  13076 toggle public void send(XARInputFilter proxyFilter) throws FilterException
59    {
60  13076 proxyFilter.beginWikiClass(this.parameters);
61   
62  13076 for (WikiClassProperty property : this.properties.values()) {
63  89663 property.send(proxyFilter);
64    }
65   
66  13076 proxyFilter.endWikiClass(this.parameters);
67    }
68   
 
69  12673 toggle public boolean isEmpty()
70    {
71  12673 return this.properties.isEmpty();
72    }
73   
 
74  89663 toggle public void addProperty(WikiClassProperty property)
75    {
76  89663 this.properties.put(property.name, property);
77    }
78    }
79   
 
80  13076 toggle @Override
81    public WikiClass read(XMLStreamReader xmlReader, XARInputProperties properties)
82    throws XMLStreamException, FilterException
83    {
84  13076 WikiClass wikiClass = new WikiClass();
85   
86  207333 for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
87  194257 String elementName = xmlReader.getLocalName();
88   
89  194257 if (wikiClass.name == null && XARClassModel.ELEMENT_NAME.equals(elementName)) {
90  13076 wikiClass.name = xmlReader.getElementText();
91  13076 wikiClass.parameters.put(WikiClassFilter.PARAMETER_NAME, wikiClass.name);
92  181181 } else if (XARClassModel.CLASS_PARAMETERS.containsKey(elementName)) {
93  91518 String value = xmlReader.getElementText();
94   
95  91518 EventParameter parameter = XARClassModel.CLASS_PARAMETERS.get(elementName);
96   
97  91518 if (parameter != null) {
98  91518 Object wsValue = convert(parameter.type, value);
99  91518 if (wsValue != null) {
100  91518 wikiClass.parameters.put(parameter.name, wsValue);
101    }
102    }
103    } else {
104  89663 wikiClass.addProperty(this.propertyReader.read(xmlReader, properties));
105    }
106    }
107   
108  13076 return wikiClass;
109    }
110    }