Examples of PackageRelationshipCollection


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

  /**
   * 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

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

  /**
   * 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

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

   *  Fetches the InputStream to read the contents, based
   *  of the specified core part, for which we are defined
   *  as a suitable relationship
   */
  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();
View Full Code Here

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

        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){
View Full Code Here

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

        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){
View Full Code Here

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

 
  public POIXMLProperties(OPCPackage docPackage) throws IOException, OpenXML4JException, XmlException {
    this.pkg = docPackage;
   
    // Core properties
    PackageRelationshipCollection coreRel =
      pkg.getRelationshipsByType(POIXMLDocument.CORE_PROPERTIES_REL_TYPE);
    if(coreRel.size() == 1) {
      core = new CoreProperties( (PackagePropertiesPart)
          pkg.getPart(coreRel.getRelationship(0)) );
    } else {
      throw new IllegalArgumentException("A document must always have core properties defined!");
    }
   
    // Extended properties
    PackageRelationshipCollection extRel =
      pkg.getRelationshipsByType(POIXMLDocument.EXTENDED_PROPERTIES_REL_TYPE);
    if(extRel.size() == 1) {
      org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.parse(
          pkg.getPart( extRel.getRelationship(0) ).getInputStream()
      );
      ext = new ExtendedProperties(props);
    } else {
      ext = new ExtendedProperties(org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.newInstance());
    }
   
    // Custom properties
    PackageRelationshipCollection custRel =
      pkg.getRelationshipsByType(POIXMLDocument.CUSTOM_PROPERTIES_REL_TYPE);
    if(custRel.size() == 1) {
      org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.parse(
          pkg.getPart( custRel.getRelationship(0) ).getInputStream()
      );
      cust = new CustomProperties(props);
    } else {
      cust = new CustomProperties(org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.newInstance());
    }
View Full Code Here

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

    }
    throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
  }
 
  public static POIXMLTextExtractor createExtractor(OPCPackage pkg) throws IOException, OpenXML4JException, XmlException {
    PackageRelationshipCollection core =
      pkg.getRelationshipsByType(CORE_DOCUMENT_REL);
    if(core.size() != 1) {
      throw new IllegalArgumentException("Invalid OOXML Package received - expected 1 core document, found " + core.size());
    }
   
    PackagePart corePart = pkg.getPart(core.getRelationship(0));
    if(corePart.getContentType().equals(XSSFRelation.WORKBOOK.getContentType())) {
      return new XSSFExcelExtractor(pkg);
    }
    if(corePart.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
      return new XWPFWordExtractor(pkg);
View Full Code Here

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

        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){
View Full Code Here

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

    /**
     * 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

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

    // Core properties
    core = new CoreProperties((PackagePropertiesPart)pkg.getPackageProperties() );

    // Extended properties
    PackageRelationshipCollection extRel =
      pkg.getRelationshipsByType(POIXMLDocument.EXTENDED_PROPERTIES_REL_TYPE);
    if(extRel.size() == 1) {
      extPart = pkg.getPart( extRel.getRelationship(0));
      org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.Factory.parse(
         extPart.getInputStream()
      );
      ext = new ExtendedProperties(props);
    } else {
      extPart = null;
      ext = new ExtendedProperties((org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument)NEW_EXT_INSTANCE.copy());
    }

    // Custom properties
    PackageRelationshipCollection custRel =
      pkg.getRelationshipsByType(POIXMLDocument.CUSTOM_PROPERTIES_REL_TYPE);
    if(custRel.size() == 1) {
      custPart = pkg.getPart( custRel.getRelationship(0));
      org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument props = org.openxmlformats.schemas.officeDocument.x2006.customProperties.PropertiesDocument.Factory.parse(
          custPart.getInputStream()
      );
      cust = new CustomProperties(props);
    } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.