OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 93 | Rev 182 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 93 Rev 180
Line 39... Line 39...
39
 
39
 
40
import javax.xml.XMLConstants;
40
import javax.xml.XMLConstants;
41
import javax.xml.validation.Schema;
41
import javax.xml.validation.Schema;
42
import javax.xml.validation.SchemaFactory;
42
import javax.xml.validation.SchemaFactory;
43
 
43
 
44
import net.jcip.annotations.GuardedBy;
-
 
45
import net.jcip.annotations.Immutable;
-
 
46
import net.jcip.annotations.ThreadSafe;
-
 
47
 
-
 
48
import org.jdom.Content;
44
import org.jdom.Content;
49
import org.jdom.DocType;
45
import org.jdom.DocType;
50
import org.jdom.Document;
46
import org.jdom.Document;
51
import org.jdom.Element;
47
import org.jdom.Element;
52
import org.jdom.JDOMException;
48
import org.jdom.JDOMException;
Line 54... Line 50...
54
import org.jdom.Parent;
50
import org.jdom.Parent;
55
import org.jdom.Text;
51
import org.jdom.Text;
56
import org.jdom.xpath.XPath;
52
import org.jdom.xpath.XPath;
57
import org.xml.sax.SAXException;
53
import org.xml.sax.SAXException;
58
 
54
 
-
 
55
import net.jcip.annotations.GuardedBy;
-
 
56
import net.jcip.annotations.Immutable;
-
 
57
import net.jcip.annotations.ThreadSafe;
-
 
58
 
59
/**
59
/**
60
 * Various bits of OpenDocument XML.
60
 * Various bits of OpenDocument XML.
61
 * 
61
 * 
62
 * @author Sylvain CUAZ
62
 * @author Sylvain CUAZ
63
 * @see #get(XMLFormatVersion)
63
 * @see #get(XMLFormatVersion)
Line 67... Line 67...
67
    /**
67
    /**
68
     * If this system property is set to <code>true</code> then {@link #get(XMLFormatVersion)} will
68
     * If this system property is set to <code>true</code> then {@link #get(XMLFormatVersion)} will
69
     * never return <code>null</code>, allowing to support unknown versions.
69
     * never return <code>null</code>, allowing to support unknown versions.
70
     */
70
     */
71
    public static final String LAST_FOR_UNKNOWN_PROP = OOXML.class.getPackage().getName() + ".lastOOXMLForUnknownVersion";
71
    public static final String LAST_FOR_UNKNOWN_PROP = OOXML.class.getPackage().getName() + ".lastOOXMLForUnknownVersion";
-
 
72
    private static final boolean LAST_FOR_UNKNOWN = Boolean.getBoolean(LAST_FOR_UNKNOWN_PROP);
72
    private static final XML_OO instanceOO = new XML_OO();
73
    private static final XML_OO instanceOO = new XML_OO();
73
    @GuardedBy("OOXML")
74
    @GuardedBy("OOXML")
74
    private static final SortedMap<String, XML_OD> instancesODByDate = new TreeMap<String, XML_OD>();
75
    private static final SortedMap<String, XML_OD> instancesODByDate = new TreeMap<String, XML_OD>();
75
    @GuardedBy("OOXML")
76
    @GuardedBy("OOXML")
76
    private static final Map<String, XML_OD> instancesODByVersion = new HashMap<String, XML_OD>();
77
    private static final Map<String, XML_OD> instancesODByVersion = new HashMap<String, XML_OD>();
Line 81... Line 82...
81
 
82
 
