Package org.apache.poi.openxml4j.opc

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


     * Retrieves all the PackageParts which are defined as
     *  relationships of the base document with the
     *  specified content type.
     */
    protected PackagePart[] getRelatedByType(String contentType) throws InvalidFormatException {
        PackageRelationshipCollection partsC =
            getPackagePart().getRelationshipsByType(contentType);

        PackagePart[] parts = new PackagePart[partsC.size()];
        int count = 0;
        for (PackageRelationship rel : partsC) {
            parts[count] = getTargetPart(rel);
            count++;
        }
View Full Code Here


  /**
   * Gets the PackagePart of the notes for the
   *  given slide, or null if there isn't one.
   */
  public PackagePart getNodesPart(CTSlideIdListEntry parentSlide) throws IOException, XmlException {
    PackageRelationshipCollection notes;
    PackagePart slidePart = getSlidePart(parentSlide);
   
    try {
      notes = slidePart.getRelationshipsByType(XSLFRelation.NOTES.getRelation());
    } catch(InvalidFormatException e) {
      throw new IllegalStateException(e);
    }
   
    if(notes.size() == 0) {
      // No notes for this slide
      return null;
    }
    if(notes.size() > 1) {
      throw new IllegalStateException("Expecting 0 or 1 notes for a slide, but found " + notes.size());
    }
   
    try {
      return getTargetPart(notes.getRelationship(0));
    } catch(InvalidFormatException e) {
      throw new IllegalStateException(e);
    }
  }
View Full Code Here

  /**
   * 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 = getTargetPart(
          commentRels.getRelationship(0)
      );
      CmLstDocument commDoc =
        CmLstDocument.Factory.parse(cPart.getInputStream());
      return commDoc.getCmLst();
    } catch(InvalidFormatException e) {
View Full Code Here

                    || zip.getEntry("[Content_Types].xml") != null) {
                // Use POI to open and investigate it for us
                OPCPackage pkg = OPCPackage.open(stream.getFile().getPath(), PackageAccess.READ);
                stream.setOpenContainer(pkg);

                PackageRelationshipCollection core =
                    pkg.getRelationshipsByType(ExtractorFactory.CORE_DOCUMENT_REL);
                if (core.size() != 1) {
                    // Invalid OOXML Package received
                    return null;
                }

                // Get the type of the core document part
                PackagePart corePart = pkg.getPart(core.getRelationship(0));
                String coreType = corePart.getContentType();

                // Turn that into the type of the overall document
                String docType = coreType.substring(0, coreType.lastIndexOf('.'));
View Full Code Here

    /**
     * Detects the type of an OfficeOpenXML (OOXML) file from
     *  opened Package
     */
    public static MediaType detectOfficeOpenXML(OPCPackage pkg) {
        PackageRelationshipCollection core =
           pkg.getRelationshipsByType(ExtractorFactory.CORE_DOCUMENT_REL);
        if (core.size() != 1) {
            // Invalid OOXML Package received
            return null;
        }

        // Get the type of the core document part
        PackagePart corePart = pkg.getPart(core.getRelationship(0));
        String coreType = corePart.getContentType();

        // Turn that into the type of the overall document
        String docType = coreType.substring(0, coreType.lastIndexOf('.'));

View Full Code Here

                    || zip.getEntry("[Content_Types].xml") != null) {
                // Use POI to open and investigate it for us
                OPCPackage pkg = OPCPackage.open(stream.getFile().getPath());
                stream.setOpenContainer(pkg);

                PackageRelationshipCollection core =
                    pkg.getRelationshipsByType(ExtractorFactory.CORE_DOCUMENT_REL);
                if (core.size() != 1) {
                    // Invalid OOXML Package received
                    return null;
                }

                // Get the type of the core document part
                PackagePart corePart = pkg.getPart(core.getRelationship(0));
                String coreType = corePart.getContentType();

                // Turn that into the type of the overall document
                String docType = coreType.substring(0, coreType.lastIndexOf('.'));
View Full Code Here

        xhtml.endDocument();
       
        // Now do any embedded parts
        List<PackagePart> mainParts = getMainDocumentParts();
        for(PackagePart part : mainParts) {
           PackageRelationshipCollection rels;
           try {
              rels = part.getRelationships();
           } catch(InvalidFormatException e) {
              throw new TikaException("Corrupt OOXML file", e);
           }
View Full Code Here

    /**
     * Detects the type of an OfficeOpenXML (OOXML) file from
     *  opened Package
     */
    public static MediaType detectOfficeOpenXML(OPCPackage pkg) {
        PackageRelationshipCollection core =
           pkg.getRelationshipsByType(ExtractorFactory.CORE_DOCUMENT_REL);
        if (core.size() != 1) {
            // Invalid OOXML Package received
            return null;
        }

        // Get the type of the core document part
        PackagePart corePart = pkg.getPart(core.getRelationship(0));
        String coreType = corePart.getContentType();

        // Turn that into the type of the overall document
        String docType = coreType.substring(0, coreType.lastIndexOf('.'));

View Full Code Here

    }
    /**
     * Detects Open XML Paper Specification (XPS)
     */
    private static MediaType detectXPSOPC(OPCPackage pkg) {
        PackageRelationshipCollection xps =
                pkg.getRelationshipsByType("http://schemas.microsoft.com/xps/2005/06/fixedrepresentation");
        if (xps.size() == 1) {
            return MediaType.application("vnd.ms-xpsdocument");
        } else {
            // Non-XPS Package received
            return null;
        }
View Full Code Here

    }
    /**
     * Detects AutoCAD formats that live in OPC packaging
     */
    private static MediaType detectAutoCADOPC(OPCPackage pkg) {
        PackageRelationshipCollection dwfxSeq =
                pkg.getRelationshipsByType("http://schemas.autodesk.com/dwfx/2007/relationships/documentsequence");
        if (dwfxSeq.size() == 1) {
            return MediaType.parse("model/vnd.dwfx+xps");
        } else {
            // Non-AutoCAD Package received
            return null;
        }
View Full Code Here

TOP

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

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.