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

File XMLOutputFilterStreamUtils.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

8
13
1
1
71
38
5
0.38
13
1
5

Classes

Class Line # Actions
XMLOutputFilterStreamUtils 42 13 0% 5 2
0.9090909490.9%
 

Contributing tests

This file is covered by 29 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.output;
21   
22    import java.io.IOException;
23   
24    import javax.xml.stream.XMLOutputFactory;
25    import javax.xml.stream.XMLStreamException;
26    import javax.xml.stream.XMLStreamWriter;
27   
28    import org.xwiki.filter.FilterException;
29    import org.xwiki.filter.output.OutputStreamOutputTarget;
30    import org.xwiki.filter.output.OutputTarget;
31    import org.xwiki.filter.output.WriterOutputTarget;
32    import org.xwiki.filter.xml.output.ResultOutputTarget;
33    import org.xwiki.filter.xml.output.XMLOutputProperties;
34    import org.xwiki.xml.stax.StAXUtils;
35   
36    import javanet.staxutils.IndentingXMLStreamWriter;
37   
38    /**
39    * @version $Id: 4b475b3de8c178e7b4fe963b68ac190eb3392ea5 $
40    * @since 6.2M1
41    */
 
42    public final class XMLOutputFilterStreamUtils
43    {
 
44  7604 toggle public static XMLStreamWriter createXMLStreamWriter(XMLOutputProperties properties) throws XMLStreamException,
45    IOException, FilterException
46    {
47  7604 XMLStreamWriter xmlStreamWriter;
48   
49  7604 OutputTarget target = properties.getTarget();
50   
51  7604 XMLOutputFactory factory = XMLOutputFactory.newInstance();
52   
53  7604 if (target instanceof WriterOutputTarget) {
54  7578 xmlStreamWriter = factory.createXMLStreamWriter(((WriterOutputTarget) target).getWriter());
55  26 } else if (target instanceof OutputStreamOutputTarget) {
56  25 xmlStreamWriter =
57    factory.createXMLStreamWriter(((OutputStreamOutputTarget) target).getOutputStream(),
58    properties.getEncoding());
59  1 } else if (target instanceof ResultOutputTarget) {
60  1 xmlStreamWriter = StAXUtils.getXMLStreamWriter(((ResultOutputTarget) target).getResult());
61    } else {
62  0 throw new FilterException("Unknown target type [" + target.getClass() + "]");
63    }
64   
65  7604 if (properties.isFormat()) {
66  6344 xmlStreamWriter = new IndentingXMLStreamWriter(xmlStreamWriter);
67    }
68   
69  7604 return xmlStreamWriter;
70    }
71    }