OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
174 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.xml;
15
 
16
import java.beans.XMLDecoder;
17
import java.beans.XMLEncoder;
18
import java.util.Iterator;
19
 
20
import org.jdom2.Element;
21
 
22
/**
23
 * To encode and decode using {@link XMLEncoder} and {@link XMLDecoder}.
24
 *
25
 * @author Sylvain CUAZ
26
 */
27
public final class XMLDecoderJDOM extends AbstractXMLDecoder<Element, RuntimeException> {
28
 
29
    @Override
30
    protected String getAttributeValue(Element elem, String attrName) {
31
        return elem.getAttributeValue(attrName);
32
    }
33
 
34
    @Override
35
    protected String getLocalName(Element elem) {
36
        return elem.getName();
37
    }
38
 
39
    @Override
40
    protected String getElementText(Element elem) {
41
        return elem.getText();
42
    }
43
 
44
    @Override
45
    protected Element getFirstChild(Element elem) {
46
        return elem.getChildren().get(0);
47
    }
48
 
49
    @Override
50
    protected String toString(Element elem) {
51
        return JDOM2Utils.output(elem);
52
    }
53
 
54
    @Override
55
    protected Children<Element> createChildren(final Element elem) {
56
        return new Children<Element>() {
57
 
58
            private final Iterator<Element> iter = elem.getChildren().iterator();
59
 
60
            @Override
61
            public Element getNextChild() {
62
                if (!this.iter.hasNext())
63
                    return null;
64
 
65
                final Element res = this.iter.next();
66
                assert res != null;
67
                return res;
68
            }
69
        };
70
    }
71
 
72
    protected XMLDecoderJDOM() {
73
    }
74
}