1. Project Clover database Tue Dec 20 2016 21:24:09 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 52 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  5026 toggle public void send(XARInputFilter proxyFilter) throws FilterException
59    {
60  5027 proxyFilter.beginWikiClass(this.parameters);
61   
62  5030 for (WikiClassProperty property : this.properties.values()) {
63  37558 property.send(proxyFilter);
64    }
65   
66  5030 proxyFilter.endWikiClass(this.parameters);
67    }
68   
 
69  4291 toggle public boolean isEmpty()
70    {
71  4291 return this.properties.isEmpty();
72    }
73   
 
74  37528 toggle public void addProperty(WikiClassProperty property)
75    {
76  37534 this.properties.put(property.name, property);
77    }
78    }
79   
 
80  5030 toggle @Override
81    public WikiClass read(XMLStreamReader xmlReader, XARInputProperties properties)
82    throws XMLStreamException, FilterException
83    {
84  5030 WikiClass wikiClass = new WikiClass();
85   
86  82663 for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
87  77646 String elementName = xmlReader.getLocalName();
88   
89  77638 if (wikiClass.name == null && XARClassModel.ELEMENT_NAME.equals(elementName)) {
90  5024 wikiClass.name = xmlReader.getElementText();
91  5023 wikiClass.parameters.put(WikiClassFilter.PARAMETER_NAME, wikiClass.name);
92  72638 } else if (XARClassModel.CLASS_PARAMETERS.containsKey(elementName)) {
93  35174 String value = xmlReader.getElementText();
94   
95  35177 EventParameter parameter = XARClassModel.CLASS_PARAMETERS.get(elementName);
96   
97  35179 if (parameter != null) {
98  35176 Object wsValue = convert(parameter.type, value);
99  35190 if (wsValue != null) {
100  35189 wikiClass.parameters.put(parameter.name, wsValue);
101    }
102    }
103    } else {
104  37473 wikiClass.addProperty(this.propertyReader.read(xmlReader, properties));
105    }
106    }
107   
108  5030 return wikiClass;
109    }
110    }