OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 73 Rev 83
Line 28... Line 28...
28
 
28
 
29
import java.awt.Point;
29
import java.awt.Point;
30
import java.io.File;
30
import java.io.File;
31
import java.io.IOException;
31
import java.io.IOException;
32
import java.io.InputStream;
32
import java.io.InputStream;
-
 
33
import java.io.OutputStream;
33
import java.math.BigDecimal;
34
import java.math.BigDecimal;
34
import java.net.URI;
35
import java.net.URI;
35
import java.net.URISyntaxException;
36
import java.net.URISyntaxException;
36
import java.util.ArrayList;
37
import java.util.ArrayList;
37
import java.util.Collection;
38
import java.util.Collection;
Line 365... Line 366...
365
    public static ODSingleXMLDocument createFromPackage(File f) throws JDOMException, IOException {
366
    public static ODSingleXMLDocument createFromPackage(File f) throws JDOMException, IOException {
366
        // this loads all linked files
367
        // this loads all linked files
367
        return new ODPackage(f).toSingle();
368
        return new ODPackage(f).toSingle();
368
    }
369
    }
369
 
370
 
-
 
371
    public static ODSingleXMLDocument createFromPackage(InputStream in) throws IOException {
-
 
372
        // this loads all linked files
-
 
373
        return new ODPackage(in).toSingle();
-
 
374
    }
-
 
375
 
370
    /**
376
    /**
371
     * Create a document from a flat XML.
377
     * Create a document from a flat XML.
372
     * 
378
     * 
373
     * @param f an OpenDocument XML file.
379
     * @param f an OpenDocument XML file.
374
     * @return the created file.
380
     * @return the created file.
Line 529... Line 535...
529
 
535
 
530
    public ODPackage getPackage() {
536
    public ODPackage getPackage() {
531
        return this.pkg;
537
        return this.pkg;
532
    }
538
    }
533
 
539
 
534
    private final Element getBasicScriptElem() {
540
    final Element getBasicScriptElem() {
535
        return this.getBasicScriptElem(false);
541
        return this.getBasicScriptElem(false);
536
    }
542
    }
537
 
543
 
538
    private final Element getBasicScriptElem(final boolean create) {
544
    private final Element getBasicScriptElem(final boolean create) {
539
        final OOXML xml = getXML();
545
        final OOXML xml = getXML();
Line 801... Line 807...
801
     * 
807
     * 
802
     * @param libraries which libraries to remove.
808
     * @param libraries which libraries to remove.
803
     * @return the actually removed libraries.
809
     * @return the actually removed libraries.
804
     */
810
     */
805
    public final Set<String> removeBasicLibraries(final Collection<String> libraries) {
811
    public final Set<String> removeBasicLibraries(final Collection<String> libraries) {
-
 
812
        final Element basicScriptElem = this.getBasicScriptElem(false);
806
        final Map<String, Element> thisLibrariesElements = this.readBasicLibraries(this.getBasicScriptElem(false)).get1();
813
        final Map<String, Element> thisLibrariesElements = this.readBasicLibraries(basicScriptElem).get1();
-
 
814
        // don't return if thisLibrariesElements is empty as we also check the package content
-
 
815
 
807
        final Set<String> res = new HashSet<String>();
816
        final Set<String> res = new HashSet<String>();
808
        for (final String libToRm : libraries) {
817
        for (final String libToRm : libraries) {
809
            final Element elemToRm = thisLibrariesElements.get(libToRm);
818
            final Element elemToRm = thisLibrariesElements.get(libToRm);
810
            if (elemToRm != null) {
819
            if (elemToRm != null) {
-
 
820
                // also detach empty <libraries>
811
                elemToRm.detach();
821
                JDOMUtils.detachEmptyParent(elemToRm);
812
                res.add(libToRm);
822
                res.add(libToRm);
813
            }
823
            }
814
            if (Library.removeFromPackage(this.getPackage(), libToRm))
824
            if (Library.removeFromPackage(this.getPackage(), libToRm))
815
                res.add(libToRm);
825
                res.add(libToRm);
816
        }
826
        }
-
 
827
        // Detach empty <script>, works because we already detached empty <libraries>
-
 
828
        if (basicScriptElem != null && basicScriptElem.getChildren().isEmpty())
-
 
829
            basicScriptElem.detach();
-
 
830
 
817
        return res;
831
        return res;
818
    }
832
    }
819
 
833
 
820
    /**
834
    /**
821
     * Fusionne les office:font-decls/style:font-decl. On ne préfixe jamais, on ajoute seulement si
835
     * Fusionne les office:font-decls/style:font-decl. On ne préfixe jamais, on ajoute seulement si
Line 1371... Line 1385...
1371
     */
1385
     */
1372
    public File saveToPackageAs(File f) throws IOException {
1386
    public File saveToPackageAs(File f) throws IOException {
1373
        return this.pkg.saveAs(f);
1387
        return this.pkg.saveAs(f);
1374
    }
1388
    }
1375
 
1389
 
-
 
1390
    public void saveToPackage(OutputStream f) throws IOException {
-
 
1391
        this.pkg.save(f);
-
 
1392
    }
-
 
1393
 
1376
    public File save() throws IOException {
1394
    public File save() throws IOException {
1377
        return this.saveAs(this.getPackage().getFile());
1395
        return this.saveAs(this.getPackage().getFile());
1378
    }
1396
    }
1379
 
1397
 
1380
    public File saveAs(File fNoExt) throws IOException {
1398
    public File saveAs(File fNoExt) throws IOException {