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

File FilterEventParametersConverter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart6.png
72% of files have more coverage

Code metrics

8
14
2
1
78
43
6
0.43
7
2
3

Classes

Class Line # Actions
FilterEventParametersConverter 42 14 0% 6 11
0.541666754.2%
 

Contributing tests

This file is covered by 95 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.internal.converter;
21   
22    import java.lang.reflect.Type;
23    import java.util.Map;
24   
25    import javax.inject.Singleton;
26   
27    import org.apache.commons.lang3.StringUtils;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.filter.FilterEventParameters;
30    import org.xwiki.properties.converter.AbstractConverter;
31    import org.xwiki.properties.converter.ConversionException;
32   
33    /**
34    * Converter that converts a value into an {@link FilterEventParameters} object.
35    *
36    * @version $Id: 51e25facab3aab806b1567af60bddca33631c789 $
37    * @since 5.2M2
38    */
39    // TODO: add real syntax support (only convert from empty String to empty Map right now)
40    @Component
41    @Singleton
 
42    public class FilterEventParametersConverter extends AbstractConverter<FilterEventParameters>
43    {
 
44  4461 toggle @Override
45    protected FilterEventParameters convertToType(Type type, Object value)
46    {
47  4461 if (value == null) {
48  0 return null;
49    }
50   
51  4461 FilterEventParameters parameters;
52   
53  4461 if (value instanceof FilterEventParameters) {
54  0 parameters = (FilterEventParameters) value;
55  4461 } else if (value instanceof Map) {
56  0 parameters = new FilterEventParameters();
57  0 parameters.putAll((Map) value);
58    } else {
59  4461 String parametersString = value.toString().trim();
60   
61  4461 if (StringUtils.isEmpty(parametersString)) {
62  4461 parameters = FilterEventParameters.EMPTY;
63    } else {
64  0 throw new ConversionException("Only able to convert empty string to ["
65    + FilterEventParameters.class.getName() + "]");
66    }
67    }
68   
69  4461 return parameters;
70    }
71   
 
72  0 toggle @Override
73    protected String convertToString(FilterEventParameters value)
74    {
75  0 throw new ConversionException("Conversion from [" + FilterEventParameters.class.getName() + "] to ["
76    + String.class.getName() + "] is not supported");
77    }
78    }