OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 132
Line 16... Line 16...
16
import org.openconcerto.sql.Log;
16
import org.openconcerto.sql.Log;
17
import org.openconcerto.utils.i18n.Grammar;
17
import org.openconcerto.utils.i18n.Grammar;
18
import org.openconcerto.utils.i18n.NounClass;
18
import org.openconcerto.utils.i18n.NounClass;
19
import org.openconcerto.utils.i18n.Phrase;
19
import org.openconcerto.utils.i18n.Phrase;
20
import org.openconcerto.utils.i18n.VariantKey;
20
import org.openconcerto.utils.i18n.VariantKey;
21
import org.openconcerto.xml.JDOMUtils;
21
import org.openconcerto.xml.JDOM2Utils;
22
 
22
 
23
import java.io.IOException;
23
import java.io.IOException;
24
import java.io.InputStream;
24
import java.io.InputStream;
25
import java.util.AbstractMap.SimpleEntry;
25
import java.util.AbstractMap.SimpleEntry;
26
import java.util.List;
-
 
27
import java.util.Locale;
26
import java.util.Locale;
28
import java.util.Map.Entry;
27
import java.util.Map.Entry;
29
import java.util.regex.Pattern;
28
import java.util.regex.Pattern;
30
 
29
 
-
 
30
import org.jdom2.Document;
-
 
31
import org.jdom2.Element;
-
 
32
import org.jdom2.JDOMException;
31
import net.jcip.annotations.ThreadSafe;
33
import org.jdom2.input.SAXBuilder;
32
 
34
 
33
import org.jdom.Document;
-
 
34
import org.jdom.Element;
-
 
35
import org.jdom.JDOMException;
-
 
36
import org.jdom.input.SAXBuilder;
35
import net.jcip.annotations.ThreadSafe;
37
 
36
 
38
/**
37
/**
39
 * Parses XML to create phrases.
38
 * Parses XML to create phrases.
40
 * 
39
 * 
41
 * <pre>
40
 * <pre>
Line 60... Line 59...
60
    }
59
    }
61
 
60
 
62
    public final void load(final InputStream ins) throws JDOMException, IOException {
61
    public final void load(final InputStream ins) throws JDOMException, IOException {
63
        final Grammar gr = Grammar.getInstance(getLocale());
62
        final Grammar gr = Grammar.getInstance(getLocale());
64
        final Document doc = new SAXBuilder().build(ins);
63
        final Document doc = new SAXBuilder().build(ins);
65
        @SuppressWarnings("unchecked")
-
 
66
        final List<Element> elements = doc.getRootElement().getChildren("element");
64
        for (final Element elem : doc.getRootElement().getChildren("element"))
67
        for (final Element elem : elements)
-
 
68
            this.load(gr, elem);
65
            this.load(gr, elem);
69
    }
66
    }
70
 
67
 
71
    public final Entry<String, Phrase> createPhrase(final Element elem) throws IOException {
68
    public final Entry<String, Phrase> createPhrase(final Element elem) throws IOException {
72
        return this.createPhrase(Grammar.getInstance(getLocale()), elem);
69
        return this.createPhrase(Grammar.getInstance(getLocale()), elem);
Line 99... Line 96...
99
            // most languages have at most 2 grammatical number
96
            // most languages have at most 2 grammatical number
100
            final String plural = elem.getAttributeValue("namePlural");
97
            final String plural = elem.getAttributeValue("namePlural");
101
            if (plural != null)
98
            if (plural != null)
102
                res.putVariant(Grammar.PLURAL, plural);
99
                res.putVariant(Grammar.PLURAL, plural);
103
        } else {
100
        } else {
104
            @SuppressWarnings("unchecked")
-
 
105
            final List<Element> variantElems = nameElem.getChildren("variant");
101
            for (final Element variantElem : nameElem.getChildren("variant")) {
106
            for (final Element variantElem : variantElems) {
-
 
107
                final String value = variantElem.getAttributeValue("value");
102
                final String value = variantElem.getAttributeValue("value");
108
                if (value == null) {
103
                if (value == null) {
109
                    warning(refid, variantElem, "No value");
104
                    warning(refid, variantElem, "No value");
110
                    continue;
105
                    continue;
111
                }
106
                }
Line 144... Line 139...
144
        if (entry != null)
139
        if (entry != null)
145
            this.put(entry.getKey(), entry.getValue());
140
            this.put(entry.getKey(), entry.getValue());
146
    }
141
    }
147
 
142
 
148
    private void warning(final String refid, final Element variantElem, final String msg) {
143
    private void warning(final String refid, final Element variantElem, final String msg) {
149
        Log.get().warning(msg + " for variant of " + refid + " : " + JDOMUtils.output(variantElem));
144
        Log.get().warning(msg + " for variant of " + refid + " : " + JDOM2Utils.output(variantElem));
150
    }
145
    }
151
}
146
}