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

File XMLInputFilterFactory.java

 

Coverage histogram

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

Code metrics

2
14
3
1
103
61
5
0.36
4.67
3
1.67

Classes

Class Line # Actions
XMLInputFilterFactory 55 14 0% 5 13
0.3157894631.6%
 

Contributing tests

This file is covered by 41 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   
33    import org.xwiki.component.annotation.Component;
34    import org.xwiki.component.manager.ComponentLookupException;
35    import org.xwiki.component.manager.ComponentManager;
36    import org.xwiki.filter.FilterException;
37    import org.xwiki.filter.UnknownFilter;
38    import org.xwiki.filter.filterxml.input.FilterXMLInputProperties;
39    import org.xwiki.filter.filterxml.internal.output.XMLOutputFilterFactory;
40    import org.xwiki.filter.output.OutputFilterStreamFactory;
41    import org.xwiki.filter.type.FilterStreamType;
42    import org.xwiki.filter.xml.internal.input.AbstractXMLBeanInputFilterStreamFactory;
43    import org.xwiki.filter.xml.parser.XMLParserFactory;
44   
45    /**
46    * A generic xml output filter implementation. This class can be used as a test bench to validate various XMLInputStream
47    * wiki parsers.
48    *
49    * @version $Id: 2a6171ed6f12d58efff82a8b4146df7478f88f39 $
50    * @since 6.2M1
51    */
52    @Component
53    @Named("filter+xml")
54    @Singleton
 
55    public class XMLInputFilterFactory extends
56    AbstractXMLBeanInputFilterStreamFactory<FilterXMLInputProperties, Object>
57    {
58    @Inject
59    private XMLParserFactory parserFactory;
60   
61    @Inject
62    private Provider<ComponentManager> contextComponentManager;
63   
64    /**
65    * Default constructor.
66    */
 
67  42 toggle public XMLInputFilterFactory()
68    {
69  42 super(FilterStreamType.FILTER_XML);
70   
71  42 setName("Generic XML input stream");
72  42 setDescription("Generates wiki events from generic XML file.");
73    }
74   
 
75  0 toggle @Override
76    public Collection<Class<?>> getFilterInterfaces() throws FilterException
77    {
78  0 List<OutputFilterStreamFactory> factories;
79  0 try {
80  0 factories = this.contextComponentManager.get().getInstanceList(OutputFilterStreamFactory.class);
81    } catch (ComponentLookupException e) {
82  0 throw new FilterException("Failed to lookup OutputFilterFactory components instances", e);
83    }
84   
85  0 Set<Class<?>> filters = new HashSet<Class<?>>();
86   
87  0 filters.add(UnknownFilter.class);
88   
89  0 for (OutputFilterStreamFactory factory : factories) {
90  0 if (factory.getClass() != XMLOutputFilterFactory.class) {
91  0 filters.addAll(factory.getFilterInterfaces());
92    }
93    }
94   
95  0 return filters;
96    }
97   
 
98  26 toggle @Override
99    protected XMLEventWriter createXMLEventWriter(Object filter, FilterXMLInputProperties parameters)
100    {
101  26 return this.parserFactory.createXMLEventWriter(filter, null);
102    }
103    }