1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.filter.xar.internal.input

File AbstractReader.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

22
22
2
1
78
47
14
0.64
11
2
7

Classes

Class Line # Actions
AbstractReader 36 22 0% 14 7
0.8478260684.8%
 

Contributing tests

This file is covered by 36 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   
21    package org.xwiki.filter.xar.internal.input;
22   
23    import java.util.Date;
24    import java.util.Locale;
25   
26    import org.apache.commons.lang3.LocaleUtils;
27    import org.apache.commons.lang3.StringUtils;
28    import org.xwiki.filter.FilterException;
29    import org.xwiki.rendering.parser.ParseException;
30    import org.xwiki.rendering.syntax.Syntax;
31   
32    /**
33    * @version $Id: 33df362ab3fd424d8db687fe9d80e4e5db69c9e8 $
34    * @since 6.2M1
35    */
 
36    public abstract class AbstractReader
37    {
 
38  212545 toggle protected <T> T convert(Class<?> type, String source) throws FilterException
39    {
40  212545 Object value = source;
41   
42  212545 if (type == Locale.class) {
43  7615 value = toLocale(source);
44  204930 } else if (type == Date.class) {
45  8162 value = StringUtils.isNotEmpty(source) ? new Date(Long.parseLong(source)) : null;
46  196768 } else if (type == Boolean.class) {
47  15222 value = StringUtils.isNotEmpty(source) ? Boolean.parseBoolean(source) : null;
48  181546 } else if (type == Syntax.class) {
49  7672 if (StringUtils.isNotEmpty(source)) {
50  7672 try {
51  7672 value = Syntax.valueOf(source);
52    } catch (ParseException e) {
53  0 throw new FilterException(String.format("Failed to create Syntax istance for [%s]", source), e);
54    }
55    } else {
56  0 value = null;
57    }
58  173874 } else if (type == Integer.class) {
59  7396 value = StringUtils.isNotEmpty(source) ? Integer.parseInt(source) : null;
60    }
61   
62  212545 return (T) value;
63    }
64   
 
65  15290 toggle protected Locale toLocale(String value)
66    {
67  15290 Locale locale = null;
68  15290 if (value != null) {
69  15290 if (value.length() == 0) {
70  9530 locale = Locale.ROOT;
71    } else {
72  5760 locale = LocaleUtils.toLocale(value);
73    }
74    }
75   
76  15290 return locale;
77    }
78    }