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

File XMLOutputFilterFactory.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
14
3
1
109
66
5
0.36
4.67
3
1.67

Classes

Class Line # Actions
XMLOutputFilterFactory 58 14 0% 5 1
0.9473684494.7%
 

Contributing tests

This file is covered by 24 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.output;
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.FactoryConfigurationError;
32    import javax.xml.stream.XMLStreamException;
33    import javax.xml.transform.Result;
34   
35    import org.apache.commons.lang3.ArrayUtils;
36    import org.xwiki.component.annotation.Component;
37    import org.xwiki.component.manager.ComponentLookupException;
38    import org.xwiki.component.manager.ComponentManager;
39    import org.xwiki.filter.FilterException;
40    import org.xwiki.filter.UnknownFilter;
41    import org.xwiki.filter.filterxml.internal.input.XMLInputFilterFactory;
42    import org.xwiki.filter.filterxml.output.FilterXMLOutputProperties;
43    import org.xwiki.filter.input.InputFilterStreamFactory;
44    import org.xwiki.filter.type.FilterStreamType;
45    import org.xwiki.filter.xml.internal.output.AbstractXMLBeanOutputFilterStreamFactory;
46    import org.xwiki.filter.xml.serializer.XMLSerializerFactory;
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: bd32aab6ddcedc15f97b0c20d5c7a96ebcb77a83 $
53    * @since 6.2M1
54    */
55    @Component
56    @Named("filter+xml")
57    @Singleton
 
58    public class XMLOutputFilterFactory extends
59    AbstractXMLBeanOutputFilterStreamFactory<FilterXMLOutputProperties, Object>
60    {
61    @Inject
62    private XMLSerializerFactory serializerFactory;
63   
64    @Inject
65    private Provider<ComponentManager> contextComponentManager;
66   
67    /**
68    * Default constructor.
69    */
 
70  25 toggle public XMLOutputFilterFactory()
71    {
72  25 super(FilterStreamType.FILTER_XML);
73   
74  25 setName("Generic XML output stream");
75  25 setDescription("Write generic XML from wiki events.");
76    }
77   
 
78  25 toggle @Override
79    public Collection<Class<?>> getFilterInterfaces() throws FilterException
80    {
81  25 List<InputFilterStreamFactory> factories;
82  25 try {
83  25 factories = this.contextComponentManager.get().getInstanceList(InputFilterStreamFactory.class);
84    } catch (ComponentLookupException e) {
85  0 throw new FilterException("Failed to lookup InputFilterFactory components instances", e);
86    }
87   
88  25 Set<Class<?>> filters = new HashSet<Class<?>>();
89   
90  25 filters.add(UnknownFilter.class);
91   
92  25 for (InputFilterStreamFactory factory : factories) {
93  96 if (factory.getClass() != XMLInputFilterFactory.class) {
94  71 filters.addAll(factory.getFilterInterfaces());
95    }
96    }
97   
98  25 return filters;
99    }
100   
 
101  25 toggle @Override
102    protected Object createListener(Result result, FilterXMLOutputProperties properties) throws XMLStreamException,
103    FactoryConfigurationError, FilterException
104    {
105   
106  25 return this.serializerFactory.createSerializer(getFilterInterfaces().toArray(ArrayUtils.EMPTY_CLASS_ARRAY),
107    result, null);
108    }
109    }