OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 80 Rev 174
Line 25... Line 25...
25
import org.openconcerto.openoffice.text.TextStyle.StyleTextProperties;
25
import org.openconcerto.openoffice.text.TextStyle.StyleTextProperties;
26
import org.openconcerto.utils.NumberUtils;
26
import org.openconcerto.utils.NumberUtils;
27
 
27
 
28
import java.math.RoundingMode;
28
import java.math.RoundingMode;
29
import java.text.DecimalFormat;
29
import java.text.DecimalFormat;
-
 
30
import java.text.DecimalFormatSymbols;
30
import java.util.Arrays;
31
import java.util.Arrays;
31
import java.util.Collections;
32
import java.util.Collections;
32
import java.util.HashSet;
33
import java.util.HashSet;
33
import java.util.List;
34
import java.util.List;
-
 
35
import java.util.Locale;
34
import java.util.Map.Entry;
36
import java.util.Map.Entry;
35
import java.util.Set;
37
import java.util.Set;
36
import java.util.SortedMap;
38
import java.util.SortedMap;
37
import java.util.TreeMap;
39
import java.util.TreeMap;
38
import java.util.regex.Matcher;
40
import java.util.regex.Matcher;
Line 43... Line 45...
43
import org.jdom.Namespace;
45
import org.jdom.Namespace;
44
 
46
 
45
// from section 16.27 in v1.2-cs01-part1
47
// from section 16.27 in v1.2-cs01-part1
46
public abstract class DataStyle extends Style {
48
public abstract class DataStyle extends Style {
47
    private static final int DEFAULT_GROUPING_SIZE = new DecimalFormat().getGroupingSize();
49
    private static final int DEFAULT_GROUPING_SIZE = new DecimalFormat().getGroupingSize();
-
 
50
    // 15 as of LibreOffice 6, was 10 earlier
-
 
51
    /**
-
 
52
     * The default number of decimal digits if neither defined in the style nor in default-style.
-
 
53
     */
48
    public static final int DEFAULT_DECIMAL_PLACES = 10;
54
    public static final int DEFAULT_DECIMAL_PLACES = Integer.parseInt(System.getProperty("openDocument.defaultDecimalPlaces", "15"));
49
    private static final Pattern QUOTE_PATRN = Pattern.compile("'", Pattern.LITERAL);
55
    private static final Pattern QUOTE_PATRN = Pattern.compile("'", Pattern.LITERAL);
50
    private static final Pattern EXP_PATTERN = Pattern.compile("E(\\d+)$");
56
    private static final Pattern EXP_PATTERN = Pattern.compile("E(\\d+)$");
51
 
57
 
52
    public static int getDecimalPlaces(final CellStyle defaultStyle) {
58
    public static int getDecimalPlaces(final CellStyle defaultStyle) {
53
        if (defaultStyle != null) {
59
        if (defaultStyle != null) {
Line 83... Line 89...
83
 
89
 
84
        protected DataStyleDesc(Class<S> clazz, XMLVersion version, String elemName, String baseName) {
90
        protected DataStyleDesc(Class<S> clazz, XMLVersion version, String elemName, String baseName) {
85
            super(clazz, version, elemName, baseName);
91
            super(clazz, version, elemName, baseName);
86
            this.setElementNS(getVersion().getNS("number"));
92
            this.setElementNS(getVersion().getNS("number"));
87
            // from 19.469 in v1.2-cs01-part1
93
            // from 19.469 in v1.2-cs01-part1
88
            this.getRefElementsMap().addAll(
94
            this.getRefElementsMap().addAll("style:data-style-name",
89
                    "style:data-style-name",
-
 
90
                    Arrays.asList("presentation:date-time-decl", "style:style", "text:creation-date", "text:creation-time", "text:database-display", "text:date", "text:editing-duration",
95
                    Arrays.asList("presentation:date-time-decl", "style:style", "text:creation-date", "text:creation-time", "text:database-display", "text:date", "text:editing-duration",
91
                            "text:expression", "text:meta-field", "text:modification-date", "text:modification-time", "text:print-date", "text:print-time", "text:table-formula", "text:time",
96
                            "text:expression", "text:meta-field", "text:modification-date", "text:modification-time", "text:print-date", "text:print-time", "text:table-formula", "text:time",
92
                            "text:user-defined", "text:user-field-get", "text:user-field-input", "text:variable-get", "text:variable-input", "text:variable-set"));
97
                            "text:user-defined", "text:user-field-get", "text:user-field-input", "text:variable-get", "text:variable-input", "text:variable-set"));
93
            this.getRefElementsMap().add("style:apply-style-name", "style:map");
98
            this.getRefElementsMap().add("style:apply-style-name", "style:map");
94
        }
99
        }
Line 174... Line 179...
174
            Log.get().warning(msg);
179
            Log.get().warning(msg);
175
        else
180
        else
176
            throw new UnsupportedOperationException(msg);
181
            throw new UnsupportedOperationException(msg);
177
    }
182
    }
178
 
183
 
-
 
184
    public final Locale getLocale() {
-
 
185
        return this.getLocale(this.getElement());
-
 
186
    }
-
 
187
 
-
 
188
    protected final Locale getLocale(final Element elem) {
-
 
189
        final Locale res = DateStyle.getElementLocale(elem);
-
 
190
        return res != null ? res : this.getPackage().getLocale();
-
 
191
    }
-
 
192
 
179
    protected final String formatNumberOrScientificNumber(final Element elem, final Number n, CellStyle defaultStyle) {
193
    protected final String formatNumberOrScientificNumber(final Element elem, final Number n, CellStyle defaultStyle) {
180
        return this.formatNumberOrScientificNumber(elem, n, 1, defaultStyle);
194
        return this.formatNumberOrScientificNumber(elem, n, 1, defaultStyle);
181
    }
195
    }
182
 
196
 
183
    protected final String formatNumberOrScientificNumber(final Element elem, final Number n, final int multiplier, CellStyle defaultStyle) {
197
    protected final String formatNumberOrScientificNumber(final Element elem, final Number n, final int multiplier, CellStyle defaultStyle) {
Line 241... Line 255...
241
            numberSB.append('E');
255
            numberSB.append('E');
242
            for (int i = 0; i < Integer.parseInt(minExpAttr.getValue()); i++)
256
            for (int i = 0; i < Integer.parseInt(minExpAttr.getValue()); i++)
243
                numberSB.append('0');
257
                numberSB.append('0');
244
        }
258
        }
245
 
259
 
-
 
260
        final DecimalFormatSymbols symbols = new DecimalFormatSymbols(this.getLocale());
-
 
261
 
246
        final DecimalFormat decFormat = new DecimalFormat(numberSB.toString());
262
        final DecimalFormat decFormat = new DecimalFormat(numberSB.toString(), symbols);
247
        // Java always use HALF_EVEN
263
        // Java always use HALF_EVEN
248
        decFormat.setRoundingMode(RoundingMode.HALF_UP);
264
        decFormat.setRoundingMode(RoundingMode.HALF_UP);
249
        decFormat.setGroupingUsed(grouping);
265
        decFormat.setGroupingUsed(grouping);
250
        // needed since the default size is overwritten by the pattern
266
        // needed since the default size is overwritten by the pattern
251
        decFormat.setGroupingSize(DEFAULT_GROUPING_SIZE);
267
        decFormat.setGroupingSize(DEFAULT_GROUPING_SIZE);