1. Project Clover database Sat Feb 2 2019 06:45:20 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  2176 toggle public AbstractExtensionPropertySerializer(String type)
42    {
43  2176 this.type = type;
44    }
45   
46    /**
47    * @return the type identifier
48    */
 
49  6472717 toggle public String getType()
50    {
51  6472717 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  4962708 toggle protected Element createRootElement(Document document, String elementName)
60    {
61  4962708 Element element = document.createElement(elementName);
62   
63  4962708 if (getType() != null) {
64  1508105 element.setAttribute("type", getType());
65    }
66   
67  4962708 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  4961499 toggle protected Element createRootElement(Document document, String elementName, String elementTextContent)
80    {
81  4961499 Element element = createRootElement(document, elementName);
82  4961499 element.setTextContent(elementTextContent);
83  4961499 return element;
84    }
85   
 
86  4960840 toggle @Override
87    public Element toElement(Document document, String elementName, T elementValue)
88    {
89  4960840 return createRootElement(document, elementName, elementValue.toString());
90    }
91    }