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

File XMLInputFilterStreamUtils.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

12
20
2
1
84
49
8
0.4
10
2
4

Classes

Class Line # Actions
XMLInputFilterStreamUtils 41 20 0% 8 23
0.3235294232.4%
 

Contributing tests

This file is covered by 49 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: 813dec54f32e7e710e8cf7e7113afd393f35d0bf $
39    * @since 6.2M1
40    */
 
41    public final class XMLInputFilterStreamUtils
42    {
43    private static final XMLInputFactory XML_INPUT_FACTORY = XMLInputFactory.newInstance();
44   
 
45  0 toggle public static XMLEventReader createXMLEventReader(XMLInputProperties properties)
46    throws XMLStreamException, IOException, FilterException
47    {
48  0 XMLEventReader xmlEventReader;
49   
50  0 InputSource source = properties.getSource();
51   
52  0 if (source instanceof ReaderInputSource) {
53  0 xmlEventReader = XML_INPUT_FACTORY.createXMLEventReader(((ReaderInputSource) source).getReader());
54  0 } else if (source instanceof InputStreamInputSource) {
55  0 xmlEventReader = XML_INPUT_FACTORY.createXMLEventReader(((InputStreamInputSource) source).getInputStream());
56  0 } else if (source instanceof SourceInputSource) {
57  0 xmlEventReader = StAXUtils.getXMLEventReader(((SourceInputSource) source).getSource());
58    } else {
59  0 throw new FilterException("Unknown source type [" + source.getClass() + "]");
60    }
61   
62  0 return xmlEventReader;
63    }
64   
 
65  4283 toggle public static XMLStreamReader createXMLStreamReader(XMLInputProperties properties)
66    throws XMLStreamException, IOException, FilterException
67    {
68  4283 XMLStreamReader xmlStreamReader;
69   
70  4283 InputSource source = properties.getSource();
71   
72  4283 if (source instanceof ReaderInputSource) {
73  1798 xmlStreamReader = XML_INPUT_FACTORY.createXMLStreamReader(((ReaderInputSource) source).getReader());
74  2485 } else if (source instanceof InputStreamInputSource) {
75  2485 xmlStreamReader = XML_INPUT_FACTORY.createXMLStreamReader(((InputStreamInputSource) source).getInputStream());
76  0 } else if (source instanceof SourceInputSource) {
77  0 xmlStreamReader = StAXUtils.getXMLStreamReader(((SourceInputSource) source).getSource());
78    } else {
79  0 throw new FilterException("Unknown source type [" + source.getClass() + "]");
80    }
81   
82  4282 return xmlStreamReader;
83    }
84    }