Examples of OPCPackage


Examples of org.apache.poi.openxml4j.opc.OPCPackage

     * Check that the sheet iterator returns sheets in the logical order
     * (as they are defined in the workbook.xml)
     */
    public void testOrderOfSheets() throws Exception {
        File f = new File(dirName, "reordered_sheets.xlsx");
        OPCPackage pkg = OPCPackage.open(f.toString());

        XSSFReader r = new XSSFReader(pkg);

        String[] sheetNames = {"Sheet4", "Sheet2", "Sheet3", "Sheet1"};
        XSSFReader.SheetIterator it = (XSSFReader.SheetIterator)r.getSheetsData();
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.OPCPackage

        System.getProperty("HSSF.testdata.path") +
        File.separator + "WithVariousData.xlsx"
    );
    assertTrue(xml.exists());
     
    OPCPackage pkg = OPCPackage.open(xml.toString());
    XSSFWorkbook wb = new XSSFWorkbook(pkg);
        List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
        CommentsTable ct = null;
        for(POIXMLDocumentPart p : rels) {
            if(p instanceof CommentsTable){
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.OPCPackage

    /**
     * Create a new SpreadsheetML package and setup the default minimal content
     */
    protected static OPCPackage newPackage() {
        try {
            OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
            // Main part
            PackagePartName corePartName = PackagingURIHelper.createPartName(XSSFRelation.WORKBOOK.getDefaultFileName());
            // Create main part relationship
            pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
            // Create main document part
            pkg.createPart(corePartName, XSSFRelation.WORKBOOK.getContentType());

            pkg.getPackageProperties().setCreatorProperty("Apache POI");

            return pkg;
        } catch (Exception e){
            throw new POIXMLException(e);
        }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.OPCPackage

   * A package implementer shall neither create nor recognize a part with a
   * part name derived from another part name by appending segments to it.
   * [M1.11]
   */
  public void testPartNameDerivationAdditionFailure() {
    OPCPackage pkg = OPCPackage.create("TODELETEIFEXIST.docx");
    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) {
      fail(e.getMessage());
    }
    fail("A package implementer shall neither create nor recognize a part with a"
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.OPCPackage

   * Rule M1.12 : Packages shall not contain equivalent part names and package
   * implementers shall neither create nor recognize packages with equivalent
   * part names.
   */
  public void testAddPackageAlreadyAddFailure() throws Exception {
    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    PackagePartName name1 = null;
    PackagePartName name2 = null;
    try {
      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 (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

Examples of org.apache.poi.openxml4j.opc.OPCPackage

   * Rule M1.12 : Packages shall not contain equivalent part names and package
   * implementers shall neither create nor recognize packages with equivalent
   * part names.
   */
  public void testAddPackageAlreadyAddFailure2() throws Exception {
    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    PackagePartName partName = null;
    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;
    }
    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

Examples of org.apache.poi.openxml4j.opc.OPCPackage

   * any other part. Package implementers shall enforce this requirement upon
   * the attempt to create such a relationship and shall treat any such
   * relationship as invalid.
   */
  public void testAddRelationshipRelationshipsPartFailure() {
    OPCPackage pkg = OPCPackage.create("DELETEIFEXISTS.docx");
    PackagePartName name1 = null;
    try {
      name1 = PackagingURIHelper
          .createPartName("/test/_rels/document.xml.rels");
    } catch (InvalidFormatException e) {
      fail("This exception should never happen !");
    }

    try {
      pkg.addRelationship(name1, TargetMode.INTERNAL,
          PackageRelationshipTypes.CORE_DOCUMENT);
    } catch (InvalidOperationException e) {
      return;
    }
    fail("Fail test -> M1.25: The Relationships part shall not have relationships to any other part");
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.OPCPackage

* @author Julien Chable
*/
public final class TestOPCComplianceCoreProperties extends TestCase {

  public void testCorePropertiesPart() {
    OPCPackage pkg;
    try {
      InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
      pkg = OPCPackage.open(is);
    } catch (InvalidFormatException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    pkg.revert();
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.OPCPackage

  }

  private static String extractInvalidFormatMessage(String sampleNameSuffix) {

    InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_" + sampleNameSuffix);
    OPCPackage pkg;
    try {
      pkg = OPCPackage.open(is);
    } catch (InvalidFormatException e) {
      // expected during successful test
      return e.getMessage();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    pkg.revert();
    // Normally must thrown an InvalidFormatException exception.
    throw new AssertionFailedError("expected OPC compliance exception was not thrown");
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.OPCPackage

  /**
   * Test M4.1 rule.
   */
  public void testOnlyOneCorePropertiesPart_AddRelationship() {
    InputStream is = OpenXML4JTestDataSamples.openComplianceSampleStream("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
    OPCPackage pkg;
    try {
      pkg = OPCPackage.open(is);
    } catch (InvalidFormatException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    URI partUri = createURI("/docProps/core2.xml");
    try {
      pkg.addRelationship(PackagingURIHelper.createPartName(partUri), TargetMode.INTERNAL,
          PackageRelationshipTypes.CORE_PROPERTIES);
      fail("expected OPC compliance exception was not thrown");
    } catch (InvalidFormatException e) {
      throw new RuntimeException(e);
    } catch (InvalidOperationException e) {
      // expected during successful test
      assertEquals("OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.", e.getMessage());
    }
    pkg.revert();
  }
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.