Examples of PackageRelationshipCollection


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(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(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

   * 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

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

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

Examples of org.openxml4j.opc.PackageRelationshipCollection

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

Examples of org.openxml4j.opc.PackageRelationshipCollection

   *  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

Examples of org.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 =
      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
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.