82
    static {
83
    static {
83
        register(new XML_OD_1_0());
84
        register(new XML_OD_1_0());
84
        register(new XML_OD_1_1());
85
        register(new XML_OD_1_1());
85
        register(new XML_OD_1_2());
86
        register(new XML_OD_1_2());
-
 
87
        register(new XML_OD_1_3());
86
 
88
 
87
        final List<OOXML> tmp = new ArrayList<OOXML>(instancesODByDate.size() + 1);
89
        final List<OOXML> tmp = new ArrayList<OOXML>(instancesODByDate.size() + 1);
88
        tmp.add(instanceOO);
90
        tmp.add(instanceOO);
89
        tmp.addAll(instancesODByDate.values());
91
        tmp.addAll(instancesODByDate.values());
90
        values = Collections.unmodifiableList(tmp);
92
        values = Collections.unmodifiableList(tmp);
Line 104... Line 106...
104
     * @param version the version.
106
     * @param version the version.
105
     * @return the corresponding instance, <code>null</code> for unsupported versions.
107
     * @return the corresponding instance, <code>null</code> for unsupported versions.
106
     * @see #LAST_FOR_UNKNOWN_PROP
108
     * @see #LAST_FOR_UNKNOWN_PROP
107
     */
109
     */
108
    public static OOXML get(XMLFormatVersion version) {
110
    public static OOXML get(XMLFormatVersion version) {
109
        return get(version, Boolean.getBoolean(LAST_FOR_UNKNOWN_PROP));
111
        return get(version, LAST_FOR_UNKNOWN);
110
    }
112
    }
111
 
113
 
112
    public static synchronized OOXML get(XMLFormatVersion version, final boolean lastForUnknown) {
114
    public static synchronized OOXML get(XMLFormatVersion version, final boolean lastForUnknown) {
113
        if (version.getXMLVersion() == XMLVersion.OOo) {
115
        if (version.getXMLVersion() == XMLVersion.OOo) {
114
            return instanceOO;
116
            return instanceOO;
Line 332... Line 334...
332
     * @param s a plain ole String, eg "term\tdefinition".
334
     * @param s a plain ole String, eg "term\tdefinition".
333
     * @return an Element suitable to be inserted in an OO XML document, eg
335
     * @return an Element suitable to be inserted in an OO XML document, eg
334
     * 
336
     * 
335
     *         <pre>
337
     *         <pre>
336
     *     &lt;text:span&gt;term&lt;text:tab-stop/&gt;definition&lt;/text:span&gt;
338
     *     &lt;text:span&gt;term&lt;text:tab-stop/&gt;definition&lt;/text:span&gt;
337
     * </pre>
339
     *         </pre>
338
     * 
340
     * 
339
     *         .
341
     *         .
340
     */
342
     */
341
    public final Element encodeWS(final String s) {
343
    public final Element encodeWS(final String s) {
342
        return Span.createEmpty(getFormatVersion()).setContent(encodeWSasList(s));
344
        return Span.createEmpty(getFormatVersion()).setContent(encodeWSasList(s));
Line 739... Line 741...
739
        public XML_OD_1_1() {
741
        public XML_OD_1_1() {
740
            super("20070201", "1.1", "OpenDocument-strict-schema-v1.1.rng", "OpenDocument-manifest-schema-v1.1.rng");
742
            super("20070201", "1.1", "OpenDocument-strict-schema-v1.1.rng", "OpenDocument-manifest-schema-v1.1.rng");
741
        }
743
        }
742
    }
744
    }
743
 
745
 
744
    private static final class XML_OD_1_2 extends XML_OD {
746
    private static final class XML_OD_1_2 extends XML_OD_1_2plus {
745
        public XML_OD_1_2() {
747
        public XML_OD_1_2() {
746
            super("20110317", "1.2", "OpenDocument-v1.2-schema.rng", "OpenDocument-v1.2-manifest-schema.rng");
748
            super("20110317", "1.2", "OpenDocument-v1.2-schema.rng", "OpenDocument-v1.2-manifest-schema.rng");
747
        }
749
        }
-
 
750
    }
-
 
751
 
-
 
752
    private static abstract class XML_OD_1_2plus extends XML_OD {
-
 
753
        protected XML_OD_1_2plus(final String dateString, final String versionString, final String schemaFile, final String manifestSchemaFile) {
-
 
754
            super(dateString, versionString, schemaFile, manifestSchemaFile);
-
 
755
        }
748
 
756
 
749
        @Override
757
        @Override
750
        public Document createManifestDoc() {
758
        public Document createManifestDoc() {
751
            final Document res = super.createManifestDoc();
759
            final Document res = super.createManifestDoc();
752
            res.getRootElement().setAttribute("version", getFormatVersion().getOfficeVersion(), res.getRootElement().getNamespace());
760
            res.getRootElement().setAttribute("version", getFormatVersion().getOfficeVersion(), res.getRootElement().getNamespace());
753
            return res;
761
            return res;
754
        }
762
        }
755
    }
763
    }
-
 
764
 
-
 
765
    // https://issues.oasis-open.org/issues/?jql=project%20%3D%20OFFICE%20AND%20resolution%20%3D%20Fixed%20AND%20fixVersion%20%3D%20%22ODF%201.3%22
-
 
766
    // - https://issues.oasis-open.org/browse/OFFICE-3860 : New attributes "min-decimal-places" and
-
 
767
    // "forced-exponent-sign" parsed in DataStyle.formatNumberOrScientificNumber()
-
 
768
    private static final class XML_OD_1_3 extends XML_OD_1_2plus {
-
 
769
        public XML_OD_1_3() {
-
 
770
            super("20191225", "1.3", "OpenDocument-schema-v1.3.rng", "OpenDocument-manifest-schema-v1.3.rng");
-
 
771
        }
-
 
772
    }
756
}
773
}