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

File DefaultXMLSerializerFactory.java

 

Coverage histogram

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

Code metrics

2
8
4
1
102
56
5
0.62
2
4
1.25

Classes

Class Line # Actions
DefaultXMLSerializerFactory 47 8 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 308 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.serializer;
21   
22    import java.io.Closeable;
23    import java.lang.reflect.Proxy;
24   
25    import javax.inject.Inject;
26    import javax.inject.Singleton;
27    import javax.xml.stream.FactoryConfigurationError;
28    import javax.xml.stream.XMLStreamException;
29    import javax.xml.transform.Result;
30   
31    import org.apache.commons.lang3.ArrayUtils;
32    import org.xwiki.component.annotation.Component;
33    import org.xwiki.filter.FilterDescriptorManager;
34    import org.xwiki.filter.xml.XMLConfiguration;
35    import org.xwiki.filter.xml.internal.parameter.ParameterManager;
36    import org.xwiki.filter.xml.serializer.XMLSerializerFactory;
37    import org.xwiki.properties.ConverterManager;
38   
39    /**
40    * Default implementation of {@link XMLSerializerFactory}.
41    *
42    * @version $Id: b85390845a750a3ff2228d4eb00a26db33c6ec61 $
43    * @since 5.2M1
44    */
45    @Component
46    @Singleton
 
47    public class DefaultXMLSerializerFactory implements XMLSerializerFactory
48    {
49    /**
50    * The parameter converter.
51    */
52    @Inject
53    private ParameterManager parameterManager;
54   
55    /**
56    * The events supported by the filter.
57    */
58    @Inject
59    private FilterDescriptorManager descriptorManager;
60   
61    /**
62    * Used to convert simple types.
63    */
64    @Inject
65    private ConverterManager converter;
66   
 
67  539 toggle @Override
68    public <T> T createSerializer(Class<T> filterInterface, Result xmlResult, XMLConfiguration configuration)
69    throws XMLStreamException, FactoryConfigurationError
70    {
71  539 return createSerializer(new Class<?>[] { filterInterface, Closeable.class }, xmlResult, configuration);
72    }
73   
 
74  564 toggle @Override
75    public <T> T createSerializer(Class<?>[] filterInterfaces, Result xmlResult, XMLConfiguration configuration)
76    throws XMLStreamException, FactoryConfigurationError
77    {
78  564 return createSerializerInternal(addCloseable(filterInterfaces), xmlResult, configuration);
79    }
80   
 
81  564 toggle private Class<?>[] addCloseable(Class<?>[] filterInterfaces)
82    {
83  564 for (Class<?> i : filterInterfaces) {
84  1132 if (i == Closeable.class) {
85  539 return filterInterfaces;
86    }
87    }
88   
89  25 return ArrayUtils.add(filterInterfaces, Closeable.class);
90    }
91   
 
92  564 toggle private <T> T createSerializerInternal(Class<?>[] filterInterfaces, Result xmlResult,
93    XMLConfiguration configuration)
94    throws XMLStreamException, FactoryConfigurationError
95    {
96  564 DefaultXMLSerializer handler =
97    new DefaultXMLSerializer(xmlResult, this.parameterManager,
98    this.descriptorManager.getFilterDescriptor(filterInterfaces), this.converter, configuration);
99   
100  564 return (T) Proxy.newProxyInstance(filterInterfaces[0].getClassLoader(), filterInterfaces, handler);
101    }
102    }