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

File DefaultXMLParser.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

108
171
25
2
520
392
97
0.57
6.84
12.5
3.88

Classes

Class Line # Actions
DefaultXMLParser 64 117 0% 66 37
0.8221153682.2%
DefaultXMLParser.Block 87 54 0% 31 21
0.7812578.1%
 

Contributing tests

This file is covered by 618 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.xml.internal.parser;
21   
22    import java.lang.reflect.InvocationTargetException;
23    import java.lang.reflect.Method;
24    import java.lang.reflect.Type;
25    import java.util.ArrayList;
26    import java.util.Arrays;
27    import java.util.List;
28    import java.util.Stack;
29    import java.util.regex.Matcher;
30   
31    import javax.xml.parsers.ParserConfigurationException;
32   
33    import org.apache.commons.lang3.ArrayUtils;
34    import org.apache.xerces.parsers.XMLParser;
35    import org.slf4j.Logger;
36    import org.slf4j.LoggerFactory;
37    import org.w3c.dom.Element;
38    import org.w3c.dom.Node;
39    import org.w3c.dom.NodeList;
40    import org.xml.sax.Attributes;
41    import org.xml.sax.ContentHandler;
42    import org.xml.sax.SAXException;
43    import org.xml.sax.helpers.DefaultHandler;
44    import org.xwiki.component.util.ReflectionUtils;
45    import org.xwiki.filter.FilterDescriptor;
46    import org.xwiki.filter.FilterElementDescriptor;
47    import org.xwiki.filter.FilterElementParameterDescriptor;
48    import org.xwiki.filter.FilterEventParameters;
49    import org.xwiki.filter.UnknownFilter;
50    import org.xwiki.filter.xml.XMLConfiguration;
51    import org.xwiki.filter.xml.internal.XMLUtils;
52    import org.xwiki.filter.xml.internal.parameter.ParameterManager;
53    import org.xwiki.properties.ConverterManager;
54    import org.xwiki.properties.converter.ConversionException;
55    import org.xwiki.xml.Sax2Dom;
56   
57    /**
58    * Default implementation of {@link XMLParser}.
59    *
60    * @version $Id: 1edc7186f7c21910c18514962e1d95a094e3407f $
61    * @since 5.2M1
62    */
63    // TODO: move from ContentHandler to XMLEventConsumer or XMLEventWriter
 
64    public class DefaultXMLParser extends DefaultHandler implements ContentHandler
65    {
66    /**
67    * Logging helper object.
68    */
69    protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultXMLParser.class);
70   
71    private ParameterManager parameterManager;
72   
73    private ConverterManager stringConverter;
74   
75    private FilterDescriptor filterDescriptor;
76   
77    private Object filter;
78   
79    private Stack<Block> blockStack = new Stack<Block>();
80   
81    private int elementDepth = 0;
82   
83    private StringBuilder content;
84   
85    private XMLConfiguration configuration;
86   
 
87    public static class Block
88    {
89    public String name;
90   
91    public FilterElementDescriptor filterElement;
92   
93    public boolean beginSent = false;
94   
95    public List<Object> parameters = new ArrayList<Object>();
96   
97    public FilterEventParameters namedParameters = new FilterEventParameters();
98   
99    public Sax2Dom parametersDOMBuilder;
100   
101    public int elementDepth;
102   
103    private Object[] parametersTable;
104   
 
105  8066 toggle public Block(String name, FilterElementDescriptor listenerElement, int elementDepth)
106    {
107  8066 this.name = name;
108  8066 this.filterElement = listenerElement;
109  8066 this.elementDepth = elementDepth;
110    }
111   
 
112  16132 toggle public boolean isContainer()
113    {
114  16132 return this.filterElement == null || this.filterElement.getBeginMethod() != null;
115    }
116   
 
117  0 toggle public void setParameter(String name, Object value)
118    {
119  0 this.namedParameters.put(name, value);
120    }
121   
 
122  5593 toggle public void setParameter(int index, Object value)
123    {
124  11232 for (int i = this.parameters.size(); i <= index; ++i) {
125  5639 this.parameters.add(this.filterElement.getParameters()[i].getDefaultValue());
126    }
127   
128  5593 this.parameters.set(index, value);
129  5593 this.parametersTable = null;
130    }
131   
 
132  5015 toggle public List<Object> getParametersList()
133    {
134  5015 return this.parameters;
135    }
136   
 
137  11101 toggle public Object[] getParametersTable()
138    {
139  11101 if (this.parametersTable == null) {
140  8058 if (this.parameters.isEmpty()) {
141  3287 this.parametersTable = ArrayUtils.EMPTY_OBJECT_ARRAY;
142    }
143   
144  8058 this.parametersTable = this.parameters.toArray();
145    }
146   
147  11101 return this.parametersTable;
148    }
149   
 
150  3051 toggle public void fireBeginEvent(Object listener) throws SAXException
151    {
152  3051 if (this.filterElement != null) {
153  3043 fireEvent(this.filterElement.getBeginMethod(), listener);
154  8 } else if (listener instanceof UnknownFilter) {
155  0 try {
156  0 ((UnknownFilter) listener).beginUnknwon(this.name, this.namedParameters);
157    } catch (Exception e) {
158