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);
}
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();
}
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();
}
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();
}
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);
}
}
Aggregations