use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XWPFPictureData method equals.
@Override
public boolean equals(Object obj) {
/*
* In case two objects ARE equal, but its not the same instance, this
* implementation will always run through the whole
* byte-array-comparison before returning true. If this will turn into a
* performance issue, two possible approaches are available:<br>
* a) Use the checksum only and take the risk that two images might have
* the same CRC32 sum, although they are not the same.<br>
* b) Use a second (or third) checksum algorithm to minimise the chance
* that two images have the same checksums but are not equal (e.g.
* CRC32, MD5 and SHA-1 checksums, additionally compare the
* data-byte-array lengths).
*/
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof XWPFPictureData)) {
return false;
}
XWPFPictureData picData = (XWPFPictureData) obj;
PackagePart foreignPackagePart = picData.getPackagePart();
PackagePart ownPackagePart = this.getPackagePart();
if ((foreignPackagePart != null && ownPackagePart == null) || (foreignPackagePart == null && ownPackagePart != null)) {
return false;
}
if (ownPackagePart != null) {
OPCPackage foreignPackage = foreignPackagePart.getPackage();
OPCPackage ownPackage = ownPackagePart.getPackage();
if ((foreignPackage != null && ownPackage == null) || (foreignPackage == null && ownPackage != null)) {
return false;
}
if (ownPackage != null) {
if (!ownPackage.equals(foreignPackage)) {
return false;
}
}
}
Long foreignChecksum = picData.getChecksum();
Long localChecksum = getChecksum();
if (!(localChecksum.equals(foreignChecksum))) {
return false;
}
return Arrays.equals(this.getData(), picData.getData());
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XWPFDocument method commit.
/**
* commit and saves the document
*/
@Override
protected void commit() throws IOException {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
ctDocument.save(out, xmlOptions);
out.close();
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XWPFDocument method getAllEmbedds.
/**
* Get the document's embedded files.
*/
@Override
public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
List<PackagePart> embedds = new LinkedList<PackagePart>();
// Get the embeddings for the workbook
PackagePart part = getPackagePart();
for (PackageRelationship rel : getPackagePart().getRelationshipsByType(OLE_OBJECT_REL_TYPE)) {
embedds.add(part.getRelatedPart(rel));
}
for (PackageRelationship rel : getPackagePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE)) {
embedds.add(part.getRelatedPart(rel));
}
return embedds;
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XWPFHeader method commit.
/**
* save and commit footer
*/
@Override
protected void commit() throws IOException {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTNumbering.type.getName().getNamespaceURI(), "hdr"));
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
super._getHdrFtr().save(out, xmlOptions);
out.close();
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XWPFStyles method commit.
@Override
protected void commit() throws IOException {
if (ctStyles == null) {
throw new IllegalStateException("Unable to write out styles that were never read in!");
}
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTStyles.type.getName().getNamespaceURI(), "styles"));
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
ctStyles.save(out, xmlOptions);
out.close();
}
Aggregations