OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 144 Rev 174
Line 15... Line 15...
15
 
15
 
16
import static org.openconcerto.openoffice.ODPackage.RootElement.CONTENT;
16
import static org.openconcerto.openoffice.ODPackage.RootElement.CONTENT;
17
import static org.openconcerto.openoffice.ODPackage.RootElement.META;
17
import static org.openconcerto.openoffice.ODPackage.RootElement.META;
18
import static org.openconcerto.openoffice.ODPackage.RootElement.STYLES;
18
import static org.openconcerto.openoffice.ODPackage.RootElement.STYLES;
19
 
19
 
-
 
20
import org.openconcerto.openoffice.spreadsheet.CellStyle;
20
import org.openconcerto.openoffice.spreadsheet.SpreadSheet;
21
import org.openconcerto.openoffice.spreadsheet.SpreadSheet;
-
 
22
import org.openconcerto.openoffice.style.data.DataStyle;
21
import org.openconcerto.openoffice.text.TextDocument;
23
import org.openconcerto.openoffice.text.TextDocument;
22
import org.openconcerto.utils.CopyUtils;
24
import org.openconcerto.utils.CopyUtils;
23
import org.openconcerto.utils.ExceptionUtils;
25
import org.openconcerto.utils.ExceptionUtils;
24
import org.openconcerto.utils.FileUtils;
26
import org.openconcerto.utils.FileUtils;
25
import org.openconcerto.utils.ProductInfo;
27
import org.openconcerto.utils.ProductInfo;
Line 46... Line 48...
46
import java.io.FileOutputStream;
48
import java.io.FileOutputStream;
47
import java.io.IOException;
49
import java.io.IOException;
48
import java.io.InputStream;
50
import java.io.InputStream;
49
import java.io.OutputStream;
51
import java.io.OutputStream;
50
import java.nio.charset.Charset;
52
import java.nio.charset.Charset;
-
 
53
import java.text.NumberFormat;
51
import java.util.ArrayList;
54
import java.util.ArrayList;
52
import java.util.Arrays;
55
import java.util.Arrays;
53
import java.util.Collection;
56
import java.util.Collection;
54
import java.util.Collections;
57
import java.util.Collections;
55
import java.util.EnumSet;
58
import java.util.EnumSet;
56
import java.util.HashMap;
59
import java.util.HashMap;
57
import java.util.HashSet;
60
import java.util.HashSet;
58
import java.util.Iterator;
61
import java.util.Iterator;
59
import java.util.List;
62
import java.util.List;
-
 
63
import java.util.Locale;
60
import java.util.Map;
64
import java.util.Map;
61
import java.util.Map.Entry;
65
import java.util.Map.Entry;
62
import java.util.Properties;
66
import java.util.Properties;
63
import java.util.Set;
67
import java.util.Set;
64
import java.util.zip.ZipEntry;
68
import java.util.zip.ZipEntry;
Line 67... Line 71...
67
import org.jdom.DocType;
71
import org.jdom.DocType;
68
import org.jdom.Document;
72
import org.jdom.Document;
69
import org.jdom.Element;
73
import org.jdom.Element;
70
import org.jdom.JDOMException;
74
import org.jdom.JDOMException;
71
import org.jdom.Namespace;
75
import org.jdom.Namespace;
-
 
76
import org.jdom.input.SAXBuilder;
72
import org.jdom.output.Format;
77
import org.jdom.output.Format;
73
import org.jdom.output.XMLOutputter;
78
import org.jdom.output.XMLOutputter;
74
 
79
 
75
import net.jcip.annotations.GuardedBy;
80
import net.jcip.annotations.GuardedBy;
76
 
81
 
Line 375... Line 380...
375
    private ContentTypeVersioned type;
380
    private ContentTypeVersioned type;
376
    private XMLFormatVersion version;
381
    private XMLFormatVersion version;
377
    private ODMeta meta;
382
    private ODMeta meta;
378
    private File file;
383
    private File file;
379
    private ODDocument doc;
384
    private ODDocument doc;
-
 
385
    private Locale locale;
380
 
386
 
