OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 73 Rev 83
Line 14... Line 14...
14
 package org.openconcerto.openoffice.text;
14
 package org.openconcerto.openoffice.text;
15
 
15
 
16
import org.openconcerto.openoffice.ContentType;
16
import org.openconcerto.openoffice.ContentType;
17
import org.openconcerto.openoffice.ContentTypeVersioned;
17
import org.openconcerto.openoffice.ContentTypeVersioned;
18
import org.openconcerto.openoffice.ODDocument;
18
import org.openconcerto.openoffice.ODDocument;
-
 
19
import org.openconcerto.openoffice.ODNodeDesc.Children;
19
import org.openconcerto.openoffice.ODPackage;
20
import org.openconcerto.openoffice.ODPackage;
20
import org.openconcerto.openoffice.XMLFormatVersion;
21
import org.openconcerto.openoffice.XMLFormatVersion;
21
 
22
 
22
import java.io.File;
23
import java.io.File;
23
import java.io.IOException;
24
import java.io.IOException;
24
import java.util.List;
-
 
25
 
25
 
26
import org.jdom.Element;
26
import org.jdom.Element;
27
 
27
 
28
public class TextDocument extends ODDocument {
28
public class TextDocument extends ODDocument {
29
 
29
 
Line 46... Line 46...
46
    }
46
    }
47
 
47
 
48
    public static TextDocument createEmpty(String s, XMLFormatVersion ns) throws IOException {
48
    public static TextDocument createEmpty(String s, XMLFormatVersion ns) throws IOException {
49
        final ContentTypeVersioned ct = ContentType.TEXT.getVersioned(ns.getXMLVersion());
49
        final ContentTypeVersioned ct = ContentType.TEXT.getVersioned(ns.getXMLVersion());
50
        final TextDocument res = ct.createPackage(ns).getTextDocument();
50
        final TextDocument res = ct.createPackage(ns).getTextDocument();
51
        final Element textP = Paragraph.createEmpty(ns.getXMLVersion());
51
        final Element textP = Paragraph.createEmpty(ns);
52
        textP.addContent(s);
52
        textP.addContent(s);
53
        res.getBody().addContent(textP);
53
        res.getBody().addContent(textP);
54
        return res;
54
        return res;
55
    }
55
    }
56
 
56
 
57
    private TextDocument(final ODPackage orig) {
57
    private TextDocument(final ODPackage orig) {
58
        super(orig);
58
        super(orig);
59
    }
59
    }
60
 
60
 
61
    public final Paragraph getParagraph(int i) {
61
    public final Paragraph getParagraph(int i) {
62
        return new Paragraph(this.getParagraphChildren().get(i), this);
62
        return getParagraphs().get(this, i);
63
    }
63
    }
64
 
64
 
65
    @SuppressWarnings("unchecked")
-
 
66
    private final List<Element> getParagraphChildren() {
-
 
67
        final Element proto = Paragraph.createEmpty(getVersion());
-
 
68
        return this.getBody().getChildren(proto.getName(), proto.getNamespace());
-
 
69
    }
-
 
70
 
-
 
71
    public final int getParagraphCount() {
65
    public final Children<Paragraph> getParagraphs() {
72
        return this.getParagraphChildren().size();
66
        return TextNodeDesc.get(Paragraph.class).getChildren(this, getBody());
73
    }
67
    }
74
 
68
 
75
    public final String getCharacterContent(final boolean ooMode) {
69
    public final String getCharacterContent(final boolean ooMode) {
76
        return TextNode.getChildrenCharacterContent(this.getBody(), this.getFormatVersion(), ooMode);
70
        return TextNode.getChildrenCharacterContent(this.getBody(), this.getFormatVersion(), ooMode);
77
    }
71
    }
Line 84... Line 78...
84
    public synchronized void add(TextNode<?> p) {
78
    public synchronized void add(TextNode<?> p) {
85
        this.add(p, null, -1);
79
        this.add(p, null, -1);
86
    }
80
    }
87
 
81
 
88
    public synchronized void add(TextNode<?> p, Element where, int index) {
82
    public synchronized void add(TextNode<?> p, Element where, int index) {
89
        // add it first to avoid infinite loop, since setDocument() can call this method
-
 
90
        final Element addToElem = where == null ? this.getBody() : where;
83
        final Element addToElem = where == null ? this.getBody() : where;
91
        if (index < 0)
-
 
92
            addToElem.addContent(p.getElement());
-
 
93
        else
-
 
94
            addToElem.addContent(index, p.getElement());
84
        p.addToDocument(this, addToElem, index);
95
 
-
 
96
        try {
-
 
97
            p.setDocument(this);
-
 
98
        } catch (RuntimeException e) {
-
 
99
            // the paragraph can throw an exception to notify that is not compatible with us (eg
-
 
100
            // missing styles), in that case remove it
-
 
101
            p.getElement().detach();
-
 
102
            throw e;
-
 
103
        }
-
 
104
    }
85
    }
105
}
86
}