Package org.openxml4j.opc

Examples of org.openxml4j.opc.PackageRelationshipCollection


   * @param relationType The relation content type to search for
   * @throws IllegalArgumentException If we find more than one part of that type
   * TODO: this sucks! Make Package and PackagePart implement common intf that defines getRelationshipsByType & friends
   */
  protected PackagePart getSinglePartByRelationType(String relationType, PackagePart part) throws IllegalArgumentException, OpenXML4JException {
    PackageRelationshipCollection rels =
      part.getRelationshipsByType(relationType);
    if(rels.size() == 0) {
      return null;
    }
    if(rels.size() > 1) {
      throw new IllegalArgumentException("Found " + rels.size() + " relations for the type " + relationType + ", should only ever be one!");
    }
    PackageRelationship rel = rels.getRelationship(0);
    return getPackagePart(rel);
  }
View Full Code Here


   */
  public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackagePart slidePart =
      getRelatedPackagePart(slide.getId2());
   
    PackageRelationshipCollection notes;
    try {
      notes = slidePart.getRelationshipsByType(NOTES_RELATION_TYPE);
    } 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());
    }
   
    PackagePart notesPart =
      getPackagePart(notes.getRelationship(0));
    NotesDocument notesDoc =
      NotesDocument.Factory.parse(notesPart.getInputStream());
   
    return notesDoc.getNotes();
  }
View Full Code Here

   *  container, or null if none found.
   * @param relationType The relation content type to search for
   * @throws IllegalArgumentException If we find more than one part of that type
   */
  protected PackagePart getSinglePartByRelationType(String relationType) throws IllegalArgumentException, OpenXML4JException {
    PackageRelationshipCollection rels =
      container.getRelationshipsByType(relationType);
    if(rels.size() == 0) {
      return null;
    }
    if(rels.size() > 1) {
      throw new IllegalArgumentException("Found " + rels.size() + " relations for the type " + relationType + ", should only ever be one!");
    }
    PackageRelationship rel = rels.getRelationship(0);
    return getPackagePart(rel);
  }
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 =
      basePart.getRelationshipsByType(contentType);
   
    PackagePart[] parts = new PackagePart[partsC.size()];
    int count = 0;
    for (PackageRelationship rel : partsC) {
      parts[count] = getPackagePart(rel);
      count++;
    }
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

  /**
   * Returns the low level notes object for the given
   *  slide, as found from the supplied slide reference
   */
  public CTNotesSlide getNotes(CTSlideIdListEntry slide) throws IOException, XmlException {
    PackageRelationshipCollection notes;
    try {
      PackagePart slidePart =
        getTargetPart(getCorePart().getRelationship(slide.getId2()));
   
      notes = slidePart.getRelationshipsByType(NOTES_RELATION_TYPE);
    } 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 {
      PackagePart notesPart =
        getTargetPart(notes.getRelationship(0));
      NotesDocument notesDoc =
        NotesDocument.Factory.parse(notesPart.getInputStream());
     
      return notesDoc.getNotes();
    } 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(Package 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(XSSFWorkbook.WORKBOOK.getContentType())) {
      return new XSSFExcelExtractor(pkg);
    }
    if(corePart.getContentType().equals(XWPFDocument.MAIN_CONTENT_TYPE)) {
      return new XWPFWordExtractor(pkg);
View Full Code Here

    } catch(Exception e) {
      throw new OpenXML4JException(e.getLocalizedMessage());
    }

    // Get the comments, if there are any
    PackageRelationshipCollection commentsRel = getCmntRelations();
    if(commentsRel != null && commentsRel.size() > 0) {
      PackagePart commentsPart = getTargetPart(commentsRel.getRelationship(0));
      CommentsDocument cmntdoc = CommentsDocument.Factory.parse(commentsPart.getInputStream());
      for(CTComment ctcomment : cmntdoc.getComments().getCommentArray())
      {
        comments.add(new XWPFComment(ctcomment));
      }
View Full Code Here

 
  public POIXMLProperties(Package 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) {
      PropertiesDocument props = PropertiesDocument.Factory.parse(
          pkg.getPart( extRel.getRelationship(0) ).getInputStream()
      );
      ext = new ExtendedProperties(props);
    } else {
      ext = new ExtendedProperties(PropertiesDocument.Factory.newInstance());
    }
View Full Code Here

   package/container, or null if none found.
   * @param relationType The relation content type to search for
   * @throws IllegalArgumentException If we find more than one part of that type
   */
  protected PackagePart getSinglePartByRelationType(String relationType) throws IllegalArgumentException, OpenXML4JException {
    PackageRelationshipCollection rels =
      pkg.getRelationshipsByType(relationType);
    if(rels.size() == 0) {
      return null;
    }
    if(rels.size() > 1) {
      throw new IllegalArgumentException("Found " + rels.size() + " relations for the type " + relationType + ", should only ever be one!");
    }
    PackageRelationship rel = rels.getRelationship(0);
    return getTargetPart(rel);
  }
View Full Code Here

TOP

Related Classes of org.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.