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

File OutputTargetConverter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

12
18
2
1
84
49
8
0.44
9
2
4

Classes

Class Line # Actions
OutputTargetConverter 43 18 0% 8 12
0.62562.5%
 

Contributing tests

No tests hitting this source file were found.

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.internal.output;
21   
22    import java.io.File;
23    import java.io.OutputStream;
24    import java.io.Writer;
25    import java.lang.reflect.Type;
26   
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.filter.output.DefaultFileOutputTarget;
31    import org.xwiki.filter.output.DefaultOutputStreamOutputTarget;
32    import org.xwiki.filter.output.DefaultWriterOutputTarget;
33    import org.xwiki.filter.output.OutputTarget;
34    import org.xwiki.filter.output.StringWriterOutputTarget;
35    import org.xwiki.properties.converter.AbstractConverter;
36   
37    /**
38    * @version $Id: 70661a45286ddf903cb568b60051db0357594ed9 $
39    * @since 6.2M1
40    */
41    @Component
42    @Singleton
 
43    public class OutputTargetConverter extends AbstractConverter<OutputTarget>
44    {
 
45  1 toggle @Override
46    protected <G extends OutputTarget> G convertToType(Type targetType, Object value)
47    {
48  1 if (value == null) {
49  0 return null;
50    }
51   
52  1 if (value instanceof OutputTarget) {
53  0 return (G) value;
54    }
55   
56  1 OutputTarget outputTarget;
57   
58  1 if (value instanceof OutputStream) {
59  0 outputTarget = new DefaultOutputStreamOutputTarget((OutputStream) value);
60  1 } else if (value instanceof File) {
61  0 outputTarget = new DefaultFileOutputTarget((File) value);
62  1 } else if (value instanceof Writer) {
63  0 outputTarget = new DefaultWriterOutputTarget((Writer) value);
64    } else {
65  1 outputTarget = fromString(value.toString());
66    }
67   
68  1 return (G) outputTarget;
69    }
70   
 
71  1 toggle private OutputTarget fromString(String target)
72    {
73  1 OutputTarget outputTarget;
74   
75    // TODO: use some OutputTargetParser instead to make it extensible
76  1 if (target.startsWith("file:")) {
77  1 outputTarget = new DefaultFileOutputTarget(new File(target.substring("file:".length())));
78    } else {
79  0 outputTarget = new StringWriterOutputTarget();
80    }
81   
82  1 return outputTarget;
83    }
84    }