Package org.apache.poi.openxml4j.opc

Examples of org.apache.poi.openxml4j.opc.OPCPackage.createPart()


    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    // Base part
    PackagePartName nameBase = PackagingURIHelper
        .createPartName("/word/document.xml");
    PackagePart partBase = pkg.createPart(nameBase, ContentTypes.XML);
    // Relative part name
    PackagePartName relativeName = PackagingURIHelper.createPartName(
        new URI("media/image1.gif"), partBase);
    assertTrue("The part name must be equal to "
        + partNameToValid.getName(), partNameToValid
View Full Code Here


    try {
      PackagePartName name = PackagingURIHelper
          .createPartName("/word/document.xml");
      PackagePartName nameDerived = PackagingURIHelper
          .createPartName("/word/document.xml/image1.gif");
      pkg.createPart(name, ContentTypes.XML);
      pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);
    } catch (InvalidOperationException e) {
      pkg.revert();
      return;
    } catch (InvalidFormatException e) {
View Full Code Here

      PackagePartName name = PackagingURIHelper
          .createPartName("/word/document.xml");
      PackagePartName nameDerived = PackagingURIHelper
          .createPartName("/word/document.xml/image1.gif");
      pkg.createPart(name, ContentTypes.XML);
      pkg.createPart(nameDerived, ContentTypes.EXTENSION_GIF);
    } catch (InvalidOperationException e) {
      pkg.revert();
      return;
    } catch (InvalidFormatException e) {
      fail(e.getMessage());
View Full Code Here

      name1 = PackagingURIHelper.createPartName("/word/document.xml");
      name2 = PackagingURIHelper.createPartName("/word/document.xml");
    } catch (InvalidFormatException e) {
      throw new Exception(e.getMessage());
    }
    pkg.createPart(name1, ContentTypes.XML);
    try {
      pkg.createPart(name2, ContentTypes.XML);
    } catch (PartAlreadyExistsException e) {
      return;
    }
View Full Code Here

    } catch (InvalidFormatException e) {
      throw new Exception(e.getMessage());
    }
    pkg.createPart(name1, ContentTypes.XML);
    try {
      pkg.createPart(name2, ContentTypes.XML);
    } catch (PartAlreadyExistsException e) {
      return;
    }
    fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
  }
View Full Code Here

    try {
      partName = PackagingURIHelper.createPartName("/word/document.xml");
    } catch (InvalidFormatException e) {
      throw new Exception(e.getMessage());
    }
    pkg.createPart(partName, ContentTypes.XML);
    try {
      pkg.createPart(partName, ContentTypes.XML);
    } catch (InvalidOperationException e) {
      return;
    }
View Full Code Here

    } catch (InvalidFormatException e) {
      throw new Exception(e.getMessage());
    }
    pkg.createPart(partName, ContentTypes.XML);
    try {
      pkg.createPart(partName, ContentTypes.XML);
    } catch (InvalidOperationException e) {
      return;
    }
    fail("Packages shall not contain equivalent part names and package implementers shall neither create nor recognize packages with equivalent part names. [M1.12]");
  }
View Full Code Here

      throw new RuntimeException(e);
    }
   
    URI partUri = createURI("/docProps/core2.xml");
    try {
      pkg.createPart(PackagingURIHelper.createPartName(partUri),
          ContentTypes.CORE_PROPERTIES_PART);
      // no longer fail on compliance error
      //fail("expected OPC compliance exception was not thrown");
    } catch (InvalidFormatException e) {
      throw new RuntimeException(e);
View Full Code Here

     
      /* manually assemble a new image package part*/
      OPCPackage opcPckg = doc.getPackage();
      XWPFRelation jpgRelation = XWPFRelation.IMAGE_JPEG;
      PackagePartName partName = PackagingURIHelper.createPartName(jpgRelation.getDefaultFileName().replace('#', '2'));
        PackagePart newImagePart = opcPckg.createPart(partName, jpgRelation.getContentType());
        byte[] nature1 = XWPFTestDataSamples.getImage("abstract4.jpg");
        OutputStream os = newImagePart.getOutputStream();
        os.write(nature1);
      os.close();
      XWPFHeader xwpfHeader = doc.getHeaderList().get(0);
View Full Code Here

            throw new MarshalException(e);
        }
       
        PackagePart sigPart = pkg.getPart(sigPartName);
        if (sigPart == null) {
            sigPart = pkg.createPart(sigPartName, ContentTypes.DIGITAL_SIGNATURE_XML_SIGNATURE_PART);
        }
       
        try {
            OutputStream os = sigPart.getOutputStream();
            SignatureDocument sigDoc = SignatureDocument.Factory.parse(document);
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.