use of org.apache.poi.openxml4j.opc.PackageRelationship in project poi by apache.
the class ExternalLinksTable method setLinkedFileName.
/**
* Updates the last recorded name for the file that this links to
*/
public void setLinkedFileName(String target) {
String rId = link.getExternalBook().getId();
if (rId == null || rId.isEmpty()) {
// We're a new External Link Table, so nothing to remove
} else {
// Relationships can't be changed, so remove the old one
getPackagePart().removeRelationship(rId);
}
// Have a new one added
PackageRelationship newRel = getPackagePart().addExternalRelationship(target, PackageRelationshipTypes.EXTERNAL_LINK_PATH);
link.getExternalBook().setId(newRel.getId());
}
use of org.apache.poi.openxml4j.opc.PackageRelationship in project poi by apache.
the class POIXMLRelation method getContents.
/**
* Fetches the InputStream to read the contents, based
* of the specified core part, for which we are defined
* as a suitable relationship
*
* @since 3.16-beta3
*/
public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
PackageRelationshipCollection prc = corePart.getRelationshipsByType(getRelation());
Iterator<PackageRelationship> it = prc.iterator();
if (it.hasNext()) {
PackageRelationship rel = it.next();
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
PackagePart part = corePart.getPackage().getPart(relName);
return part.getInputStream();
}
log.log(POILogger.WARN, "No part " + getDefaultFileName() + " found");
return null;
}
use of org.apache.poi.openxml4j.opc.PackageRelationship in project poi by apache.
the class POIXMLDocumentPart method getPartFromOPCPackage.
/**
* Retrieves the core document part
*
* @since POI 3.14-Beta1
*/
private static PackagePart getPartFromOPCPackage(OPCPackage pkg, String coreDocumentRel) {
PackageRelationship coreRel = pkg.getRelationshipsByType(coreDocumentRel).getRelationship(0);
if (coreRel != null) {
PackagePart pp = pkg.getPart(coreRel);
if (pp == null) {
throw new POIXMLException("OOXML file structure broken/invalid - core document '" + coreRel.getTargetURI() + "' not found.");
}
return pp;
}
coreRel = pkg.getRelationshipsByType(PackageRelationshipTypes.STRICT_CORE_DOCUMENT).getRelationship(0);
if (coreRel != null) {
throw new POIXMLException("Strict OOXML isn't currently supported, please see bug #57699");
}
throw new POIXMLException("OOXML file structure broken/invalid - no core document found!");
}
use of org.apache.poi.openxml4j.opc.PackageRelationship in project poi by apache.
the class XSSFShapeGroup method createPicture.
/**
* Creates a picture.
*
* @param anchor the client anchor describes how this picture is attached to the sheet.
* @param pictureIndex the index of the picture in the workbook collection of pictures,
* {@link XSSFWorkbook#getAllPictures()} .
* @return the newly created picture shape.
*/
public XSSFPicture createPicture(XSSFClientAnchor anchor, int pictureIndex) {
PackageRelationship rel = getDrawing().addPictureReference(pictureIndex);
CTPicture ctShape = ctGroup.addNewPic();
ctShape.set(XSSFPicture.prototype());
XSSFPicture shape = new XSSFPicture(getDrawing(), ctShape);
shape.parent = this;
shape.anchor = anchor;
shape.setPictureReference(rel);
return shape;
}
use of org.apache.poi.openxml4j.opc.PackageRelationship in project poi by apache.
the class XSSFSheet method initHyperlinks.
/**
* Read hyperlink relations, link them with CTHyperlink beans in this worksheet
* and initialize the internal array of XSSFHyperlink objects
*/
private void initHyperlinks() {
hyperlinks = new ArrayList<XSSFHyperlink>();
if (!worksheet.isSetHyperlinks()) {
return;
}
try {
PackageRelationshipCollection hyperRels = getPackagePart().getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
// Turn each one into a XSSFHyperlink
for (CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
PackageRelationship hyperRel = null;
if (hyperlink.getId() != null) {
hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
}
hyperlinks.add(new XSSFHyperlink(hyperlink, hyperRel));
}
} catch (InvalidFormatException e) {
throw new POIXMLException(e);
}
}
Aggregations