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

File DefaultXMLParserFactory.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

4
10
5
1
116
65
7
0.7
2
5
1.4

Classes

Class Line # Actions
DefaultXMLParserFactory 51 10 0% 7 9
0.526315852.6%
 

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 javax.inject.Inject;
23    import javax.inject.Singleton;
24    import javax.xml.stream.XMLEventWriter;
25    import javax.xml.stream.XMLStreamException;
26    import javax.xml.transform.Result;
27    import javax.xml.transform.Source;
28    import javax.xml.transform.stax.StAXResult;
29    import javax.xml.transform.stax.StAXSource;
30   
31    import org.xml.sax.ContentHandler;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.filter.FilterDescriptorManager;
34    import org.xwiki.filter.xml.XMLConfiguration;
35    import org.xwiki.filter.xml.internal.parameter.ParameterManager;
36    import org.xwiki.filter.xml.parser.XMLParserFactory;
37    import org.xwiki.properties.ConverterManager;
38    import org.xwiki.xml.stax.SAXEventWriter;
39   
40    import javanet.staxutils.XMLEventStreamWriter;
41    import javanet.staxutils.XMLStreamUtils;
42   
43    /**
44    * Default implementation of {@link XMLParserFactory}.
45    *
46    * @version $Id: 637ecd748926bce4008a29bc3d2b606499e4caf5 $
47    * @since 5.2M1
48    */
49    @Component
50    @Singleton
 
51    public class DefaultXMLParserFactory implements XMLParserFactory
52    {
53    /**
54    * The parameter converter.
55    */
56    @Inject
57    private ParameterManager parameterManager;
58   
59    /**
60    * The events supported by the listener.
61    */
62    @Inject
63    private FilterDescriptorManager descriptorManager;
64   
65    /**
66    * Used to convert simple types.
67    */
68    @Inject
69    private ConverterManager converter;
70   
71    /**
72    * @param filter the filter to send events to
73    * @param configuration the configuration of the parser
74    * @return the parser as a {@link ContentHandler}.
75    */
 
76  640 toggle private ContentHandler createParser(Object filter, XMLConfiguration configuration)
77    {
78  640 return new DefaultXMLParser(filter, this.descriptorManager.getFilterDescriptor(filter.getClass()),
79    this.converter, this.parameterManager, configuration);
80    }
81   
 
82  6 toggle @Override
83    public void parse(Source source, Object filter, XMLConfiguration configuration) throws XMLStreamException
84    {
85  6 if (source instanceof StAXSource) {
86    // StAXSource is not supported by standard XMLInputFactory
87  0 StAXSource staxSource = (StAXSource) source;
88  0 if (staxSource.getXMLEventReader() != null) {
89  0 XMLStreamUtils.copy(staxSource.getXMLEventReader(), createXMLEventWriter(filter, configuration));
90    } else {
91  0 XMLStreamUtils.copy(staxSource.getXMLStreamReader(),
92    new XMLEventStreamWriter(createXMLEventWriter(filter, configuration)));
93    }
94    } else {
95  6 XMLStreamUtils.copy(source, createXMLEventWriter(filter, configuration));
96    }
97    }
98   
 
99  0 toggle @Override
100    public Result createResult(Object filter, XMLConfiguration configuration)
101    {
102  0 return new StAXResult(createXMLEventWriter(filter, configuration));
103    }
104   
 
105  32 toggle @Override
106    public XMLEventWriter createXMLEventWriter(Object filter, XMLConfiguration configuration)
107    {
108  32 return new SAXEventWriter(createParser(filter, configuration));
109    }
110   
 
111  608 toggle @Override
112    public ContentHandler createContentHandler(Object filter, XMLConfiguration configuration)
113    {
114  608 return createParser(filter, configuration);
115    }
116    }