Package org.apache.poi.openxml4j.opc

Examples of org.apache.poi.openxml4j.opc.PackageRelationship


     * 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;
        }
    }
View Full Code Here


            // 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());
    }
View Full Code Here

            if(r instanceof XSSFDrawing) {
                dg = (XSSFDrawing)r;
                continue;
            }

            PackageRelationship rel = r.getPackageRelationship();
            clonedSheet.getPackagePart().addRelationship(
                    rel.getTargetURI(), rel.getTargetMode(),rel.getRelationshipType());
            clonedSheet.addRelation(rel.getId(), r);
        }

        // clone the sheet drawing alongs with its relationships
        if (dg != null) {
            if(ct.isSetDrawing()) {
                // unset the existing reference to the drawing,
                // so that subsequent call of clonedSheet.createDrawingPatriarch() will create a new one
                ct.unsetDrawing();
            }
            XSSFDrawing clonedDg = clonedSheet.createDrawingPatriarch();
            // copy drawing contents
            clonedDg.getCTDrawing().set(dg.getCTDrawing());

            // Clone drawing relations
            List<POIXMLDocumentPart> srcRels = srcSheet.createDrawingPatriarch().getRelations();
            for (POIXMLDocumentPart rel : srcRels) {
                PackageRelationship relation = rel.getPackageRelationship();
                clonedSheet
                        .createDrawingPatriarch()
                        .getPackagePart()
                        .addRelationship(relation.getTargetURI(), relation.getTargetMode(),
                                relation.getRelationshipType(), relation.getId());
            }
        }
        return clonedSheet;
    }
View Full Code Here

            PackagePart picDataPart = xwpfPicData.getPackagePart();
            // TODO add support for TargetMode.EXTERNAL relations.
            TargetMode targetMode = TargetMode.INTERNAL;
            PackagePartName partName = picDataPart.getPartName();
            String relation = relDesc.getRelation();
            PackageRelationship relShip = getPackagePart().addRelationship(partName,targetMode,relation);
            String id = relShip.getId();
            addRelation(id,xwpfPicData);
            pictures.add(xwpfPicData);
            return id;
        }
        else
View Full Code Here

     * @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);
View Full Code Here

     * Creates a new XSSFReader, for the given package
     */
    public XSSFReader(Package pkg) throws IOException, OpenXML4JException {
        this.pkg = pkg;

        PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
                PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);

        // Get the part that holds the workbook
        workbookPart = this.pkg.getPart(coreDocRelationship);
    }
View Full Code Here

     * 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();
View Full Code Here

   * @throws OpenXML4JException
   *             Throws if internal error occurs.
   */
  public static ZipEntry getCorePropertiesZipEntry(ZipPackage pkg)
      throws OpenXML4JException {
    PackageRelationship corePropsRel = pkg.getRelationshipsByType(
        PackageRelationshipTypes.CORE_PROPERTIES).getRelationship(0);

    if (corePropsRel == null)
      return null;

    return new ZipEntry(corePropsRel.getTargetURI().getPath());
  }
View Full Code Here

     * Generates the relation if required
     */
    protected void generateRelationIfNeeded(PackagePart sheetPart) {
        if (needsRelationToo()) {
            // Generate the relation
            PackageRelationship rel =
                    sheetPart.addExternalRelationship(location, XSSFRelation.SHEET_HYPERLINKS.getRelation());

            // Update the r:id
            ctHyperlink.setId(rel.getId());
        }
    }
View Full Code Here

  public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
        PackageRelationshipCollection prc =
          corePart.getRelationshipsByType(_relation);
        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();
        } else {
          log.log(POILogger.WARN, "No part " + _defaultName + " found");
          return null;
View Full Code Here

TOP

Related Classes of org.apache.poi.openxml4j.opc.PackageRelationship

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.