1. Project Clover database Sat Feb 2 2019 06:45:20 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 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.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  7391 toggle public void send(XARInputFilter proxyFilter) throws FilterException
62    {
63  7391 String name = null;
64   
65  7391 if (this.parameters.containsKey(WikiObjectFilter.PARAMETER_CLASS_REFERENCE)) {
66  7391 StringBuilder nameBuilder =
67    new StringBuilder(this.parameters.get(WikiObjectFilter.PARAMETER_CLASS_REFERENCE).toString());
68   
69  7391 if (this.parameters.containsKey(WikiObjectFilter.PARAMETER_NUMBER)) {
70  7391 nameBuilder.append('[');
71  7391 nameBuilder.append(this.parameters.get(WikiObjectFilter.PARAMETER_NUMBER));
72  7391 nameBuilder.append(']');
73    }
74   
75  7391 name = nameBuilder.toString();
76    }
77   
78  7391 proxyFilter.beginWikiObject(name, this.parameters);
79   
80  7391 if (this.wikiClass != null) {
81  7389 this.wikiClass.send(proxyFilter);
82    }
83   
84  7391 for (WikiObjectProperty property : this.properties) {
85  39925 property.send(proxyFilter);
86    }
87   
88  7391 proxyFilter.endWikiObject(name, this.parameters);
89    }
90    }
91   
 
92  7391 toggle @Override
93    public WikiObject read(XMLStreamReader xmlReader, XARInputProperties properties)
94    throws XMLStreamException, FilterException
95    {
96  7391 WikiObject wikiObject = new WikiObject();
97   
98  84282 for (xmlReader.nextTag(); xmlReader.isStartElement(); xmlReader.nextTag()) {
99  76891 String elementName = xmlReader.getLocalName();
100  76891 if (elementName.equals(XARClassModel.ELEMENT_CLASS)) {
101  7389 wikiObject.wikiClass = this.classReader.read(xmlReader, properties);
102  69502 } else if (elementName.equals(XARObjectPropertyModel.ELEMENT_PROPERTY)) {
103  39925 wikiObject.properties.add(readObjectProperty(xmlReader, properties, wikiObject.wikiClass));
104    } else {
105  29577 String value = xmlReader.getElementText();
106   
107  29577 EventParameter parameter = XARObjectModel.OBJECT_PARAMETERS.get(elementName);
108   
109  29577 if (parameter != null) {
110  29577 Object wsValue = convert(parameter.type, value);
111  29577 if (wsValue != null) {
112  29577 wikiObject.parameters.put(parameter.name, wsValue);
113    }
114    }
115    }
116    }
117   
118  7391 return wikiObject;
119    }
120    }