381
    public ODPackage() {
387
    public ODPackage() {
382
        this.files = new HashMap<String, ODPackageEntry>();
388
        this.files = new HashMap<String, ODPackageEntry>();
383
        this.type = null;
389
        this.type = null;
384
        this.version = null;
390
        this.version = null;
Line 400... Line 406...
400
        new ZippedFilesProcessor() {
406
        new ZippedFilesProcessor() {
401
            @Override
407
            @Override
402
            protected void processEntry(ZipEntry entry, InputStream in) throws IOException {
408
            protected void processEntry(ZipEntry entry, InputStream in) throws IOException {
403
                final String name = entry.getName();
409
                final String name = entry.getName();
404
                final Object res;
410
                final Object res;
-
 
411
                out.reset();
-
 
412
                StreamUtils.copy(in, out);
405
                if (subdocNames.contains(name)) {
413
                if (subdocNames.contains(name)) {
406
                    try {
414
                    try {
407
                        res = OOUtils.getBuilder().build(in);
415
                        final SAXBuilder builder = OOUtils.getBuilder();
-
 
416
                        // bytes are read fully first in order to be compatible
-
 
417
                        // with SAXParser like Piccolo
-
 
418
                        res = builder.build(new ByteArrayInputStream(out.toByteArray()));
408
                    } catch (JDOMException e) {
419
                    } catch (JDOMException e) {
409
                        // always correct
420
                        // always correct
410
                        throw new IllegalStateException("parse error", e);
421
                        throw new IllegalStateException("parse error on " + name, e);
411
                    }
422
                    }
412
                } else {
423
                } else {
413
                    out.reset();
-
 
414
                    StreamUtils.copy(in, out);
-
 
415
                    res = out.toByteArray();
424
                    res = out.toByteArray();
416
                }
425
                }
417
                // we don't know yet the types
426
                // we don't know yet the types
418
                putFile(name, res, null, entry.getMethod() == ZipEntry.DEFLATED);
427
                putFile(name, res, null, entry.getMethod() == ZipEntry.DEFLATED);
419
            }
428
            }
Line 577... Line 586...
577
        if (newType == null)
586
        if (newType == null)
578
            throw new IllegalStateException("Missing " + (b ? "" : "non-") + "template for " + this.type);
587
            throw new IllegalStateException("Missing " + (b ? "" : "non-") + "template for " + this.type);
579
        this.setContentType(newType);
588
        this.setContentType(newType);
580
    }
589
    }
581
 
590
 
-
 
591
    public final void setLocale(Locale locale) {
-
 
592
        this.locale = locale;
-
 
593
    }
-
 
594
 
-
 
595
    // http://help.libreoffice.org/Common/Selecting_the_Document_Language
-
 
596
    // The document language is set by default-style/text-properties and is not used for formatting.
-
 
597
    // The formatting used to fill cell content is set by the editor application not read from the
-
 
598
    // document.
-
 
599
    public final Locale getLocale() {
-
 
600
        return this.locale == null ? Locale.getDefault() : this.locale;
-
 
601
    }
-
 
602
 
-
 
603
    public final String formatNumber(Number n, final CellStyle defaultStyle) {
-
 
604
        return formatNumber(NumberFormat.getNumberInstance(getLocale()), n, defaultStyle);
-
 
605
    }
-
 
606
 
-
 
607
    public final String formatPercent(Number n, final CellStyle defaultStyle) {
-
 
608
        return formatNumber(NumberFormat.getPercentInstance(getLocale()), n, defaultStyle);
-
 
609
    }
-
 
610
 
-
 
611
    public final String formatCurrency(Number n, final CellStyle defaultStyle) {
-
 
612
        return formatNumber(NumberFormat.getCurrencyInstance(getLocale()), n, defaultStyle);
-
 
613
    }
-
 
614
 
-
 
615
    private final String formatNumber(NumberFormat format, Number n, final CellStyle defaultStyle) {
-
 
616
        synchronized (format) {
-
 
617
            final int decPlaces = DataStyle.getDecimalPlaces(defaultStyle);
-
 
618
            format.setMinimumFractionDigits(0);
-
 
619
            format.setMaximumFractionDigits(decPlaces);
-
 
620
            return format.format(n);
-
 
621
        }
-
 
622
    }
-
 
623
 
582
    /**
624
    /**
583
     * Call {@link Validator#isValid()} on each XML subdocuments.
625
     * Call {@link Validator#isValid()} on each XML subdocuments.
584
     * 
626
     * 
585
     * @return all problems indexed by package entry names, i.e. empty if all OK, <code>null</code>
627
     * @return all problems indexed by package entry names, i.e. empty if all OK, <code>null</code>
586
     *         if validation couldn't occur.
628
     *         if validation couldn't occur.