Search in sources :

Example 21 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class POIXMLDocument method write.

/**
     * Write out this document to an Outputstream.
     *
     * Note - if the Document was opened from a {@link File} rather
     *  than an {@link InputStream}, you <b>must</b> write out to
     *  a different file, overwriting via an OutputStream isn't possible.
     *  
     * If {@code stream} is a {@link java.io.FileOutputStream} on a networked drive
     * or has a high cost/latency associated with each written byte,
     * consider wrapping the OutputStream in a {@link java.io.BufferedOutputStream}
     * to improve write performance.
     * 
     * @param stream - the java OutputStream you wish to write the file to
     *
     * @exception IOException if anything can't be written.
     */
@SuppressWarnings("resource")
public final void write(OutputStream stream) throws IOException {
    OPCPackage p = getPackage();
    if (p == null) {
        throw new IOException("Cannot write data, document seems to have been closed already");
    }
    //force all children to commit their changes into the underlying OOXML Package
    // TODO Shouldn't they be committing to the new one instead?
    Set<PackagePart> context = new HashSet<PackagePart>();
    onSave(context);
    context.clear();
    //save extended and custom properties
    getProperties().commit();
    p.save(stream);
}
Also used : IOException(java.io.IOException) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) HashSet(java.util.HashSet)

Example 22 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class XSLFSlideShow method getSlide.

/**
	 * Returns the low level slide object from
	 *  the supplied slide reference
	 */
@Internal
public CTSlide getSlide(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackagePart slidePart = getSlidePart(slide);
    SldDocument slideDoc = SldDocument.Factory.parse(slidePart.getInputStream(), DEFAULT_XML_OPTIONS);
    return slideDoc.getSld();
}
Also used : SldDocument(org.openxmlformats.schemas.presentationml.x2006.main.SldDocument) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) Internal(org.apache.poi.util.Internal)

Example 23 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class XSLFSlideShow method getNotes.

/**
	 * Returns the low level notes object for the given
	 *  slide, as found from the supplied slide reference
	 */
@Internal
public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackagePart notesPart = getNodesPart(slide);
    if (notesPart == null)
        return null;
    NotesDocument notesDoc = NotesDocument.Factory.parse(notesPart.getInputStream(), DEFAULT_XML_OPTIONS);
    return notesDoc.getNotes();
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart) NotesDocument(org.openxmlformats.schemas.presentationml.x2006.main.NotesDocument) Internal(org.apache.poi.util.Internal)

Example 24 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class XSLFSlideShow method getSlideMaster.

/**
	 * Returns the low level slide master object from
	 *  the supplied slide master reference
	 */
@Internal
public CTSlideMaster getSlideMaster(CTSlideMasterIdListEntry master) throws IOException, XmlException {
    PackagePart masterPart = getSlideMasterPart(master);
    SldMasterDocument masterDoc = SldMasterDocument.Factory.parse(masterPart.getInputStream(), DEFAULT_XML_OPTIONS);
    return masterDoc.getSldMaster();
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart) SldMasterDocument(org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument) Internal(org.apache.poi.util.Internal)

Example 25 with PackagePart

use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.

the class XSLFSlideShow method getSlideComments.

/**
	 * Returns all the comments for the given slide
	 */
@Internal
public CTCommentList getSlideComments(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackageRelationshipCollection commentRels;
    PackagePart slidePart = getSlidePart(slide);
    try {
        commentRels = slidePart.getRelationshipsByType(XSLFRelation.COMMENTS.getRelation());
    } catch (InvalidFormatException e) {
        throw new IllegalStateException(e);
    }
    if (commentRels.size() == 0) {
        // No comments for this slide
        return null;
    }
    if (commentRels.size() > 1) {
        throw new IllegalStateException("Expecting 0 or 1 comments for a slide, but found " + commentRels.size());
    }
    try {
        PackagePart cPart = slidePart.getRelatedPart(commentRels.getRelationship(0));
        CmLstDocument commDoc = CmLstDocument.Factory.parse(cPart.getInputStream(), DEFAULT_XML_OPTIONS);
        return commDoc.getCmLst();
    } catch (InvalidFormatException e) {
        throw new IllegalStateException(e);
    }
}
Also used : CmLstDocument(org.openxmlformats.schemas.presentationml.x2006.main.CmLstDocument) PackageRelationshipCollection(org.apache.poi.openxml4j.opc.PackageRelationshipCollection) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) Internal(org.apache.poi.util.Internal)

Aggregations

PackagePart (org.apache.poi.openxml4j.opc.PackagePart)118 OutputStream (java.io.OutputStream)38 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)27 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)25 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)24 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)23 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)19 QName (javax.xml.namespace.QName)18 IOException (java.io.IOException)17 XmlOptions (org.apache.xmlbeans.XmlOptions)17 InputStream (java.io.InputStream)11 Test (org.junit.Test)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 POIXMLException (org.apache.poi.POIXMLException)8 XmlException (org.apache.xmlbeans.XmlException)8 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)7 ArrayList (java.util.ArrayList)6 TikaException (org.apache.tika.exception.TikaException)6 URI (java.net.URI)5 SAXException (org.xml.sax.SAXException)5