1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.filter.xml.internal.input

File XMLInputFilterStreamUtils.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart7.png
66% of files have more coverage

Code metrics

14
22
4
1
101
60
11
0.5
5.5
4
2.75

Classes

Class Line # Actions
XMLInputFilterStreamUtils 41 22 0% 11 15
0.62562.5%
 

Contributing tests

This file is covered by 83 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.input;
21   
22    import java.io.IOException;
23   
24    import javax.xml.stream.XMLEventReader;
25    import javax.xml.stream.XMLInputFactory;
26    import javax.xml.stream.XMLStreamException;
27    import javax.xml.stream.XMLStreamReader;
28   
29    import org.xwiki.filter.FilterException;
30    import org.xwiki.filter.input.InputSource;
31    import org.xwiki.filter.input.InputStreamInputSource;
32    import org.xwiki.filter.input.ReaderInputSource;
33    import org.xwiki.filter.xml.input.SourceInputSource;
34    import org.xwiki.filter.xml.input.XMLInputProperties;
35    import org.xwiki.xml.stax.StAXUtils;
36   
37    /**
38    * @version $Id: bbdfbe20089b243ea1248063d2180d5d537ff11e $
39    * @since 6.2M1
40    */
 
41    public final class XMLInputFilterStreamUtils
42    {
43    private static final XMLInputFactory XML_INPUT_FACTORY = XMLInputFactory.newInstance();
44   
45    /**
46    * @since 9.5.2
47    * @since 9.6RC1
48    */
 
49  0 toggle public static XMLEventReader createXMLEventReader(XMLInputProperties properties)
50    throws XMLStreamException, IOException, FilterException
51    {
52  0 return createXMLEventReader(XML_INPUT_FACTORY, properties);
53    }
54   
 
55  31 toggle public static XMLEventReader createXMLEventReader(XMLInputFactory factory, XMLInputProperties properties)
56    throws XMLStreamException, IOException, FilterException
57    {
58  31 XMLEventReader xmlEventReader;
59   
60  31 InputSource source = properties.getSource();
61   
62  31 if (source instanceof ReaderInputSource) {
63  16 xmlEventReader = getXMLInputFactory(factory).createXMLEventReader(((ReaderInputSource) source).getReader());
64  15 } else if (source instanceof InputStreamInputSource) {
65  15 xmlEventReader =
66    getXMLInputFactory(factory).createXMLEventReader(((InputStreamInputSource) source).getInputStream());
67  0 } else if (source instanceof SourceInputSource) {
68  0 xmlEventReader = StAXUtils.getXMLEventReader(((SourceInputSource) source).getSource());
69    } else {
70  0 throw new FilterException("Unknown source type [" + source.getClass() + "]");
71    }
72   
73  31 return xmlEventReader;
74    }
75   
 
76  12651 toggle public static XMLStreamReader createXMLStreamReader(XMLInputProperties properties)
77    throws XMLStreamException, IOException, FilterException
78    {
79  12651 XMLStreamReader xmlStreamReader;
80   
81  12651 InputSource source = properties.getSource();
82   
83  12651 if (source instanceof ReaderInputSource) {
84  5060 xmlStreamReader = XML_INPUT_FACTORY.createXMLStreamReader(((ReaderInputSource) source).getReader());
85  7591 } else if (source instanceof InputStreamInputSource) {
86  7591 xmlStreamReader =
87    XML_INPUT_FACTORY.createXMLStreamReader(((InputStreamInputSource) source).getInputStream());
88  0 } else if (source instanceof SourceInputSource) {
89  0 xmlStreamReader = StAXUtils.getXMLStreamReader(((SourceInputSource) source).getSource());
90    } else {
91  0 throw new FilterException("Unknown source type [" + source.getClass() + "]");
92    }
93   
94  12651 return xmlStreamReader;
95    }
96   
 
97  31 toggle private static XMLInputFactory getXMLInputFactory(XMLInputFactory factory)
98    {
99  31 return factory != null ? factory : XML_INPUT_FACTORY;
100    }
101    }