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

File XMLInputFilterFactory.java

 

Coverage histogram

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

Code metrics

2
16
3
1
111
65
5
0.31
5.33
3
1.67

Classes

Class Line # Actions
XMLInputFilterFactory 58 16 0% 5 13
0.380952438.1%
 

Contributing tests

This file is covered by 50 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.filterxml.internal.input;
21   
22    import java.util.Collection;
23    import java.util.HashSet;
24    import java.util.List;
25    import java.util.Set;
26   
27    import javax.inject.Inject;
28    import javax.inject.Named;
29    import javax.inject.Provider;
30    import javax.inject.Singleton;
31    import javax.xml.stream.XMLEventWriter;
32    import javax.xml.stream.XMLInputFactory;
33   
34    import org.xwiki.component.annotation.Component;
35    import org.xwiki.component.manager.ComponentLookupException;
36    import org.xwiki.component.manager.ComponentManager;
37    import org.xwiki.filter.FilterException;
38    import org.xwiki.filter.UnknownFilter;
39    import org.xwiki.filter.filterxml.input.FilterXMLInputProperties;
40    import org.xwiki.filter.filterxml.internal.output.XMLOutputFilterFactory;
41    import org.xwiki.filter.output.OutputFilterStreamFactory;
42    import org.xwiki.filter.type.FilterStreamType;
43    import org.xwiki.filter.xml.internal.input.AbstractXMLBeanInputFilterStreamFactory;
44    import org.xwiki.filter.xml.parser.XMLParserFactory;
45   
46    import com.ctc.wstx.api.WstxInputProperties;
47   
48    /**
49    * A generic xml output filter implementation. This class can be used as a test bench to validate various XMLInputStream
50    * wiki parsers.
51    *
52    * @version $Id: 873d5fe2fe1a18b38bfb05e0e6c497ffcad926fb $
53    * @since 6.2M1
54    */
55    @Component
56    @Named("filter+xml")
57    @Singleton
 
58    public class XMLInputFilterFactory extends AbstractXMLBeanInputFilterStreamFactory<FilterXMLInputProperties, Object>
59    {
60    @Inject
61    private XMLParserFactory parserFactory;
62   
63    @Inject
64    private Provider<ComponentManager> contextComponentManager;
65   
66    /**
67    * Default constructor.
68    */
 
69  51 toggle public XMLInputFilterFactory()
70    {
71  51 super(FilterStreamType.FILTER_XML);
72   
73  51 setName("Generic XML input stream");
74  51 setDescription("Generates wiki events from generic XML file.");
75   
76  51 this.xmlFactory = XMLInputFactory.newInstance();
77    // Allow producing XML with several root elements (there is no constraint on events to have a single root
78    // begin/end event)
79  51 this.xmlFactory.setProperty(WstxInputProperties.P_INPUT_PARSING_MODE,
80    WstxInputProperties.PARSING_MODE_FRAGMENT);
81    }
82   
 
83  0 toggle @Override
84    public Collection<Class<?>> getFilterInterfaces() throws FilterException
85    {
86  0 List<OutputFilterStreamFactory> factories;
87  0 try {
88  0 factories = this.contextComponentManager.get().getInstanceList(OutputFilterStreamFactory.class);
89    } catch (ComponentLookupException e) {
90  0 throw new FilterException("Failed to lookup OutputFilterFactory components instances", e);
91    }
92   
93  0 Set<Class<?>> filters = new HashSet<>();
94   
95  0 filters.add(UnknownFilter.class);
96   
97  0 for (OutputFilterStreamFactory factory : factories) {
98  0 if (factory.getClass() != XMLOutputFilterFactory.class) {
99  0 filters.addAll(factory.getFilterInterfaces());
100    }
101    }
102   
103  0 return filters;
104    }
105   
 
106  31 toggle @Override
107    protected XMLEventWriter createXMLEventWriter(Object filter, FilterXMLInputProperties properties)
108    {
109  31 return this.parserFactory.createXMLEventWriter(filter, null);
110    }
111    }