OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19 Rev 25
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.openoffice;
14
 package org.openconcerto.openoffice;
15
 
15
 
-
 
16
import java.io.File;
-
 
17
import java.io.FileNotFoundException;
-
 
18
import java.io.IOException;
-
 
19
import java.text.ParseException;
-
 
20
 
-
 
21
import org.jdom.Document;
-
 
22
import org.jdom.Element;
-
 
23
import org.jdom.Namespace;
-
 
24
 
16
/**
25
/**
17
 * An ODF document, like a spreadsheet or a text file.
26
 * An ODF document, like a spreadsheet or a text file.
18
 * 
27
 * 
19
 * @author Sylvain
28
 * @author Sylvain
20
 */
29
 */
21
public interface ODDocument {
30
public abstract class ODDocument {
22
    public XMLVersion getVersion();
-
 
23
 
31
 
-
 
32
    private final ODPackage pkg;
-
 
33
    private ODEpoch epoch;
-
 
34
 
-
 
35
    protected ODDocument(final ODPackage orig) {
24
    public XMLFormatVersion getFormatVersion();
36
        // don't want multiple document per package.
-
 
37
        if (orig.hasODDocument())
-
 
38
            throw new IllegalStateException("ODPackage already has an ODDocument");
-
 
39
        this.pkg = orig;
-
 
40
    }
25
 
41
 
-
 
42
    public final XMLVersion getVersion() {
-
 
43
        return this.getFormatVersion().getXMLVersion();
-
 
44
    }
-
 
45
 
-
 
46
    public final XMLFormatVersion getFormatVersion() {
-
 
47
        return this.getPackage().getFormatVersion();
-
 
48
    }
-
 
49
 
26
    public ODPackage getPackage();
50
    public final ODPackage getPackage() {
-
 
51
        return this.pkg;
-
 
52
    }
-
 
53
 
-
 
54
    public final Document getContentDocument() {
-
 
55
        return this.getPackage().getContent().getDocument();
-
 
56
    }
-
 
57
 
-
 
58
    protected final Element getBody() {
-
 
59
        return getPackage().getContentType().getBody(this.getContentDocument());
-
 
60
    }
-
 
61
 
-
 
62
    private final String findEpoch() throws ParseException {
-
 
63
        final Namespace tableNS = getVersion().getTABLE();
-
 
64
        final Element settings = this.getBody().getChild("calculation-settings", tableNS);
-
 
65
        if (settings != null) {
-
 
66
            final Element nullDateElem = settings.getChild("null-date", tableNS);
-
 
67
            if (nullDateElem != null)
-
 
68
                return nullDateElem.getAttributeValue("date-value", tableNS);
-
 
69
        }
-
 
70
        return null;
-
 
71
    }
-
 
72
 
-
 
73
    public final ODEpoch getEpoch() {
-
 
74
        return this.getEpoch(false);
-
 
75
    }
-
 
76
 
-
 
77
    public final ODEpoch getEpoch(final boolean updateFromXML) {
-
 
78
        if (this.epoch == null || updateFromXML) {
-
 
79
            try {
-
 
80
                this.epoch = ODEpoch.getInstance(this.findEpoch());
-
 
81
            } catch (ParseException e) {
-
 
82
                // quite rare
-
 
83
                throw new IllegalStateException("Unable to parse the epoch of " + this, e);
-
 
84
            }
-
 
85
        }
-
 
86
        assert this.epoch != null;
-
 
87
        return this.epoch;
-
 
88
    }
-
 
89
 
-
 
90
    // *** Files
-
 
91
 
-
 
92
    public File saveAs(File file) throws FileNotFoundException, IOException {
-
 
93
        this.getPackage().setFile(file);
-
 
94
        return this.getPackage().save();
-
 
95
    }
27
}
96
}