OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 20 Rev 25
Line 12... Line 12...
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.openoffice.style.data;
14
 package org.openconcerto.openoffice.style.data;
15
 
15
 
16
import org.openconcerto.openoffice.Log;
16
import org.openconcerto.openoffice.Log;
-
 
17
import org.openconcerto.openoffice.ODEpoch;
17
import org.openconcerto.openoffice.ODPackage;
18
import org.openconcerto.openoffice.ODPackage;
-
 
19
import org.openconcerto.openoffice.ODValueType;
18
import org.openconcerto.openoffice.Style;
20
import org.openconcerto.openoffice.Style;
19
import org.openconcerto.openoffice.StyleDesc;
21
import org.openconcerto.openoffice.StyleDesc;
20
import org.openconcerto.openoffice.StyleProperties;
22
import org.openconcerto.openoffice.StyleProperties;
21
import org.openconcerto.openoffice.XMLVersion;
23
import org.openconcerto.openoffice.XMLVersion;
22
import org.openconcerto.openoffice.spreadsheet.CellStyle;
24
import org.openconcerto.openoffice.spreadsheet.CellStyle;
Line 72... Line 74...
72
            this.getRefElementsMap().putAll(
74
            this.getRefElementsMap().putAll(
73
                    "style:data-style-name",
75
                    "style:data-style-name",
74
                    Arrays.asList("presentation:date-time-decl", "style:style", "text:creation-date", "text:creation-time", "text:database-display", "text:date", "text:editing-duration",
76
                    Arrays.asList("presentation:date-time-decl", "style:style", "text:creation-date", "text:creation-time", "text:database-display", "text:date", "text:editing-duration",
75
                            "text:expression", "text:meta-field", "text:modification-date", "text:modification-time", "text:print-date", "text:print-time", "text:table-formula", "text:time",
77
                            "text:expression", "text:meta-field", "text:modification-date", "text:modification-time", "text:print-date", "text:print-time", "text:table-formula", "text:time",
76
                            "text:user-defined", "text:user-field-get", "text:user-field-input", "text:variable-get", "text:variable-input", "text:variable-set"));
78
                            "text:user-defined", "text:user-field-get", "text:user-field-input", "text:variable-get", "text:variable-input", "text:variable-set"));
-
 
79
            this.getRefElementsMap().put("style:apply-style-name", "style:map");
77
        }
80
        }
78
    }
81
    }
79
 
82
 
80
    // type accepted by #format()
-
 
81
    private final Class<?> type;
83
    private final ODValueType type;
82
    private StyleTextProperties textProps;
84
    private StyleTextProperties textProps;
83
 
85
 
84
    protected DataStyle(final ODPackage pkg, Element elem, final Class<?> type) {
86
    protected DataStyle(final ODPackage pkg, Element elem, final ODValueType type) {
85
        super(pkg, elem);
87
        super(pkg, elem);
86
        this.type = type;
88
        this.type = type;
87
    }
89
    }
88
 
90
 
89
    protected final Class<?> getDataType() {
91
    public final ODValueType getDataType() {
90
        return this.type;
92
        return this.type;
91
    }
93
    }
92
 
94
 
-
 
95
    public final ODEpoch getEpoch() {
-
 
96
        return this.getPackage().getODDocument().getEpoch();
-
 
97
    }
-
 
98
 
-
 
99
    /**
-
 
100
     * Convert the passed object to something that {@link #format(Object, CellStyle, boolean)} can
-
 
101
     * accept.
-
 
102
     * 
-
 
103
     * @param o the object to convert.
-
 
104
     * @return an object that can be formatted, <code>null</code> if <code>o</code> cannot be
-
 
105
     *         converted.
-
 
106
     * @throws NullPointerException if <code>o</code> is <code>null</code>.
-
 
107
     * @see #canFormat(Class)
-
 
108
     */
-
 
109
    public final Object convert(final Object o) throws NullPointerException {
-
 
110
        if (o == null)
-
 
111
            throw new NullPointerException();
-
 
112
 
-
 
113
        final Object res;
-
 
114
        if (this.canFormat(o.getClass()))
-
 
115
            res = o;
-
 
116
        else
-
 
117
            res = this.convertNonNull(o);
-
 
118
        assert res == null || this.canFormat(res.getClass());
-
 
119
        return res;
-
 
120
    }
-
 
121
 
-
 
122
    // o is not null and canFormat(o.getClass()) is false
-
 
123
    // return null if o cannot be converted
-
 
124
    protected abstract Object convertNonNull(Object o);
-
 
125
 
-
 
126
    /**
-
 
127
     * Whether instances of the passed class can be {@link #format(Object, CellStyle, boolean)
-
 
128
     * formatted}.
-
 
129
     * 
-
 
130
     * @param toFormat the class.
-
 
131
     * @return <code>true</code> if instances of <code>toFormat</code> can be formatted.
-
 
132
     */
93
    public final boolean canFormat(Class<?> toFormat) {
133
    public final boolean canFormat(Class<?> toFormat) {
94
        return this.getDataType().isAssignableFrom(toFormat);
134
        return this.getDataType().canFormat(toFormat);
95
    }
135
    }
96
 
136
 
97
    public final String getTitle() {
137
    public final String getTitle() {
98
        return this.getElement().getAttributeValue("title", getElement().getNamespace());
138
        return this.getElement().getAttributeValue("title", getElement().getNamespace());
99
    }
139
    }