Search in sources :

Example 1 with PackageRelationship

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

the class XSLFGroupShape method createPicture.

@Override
public XSLFPictureShape createPicture(PictureData pictureData) {
    if (!(pictureData instanceof XSLFPictureData)) {
        throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
    }
    XSLFPictureData xPictureData = (XSLFPictureData) pictureData;
    PackagePart pic = xPictureData.getPackagePart();
    PackageRelationship rel = getSheet().getPackagePart().addRelationship(pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
    XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
    new DrawPictureShape(sh).resize();
    _shapes.add(sh);
    sh.setParent(this);
    return sh;
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) DrawPictureShape(org.apache.poi.sl.draw.DrawPictureShape)

Example 2 with PackageRelationship

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

the class XSLFHyperlink method linkToSlide.

@Override
public void linkToSlide(Slide<XSLFShape, XSLFTextParagraph> slide) {
    PackagePart thisPP = _sheet.getPackagePart();
    PackagePartName otherPPN = ((XSLFSheet) slide).getPackagePart().getPartName();
    if (_link.isSetId() && !_link.getId().isEmpty()) {
        thisPP.removeRelationship(_link.getId());
    }
    PackageRelationship rel = thisPP.addRelationship(otherPPN, TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation());
    _link.setId(rel.getId());
    _link.setAction("ppaction://hlinksldjump");
}
Also used : PackagePartName(org.apache.poi.openxml4j.opc.PackagePartName) PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 3 with PackageRelationship

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

the class XSLFPictureShape method getPictureLink.

/**
     * For an external linked picture, return the last-seen
     *  path to the picture.
     * For an internal picture, returns null.
     */
public URI getPictureLink() {
    if (getBlipId() != null) {
        // Internal picture, nothing to return
        return null;
    }
    String rId = getBlipLink();
    if (rId == null) {
        // No link recorded, nothing we can do
        return null;
    }
    PackagePart p = getSheet().getPackagePart();
    PackageRelationship rel = p.getRelationship(rId);
    if (rel != null) {
        return rel.getTargetURI();
    }
    return null;
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 4 with PackageRelationship

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

the class XSSFReader method getSheet.

/**
     * Returns an InputStream to read the contents of the
     *  specified Sheet.
     * @param relId The relationId of the sheet, from a r:id on the workbook
     */
public InputStream getSheet(String relId) throws IOException, InvalidFormatException {
    PackageRelationship rel = workbookPart.getRelationship(relId);
    if (rel == null) {
        throw new IllegalArgumentException("No Sheet found with r:id " + relId);
    }
    PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
    PackagePart sheet = pkg.getPart(relName);
    if (sheet == null) {
        throw new IllegalArgumentException("No data found for Sheet with r:id " + relId);
    }
    return sheet.getInputStream();
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) PackagePartName(org.apache.poi.openxml4j.opc.PackagePartName) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 5 with PackageRelationship

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

the class ExternalLinksTable method getLinkedFileName.

/**
     * Returns the last recorded name of the file that this
     *  is linked to
     */
public String getLinkedFileName() {
    String rId = link.getExternalBook().getId();
    PackageRelationship rel = getPackagePart().getRelationship(rId);
    if (rel != null && rel.getTargetMode() == TargetMode.EXTERNAL) {
        return rel.getTargetURI().toString();
    } else {
        return null;
    }
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship)

Aggregations

PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)49 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)27 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)21 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)14 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)13 IOException (java.io.IOException)10 POIXMLException (org.apache.poi.POIXMLException)8 TikaException (org.apache.tika.exception.TikaException)5 ArrayList (java.util.ArrayList)4 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)4 XmlException (org.apache.xmlbeans.XmlException)4 Test (org.junit.Test)4 URI (java.net.URI)3 HashMap (java.util.HashMap)3 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)3 SAXException (org.xml.sax.SAXException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 XMLSignatureException (javax.xml.crypto.dsig.XMLSignatureException)2