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

File InstanceInputFilterStreamFactory.java

 

Coverage histogram

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

Code metrics

2
22
3
1
115
74
6
0.27
7.33
3
2

Classes

Class Line # Actions
InstanceInputFilterStreamFactory 56 22 0% 6 2
0.925925992.6%
 

Contributing tests

This file is covered by 1 test. .

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.instance.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   
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.component.manager.ComponentLookupException;
34    import org.xwiki.component.manager.ComponentManager;
35    import org.xwiki.component.phase.InitializationException;
36    import org.xwiki.filter.FilterException;
37    import org.xwiki.filter.descriptor.CompositeFilterStreamDescriptor;
38    import org.xwiki.filter.descriptor.FilterStreamDescriptor;
39    import org.xwiki.filter.input.AbstractBeanInputFilterStreamFactory;
40    import org.xwiki.filter.instance.input.InstanceInputEventGenerator;
41    import org.xwiki.filter.instance.input.InstanceInputProperties;
42    import org.xwiki.filter.instance.internal.InstanceFilter;
43    import org.xwiki.filter.instance.internal.InstanceUtils;
44    import org.xwiki.filter.type.FilterStreamType;
45   
46    /**
47    * A generic xml output filter implementation. This class can be used as a test bench to validate various
48    * XMLInputStream wiki parsers.
49    *
50    * @version $Id: 0dccfa8f6afc8133fb002cc04407a836b9f72c7c $
51    * @since 6.2M1
52    */
53    @Component
54    @Named(InstanceUtils.ROLEHINT)
55    @Singleton
 
56    public class InstanceInputFilterStreamFactory extends
57    AbstractBeanInputFilterStreamFactory<InstanceInputProperties, InstanceFilter>
58    {
59    public static final String ROLEHINT = "xwiki+instance";
60   
61    @Inject
62    @Named("context")
63    private Provider<ComponentManager> componentManagerProvider;
64   
 
65  2 toggle public InstanceInputFilterStreamFactory()
66    {
67  2 super(FilterStreamType.XWIKI_INSTANCE);
68   
69  2 setName("XWiki instance input stream");
70  2 setDescription("Generates wiki events from XWiki instance.");
71    }
72   
 
73  2 toggle @Override
74    public void initialize() throws InitializationException
75    {
76  2 super.initialize();
77   
78  2 List<InstanceInputEventGenerator> eventGenerators;
79  2 try {
80  2 eventGenerators = this.componentManagerProvider.get().getInstanceList(InstanceInputEventGenerator.class);
81    } catch (ComponentLookupException e) {
82  0 throw new InitializationException(
83    "Failed to get registered instance of InstanceInputEventGenerator components", e);
84    }
85   
86  2 FilterStreamDescriptor[] descriptors = new FilterStreamDescriptor[eventGenerators.size() + 1];
87   
88  2 descriptors[0] = this.descriptor;
89  4 for (int i = 0; i < eventGenerators.size(); ++i) {
90  2 descriptors[i + 1] = eventGenerators.get(i).getDescriptor();
91    }
92   
93  2 setDescriptor(new CompositeFilterStreamDescriptor(this.descriptor.getName(), this.descriptor.getDescription(),
94    descriptors));
95    }
96   
 
97  2 toggle @Override
98    public Collection<Class< ? >> getFilterInterfaces() throws FilterException
99    {
100  2 List<InstanceInputEventGenerator> eventGenerators;
101  2 try {
102  2 eventGenerators = this.componentManagerProvider.get().getInstanceList(InstanceInputEventGenerator.class);
103    } catch (ComponentLookupException e) {
104  0 throw new FilterException("Failed to get registered instance of InstanceInputEventGenerator components", e);
105    }
106   
107  2 Set<Class< ? >> filters = new HashSet<Class< ? >>();
108  2 filters.addAll(super.getFilterInterfaces());
109  2 for (InstanceInputEventGenerator generator : eventGenerators) {
110  2 filters.addAll(generator.getFilterInterfaces());
111    }
112   
113  2 return filters;
114    }
115    }