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

File WikiObjectReader.java

 

Coverage histogram

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

Code metrics

16
28
2
2
120
77
10
0.36
14
1
5

Classes

Class Line # Actions
WikiObjectReader 47 14 0% 6 2
0.9292%
WikiObjectReader.WikiObject 53 14 0% 4 2
0.904761990.5%
 

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.ArrayList;
23    import java.util.List;
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.WikiObjectFilter;
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.XARObjectModel;
38    import org.xwiki.filter.xar.internal.XARObjectPropertyModel;
39    import org.xwiki.filter.xar.internal.input.ClassReader.WikiClass;
40   
41    /**
42    * @version $Id: ae137a570903d6dd5be8a78280db30d406cca8d2 $
43    * @since 6.2M1
44    */
45    @Component
46    @Singleton
 
47    public class WikiObjectReader extends AbstractWikiObjectPropertyReader
48    implements XARXMLReader<WikiObjectReader.WikiObject>
49    {
50    @Inject
51    private XARXMLReader<ClassReader.WikiClass> classReader;
52   
 
53    public static class WikiObject
54    {
55    public WikiClass wikiClass;
56   
57    public FilterEventParameters parameters = new FilterEventParameters();
58   
59    private List<WikiObjectProperty> properties = new ArrayList<WikiObjectProperty>();
60   
 
61  2958 toggle public void send(XARInputFilter proxyFilter) throws FilterException
62    {
63  2958 String name = null;
64   
65  2958 if (this.parameters.containsKey(WikiObjectFilter.PARAMETER_CLASS_REFERENCE)) {
66  2958 StringBuilder nameBuilder =
67    new StringBuilder(this.parameters.get(WikiObjectFilter.PARAMETER_CLASS_REFERENCE).toString());
68   
69  2958 if (this.parameters.containsKey(WikiObjectFilter.PARAMETER_NUMBER)) {
70  2958 nameBuilder.append('[');
71  2958 nameBuilder.append(this.parameters.get(WikiObjectFilter.PARAMETER_NUMBER));
72  2958 nameBuilder.append(']');
73    }
74   
75  2958 name = nameBuilder.toString();
76    }
77   
78  2958 proxyFilter.beginWikiObject(name, this.parameters);
79   
80  2958 if (this.wikiClass != null) {
81  2956 this.wikiClass.send(proxyFilter);
82    }
83   
84  2958 for (WikiObjectProperty property : this.properties) {
85  12325 property.send(proxyFilter);
86    }
87   
88  2958 proxyFilter.endWikiObject(name, this.parameters);
89    }
90    }
91   
 
92  2958 toggle @Override
93    public WikiObject read(XMLStreamReader xmlReader, XARInputProperties properties)
94    throws XMLStreamException, FilterException
95    {
96  2958 WikiObject wikiObject = new WikiObject();
97   
98  30064 for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
99  27106 String elementName = xmlReader.getLocalName();
100  27106 if (elementName.equals(XARClassModel.ELEMENT_CLASS)) {
101  2956 wikiObject.wikiClass = this.classReader.read(xmlReader, properties);
102  24150 } else if (elementName.equals(XARObjectPropertyModel.ELEMENT_PROPERTY)) {
103  12325 wikiObject.properties.add(readObjectProperty(xmlReader, properties, wikiObject.wikiClass));
104    } else {
105  11825 String value = xmlReader.getElementText();
106   
107  11825 EventParameter parameter = XARObjectModel.OBJECT_PARAMETERS.get(elementName);
108   
109  11825 if (parameter != null) {
110  11825 Object wsValue = convert(parameter.type, value);
111  11825 if (wsValue != null) {
112  11825 wikiObject.parameters.put(parameter.name, wsValue);
113    }
114    }
115    }
116    }
117   
118  2958 return wikiObject;
119    }
120    }