OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 17 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.text;
14
 package org.openconcerto.openoffice.text;
15
 
15
 
-
 
16
import org.openconcerto.openoffice.ODDocument;
16
import org.openconcerto.openoffice.XMLVersion;
17
import org.openconcerto.openoffice.XMLVersion;
17
import org.openconcerto.openoffice.ODSingleXMLDocument;
-
 
18
 
18
 
19
import java.util.HashSet;
19
import java.util.HashSet;
20
import java.util.Set;
20
import java.util.Set;
21
 
21
 
22
import org.jdom.Attribute;
22
import org.jdom.Attribute;
Line 53... Line 53...
53
            }
53
            }
54
        }
54
        }
55
        return res;
55
        return res;
56
    }
56
    }
57
 
57
 
-
 
58
    Paragraph(Element elem, TextDocument parent) {
-
 
59
        super(elem, ParagraphStyle.class, parent);
-
 
60
    }
-
 
61
 
58
    public Paragraph(Element elem) {
62
    public Paragraph(Element elem) {
59
        super(elem, ParagraphStyle.class);
63
        this(elem, null);
60
    }
64
    }
61
 
65
 
62
    public Paragraph(XMLVersion ns) {
66
    public Paragraph(XMLVersion ns) {
63
        this(createEmpty(ns));
67
        this(createEmpty(ns));
64
    }
68
    }
Line 70... Line 74...
70
    public Paragraph(String text) {
74
    public Paragraph(String text) {
71
        this();
75
        this();
72
        addContent(text);
76
        addContent(text);
73
    }
77
    }
74
 
78
 
-
 
79
    // MAYBE add updateStyle() which evaluates the conditions in style:map of the conditional style
-
 
80
    // to update style-name
-
 
81
    /**
-
 
82
     * A style containing conditions and maps to other styles.
-
 
83
     * 
-
 
84
     * @return the conditional style or <code>null</code> if none or if this isn't in a document.
-
 
85
     */
-
 
86
    public final ParagraphStyle getConditionalStyle() {
-
 
87
        final String condName = this.getElement().getAttributeValue("cond-style-name", this.getElement().getNamespace());
-
 
88
        if (condName == null)
-
 
89
            return null;
-
 
90
        else
-
 
91
            return getStyle(condName);
-
 
92
    }
-
 
93
 
75
    public final void setStyle(String styleName) {
94
    public final void setStyle(String styleName) {
76
        getElement().setAttribute("style-name", styleName, getElement().getNamespace());
95
        getElement().setAttribute("style-name", styleName, getElement().getNamespace());
77
    }
96
    }
78
 
97
 
79
    public final void addContent(String text) {
98
    public final void addContent(String text) {
Line 97... Line 116...
97
 
116
 
98
    private final Set<String> getUsedTextStyles() {
117
    private final Set<String> getUsedTextStyles() {
99
        return getTextStyles(getElement());
118
        return getTextStyles(getElement());
100
    }
119
    }
101
 
120
 
-
 
121
    @Override
102
    protected void checkDocument(ODSingleXMLDocument doc) {
122
    protected void checkDocument(ODDocument doc) {
103
        if (this.getStyleName() != null && getStyle(doc.getPackage(), doc.getDocument()) == null)
123
        if (this.getStyleName() != null && getStyle(doc.getPackage(), doc.getContentDocument()) == null)
104
            throw new IllegalArgumentException("unknown style " + getStyleName() + " in " + doc);
124
            throw new IllegalArgumentException("unknown style " + getStyleName() + " in " + doc);
105
        for (final String styleName : this.getUsedTextStyles()) {
125
        for (final String styleName : this.getUsedTextStyles()) {
106
            if (doc.getStyle(TextStyle.DESC, styleName) == null) {
126
            if (doc.getPackage().getStyle(TextStyle.DESC, styleName) == null) {
107
                throw new IllegalArgumentException(this + " is using a text:span with an undefined style : " + styleName);
127
                throw new IllegalArgumentException(this + " is using a text:span with an undefined style : " + styleName);
108
            }
128
            }
109
        }
129
        }
110
    }
130
    }
111
 
131