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

File AbstractExtensionPropertySerializer.java

 

Coverage histogram

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

Code metrics

2
10
5
1
91
34
6
0.6
2
5
1.2

Classes

Class Line # Actions
AbstractExtensionPropertySerializer 31 10 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 93 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.extension.repository.internal;
21   
22    import org.w3c.dom.Document;
23    import org.w3c.dom.Element;
24   
25    /**
26    * Base class to help implement {@link ExtensionPropertySerializer}.
27    *
28    * @param <T> the type of the property value
29    * @version $Id: 0b261cede29accf2c42a981d833a8629c1f1fb33 $
30    */
 
31    public abstract class AbstractExtensionPropertySerializer<T> implements ExtensionPropertySerializer<T>
32    {
33    /**
34    * The simple type identifier. Used to recognize the type when unserializing.
35    */
36    private String type;
37   
38    /**
39    * @param type the type identifier
40    */
 
41  2216 toggle public AbstractExtensionPropertySerializer(String type)
42    {
43  2216 this.type = type;
44    }
45   
46    /**
47    * @return the type identifier
48    */
 
49  3104714 toggle public String getType()
50    {
51  3104714 return this.type;
52    }
53   
54    /**
55    * @param document the document used to create new {@link Element}
56    * @param elementName the name of the element to create
57    * @return the new element
58    */
 
59  2409279 toggle protected Element createRootElement(Document document, String elementName)
60    {
61  2409279 Element element = document.createElement(elementName);
62   
63  2409279 if (getType() != null) {
64  693496 element.setAttribute("type", getType());
65    }
66   
67  2409279 return element;
68    }
69   
70    /**
71    * Creates a new {@link Element} with the given name and text content.
72    *
73    * @param document the document used to create the new {@link Element}.
74    * @param elementName the name of the element to create
75    * @param elementTextContent the text content of the element
76    * @return the new element
77    * @since 7.0M2
78    */
 
79  2408881 toggle protected Element createRootElement(Document document, String elementName, String elementTextContent)
80    {
81  2408881 Element element = createRootElement(document, elementName);
82  2408881 element.setTextContent(elementTextContent);
83  2408881 return element;
84    }
85   
 
86  2408636 toggle @Override
87    public Element toElement(Document document, String elementName, T elementValue)
88    {
89  2408636 return createRootElement(document, elementName, elementValue.toString());
90    }
91    }