Package org.openxml4j.opc

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 =
      getCorePart().getRelationshipsByType(contentType);
   
    PackagePart[] parts = new PackagePart[partsC.size()];
    int count = 0;
    for (PackageRelationship rel : partsC) {
      parts[count] = getTargetPart(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

 
  private class SheetDataIterator implements Iterator<InputStream> {
    private Iterator<PackageRelationship> sheetRels;
    private SheetDataIterator() throws IOException, InvalidFormatException {
      // Find all the sheets
      PackageRelationshipCollection sheets =
        workbookPart.getRelationshipsByType(
          XSSFWorkbook.WORKSHEET.getRelation()
      );
      sheetRels = sheets.iterator();
    }
View Full Code Here

                    continue;
                }
               
                // Get the comments for the sheet, if there are any
                CommentsSource comments = null;
                PackageRelationshipCollection commentsRel =
                  part.getRelationshipsByType(SHEET_COMMENTS.REL);
                if(commentsRel != null && commentsRel.size() > 0) {
                  PackagePart commentsPart =
                    getTargetPart(commentsRel.getRelationship(0));
                  comments = new CommentsTable(commentsPart.getInputStream());
                }
               
                // Now create the sheet
                WorksheetDocument worksheetDoc = WorksheetDocument.Factory.parse(part.getInputStream());
                XSSFSheet sheet = new XSSFSheet(ctSheet, worksheetDoc.getWorksheet(), this, comments);
                this.sheets.add(sheet);
               
                // Process external hyperlinks for the sheet,
                //  if there are any
                PackageRelationshipCollection hyperlinkRels =
                  part.getRelationshipsByType(SHEET_HYPERLINKS.REL);
                sheet.initHyperlinks(hyperlinkRels);
               
                // Get the embeddings for the workbook
                for(PackageRelationship rel : part.getRelationshipsByType(OLEEMBEDDINGS.REL))
View Full Code Here

            try {
                PackagePart sheetPart = getPackagePart(ctSheet);
                if (sheetPart == null) {
                    continue;
                }
                PackageRelationshipCollection prc = sheetPart.getRelationshipsByType(DRAWINGS.getRelation());
                for (PackageRelationship rel : prc) {
                    PackagePart drawingPart = getTargetPart(rel);
                    PackageRelationshipCollection prc2 = drawingPart.getRelationshipsByType(IMAGES.getRelation());
                    for (PackageRelationship rel2 : prc2) {
                        PackagePart imagePart = getTargetPart(rel2);
                        XSSFPictureData pd = new XSSFPictureData(imagePart);
                        pictures.add(pd);
                    }
View Full Code Here

    /**
     * Fetches the InputStream to read the contents, based
     *  of the specified core part
     */
    public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
            PackageRelationshipCollection prc =
              corePart.getRelationshipsByType(REL);
            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

   */
  protected PackageRelationshipCollection getCollectionOfImageRelationshipsToForwardToNextDocument()
      throws OpenXML4JException {
    //

    PackageRelationshipCollection listOfImages = null;
    try {
      PackagePart docPart = container.getPart(PackagingURIHelper
          .createPartName(new URI(PATH_WORD_DOCUMENT_XML)));
      if (docPart.hasRelationships()) {
        PackageRelationshipCollection relList = docPart
            .getRelationships();
        listOfImages = relList
            .getRelationships(PackageRelationshipTypes.IMAGE_PART);
      }
    } catch (URISyntaxException e) {
      logger.error("cannot generate URI", e);
      // should never happen as arg is "word/document.xml"
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

 
  private class SheetDataIterator implements Iterator<InputStream> {
    private Iterator<PackageRelationship> sheetRels;
    private SheetDataIterator() throws IOException, InvalidFormatException {
      // Find all the sheets
      PackageRelationshipCollection sheets =
        workbookPart.getRelationshipsByType(
            XSSFRelation.WORKSHEET.getRelation()
      );
      sheetRels = sheets.iterator();
    }
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(XSSFRelation.WORKBOOK.getContentType())) {
      return new XSSFExcelExtractor(pkg);
    }
    if(corePart.getContentType().equals(XWPFDocument.MAIN_CONTENT_TYPE)) {
      return new XWPFWordExtractor(pkg);
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.