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

File MetaDataConverter.java

 

Coverage histogram

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

Code metrics

8
13
2
1
73
38
6
0.46
6.5
2
3

Classes

Class Line # Actions
MetaDataConverter 37 13 0% 6 10
0.565217456.5%
 

Contributing tests

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