Package org.openxml4j.opc

Examples of org.openxml4j.opc.PackagePart


    } else {
      docPath = demoCore.getTestRootPath() + "sample.docx";
    }

    // Retrieves core part
    PackagePart corePart = demo.getCorePartUri(docPath);
    if (corePart != null)
      System.out.println(corePart.getPartName() + " -> "
          + corePart.getContentType());
    else
      System.out.println("The specified file is not valid !");
  }
View Full Code Here


          .getRelationshipsByType(
              PackageRelationshipTypes.EXTENDED_PROPERTIES)
          .getRelationship(0);

      // Retrieves extended properties part
      PackagePart extPropsPart = p
          .getPart(extendedPropertiesRelationship);
      System.out.println(extPropsPart.getPartName() + " -> "
          + extPropsPart.getContentType());

      // Get the input stream from the extended properties part
      InputStream inStream = extPropsPart.getInputStream();

      // Parse the XML content
      SAXReader xmlReader = new SAXReader();
      Document extPropsDoc = xmlReader.read(inStream);
View Full Code Here

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

     *
     * @return false if error
     * @throws OpenXML4JException
     */
    private boolean parseDocumentContent() throws OpenXML4JException {
      PackagePart contentPart = getCorePart();
      if (contentPart == null) {
        logger.error("The document has no contents!");
        return false;
      }

      logger.debug("reading doc content:" + contentPart.getPartName());
      InputStream inStream = null;
      try {
        inStream = contentPart.getInputStream();
      } catch (IOException e) {
        logger.error("error reading the document.xml", e);
        return false;
      }

View Full Code Here

  private void test(POIXMLDocument doc, int expectedCount) throws Exception {
    assertNotNull(doc.getAllEmbedds());
    assertEquals(expectedCount, doc.getAllEmbedds().size());

    for(int i=0; i<doc.getAllEmbedds().size(); i++) {
      PackagePart pp = doc.getAllEmbedds().get(i);
      assertNotNull(pp);
     
      byte[] b = IOUtils.toByteArray(pp.getInputStream());
      assertTrue(b.length > 0);
    }
  }
View Full Code Here

        if(rel == null) {
          throw new IllegalArgumentException("No Sheet found with r:id " + relId);
        }
       
        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
        PackagePart sheet = pkg.getPart(relName);
        if(sheet == null) {
          throw new IllegalArgumentException("No data found for Sheet with r:id " + relId);
        }
        return sheet.getInputStream();
  }
View Full Code Here

    public InputStream next() {
      PackageRelationship sheet = sheetRels.next();
      try {
            PackagePartName relName = PackagingURIHelper.createPartName(sheet.getTargetURI());
        PackagePart sheetPkg = pkg.getPart(relName);
        return sheetPkg.getInputStream();
      } catch(IOException e) {
        throw new RuntimeException(e);
      } catch(InvalidFormatException ife) {
        throw new RuntimeException(ife);
      }
View Full Code Here

      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);
    }
    if(corePart.getContentType().equals(XSLFSlideShow.MAIN_CONTENT_TYPE)) {
      return new XSLFPowerPointExtractor(pkg);
    }
    throw new IllegalArgumentException("No supported documents found in the OOXML package");
  }
View Full Code Here

   
    presentationDoc =
      PresentationDocument.Factory.parse(getCorePart().getInputStream());
   
    for (CTSlideIdListEntry ctSlide : getSlideReferences().getSldIdArray()) {
            PackagePart slidePart =
                  getTargetPart(getCorePart().getRelationship(ctSlide.getId2()));
           
            for(PackageRelationship rel : slidePart.getRelationshipsByType(OLE_OBJECT_REL_TYPE))
                embedds.add(getTargetPart(rel)); // TODO: Add this reference to each slide as well
           
            for(PackageRelationship rel : slidePart.getRelationshipsByType(PACK_OBJECT_REL_TYPE))
                  embedds.add(getTargetPart(rel));
    }
  }
View Full Code Here

     * @return The target part
     * @throws InvalidFormatException
     */
    public static PackagePart getTargetPart(Package pkg, PackageRelationship rel) throws InvalidFormatException {
        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
        PackagePart part = pkg.getPart(relName);
        if (part == null) {
            throw new IllegalArgumentException("No part found for relationship " + rel);
        }
        return part;
    }
View Full Code Here

TOP

Related Classes of org.openxml4j.opc.PackagePart

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.