Package org.apache.poi.openxml4j.opc

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

   * Displays information on all the different
   *  relationships between different parts
   *  of the OOXML file container.
   */
  public void displayRelations() throws Exception {
    PackageRelationshipCollection rels =
      container.getRelationships();
    for (PackageRelationship rel : rels) {
      displayRelation(rel, "");
    }
  }
View Full Code Here

        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

     * 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] = getPackagePart().getRelatedPart(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

    }
    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));
       
       // Is it XSSF?
       for(XSSFRelation rel : XSSFExcelExtractor.SUPPORTED_TYPES) {
          if(corePart.getContentType().equals(rel.getContentType())) {
             if(getPreferEventExtractor()) {
View Full Code Here

     * When you open something like a theme, call this to
     *  re-base the XML Document onto the core child of the
     *  current core document
     */
    protected final void rebase(OPCPackage pkg) throws InvalidFormatException {
        PackageRelationshipCollection cores =
            packagePart.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
        if(cores.size() != 1) {
            throw new IllegalStateException(
                "Tried to rebase using " + PackageRelationshipTypes.CORE_DOCUMENT +
                " but found " + cores.size() + " parts of the right type"
            );
        }
        packageRel = cores.getRelationship(0);
        packagePart = packagePart.getRelatedPart(packageRel);
    }
View Full Code Here

     *
     * @param factory   the factory object that creates POIXMLFactory instances
     * @param context   context map containing already visited noted keyed by targetURI
     */
    protected void read(POIXMLFactory factory, Map<PackagePart, POIXMLDocumentPart> context) throws OpenXML4JException {
        PackageRelationshipCollection rels = packagePart.getRelationships();
        for (PackageRelationship rel : rels) {
            if(rel.getTargetMode() == TargetMode.INTERNAL){
                URI uri = rel.getTargetURI();

                PackagePart p;
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.