Examples of OPCPackage


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

  /**
   * Test M4.1 rule.
   */
  public void testOnlyOneCorePropertiesPart_AddPart() {
    String sampleFileName = OpenXML4JTestDataSamples.getComplianceSampleFileName("OPCCompliance_CoreProperties_OnlyOneCorePropertiesPart.docx");
    OPCPackage pkg = null;
    try {
      pkg = OPCPackage.open(sampleFileName);
    } catch (InvalidFormatException e) {
      throw new RuntimeException(e);
    }
   
    URI partUri = createURI("/docProps/core2.xml");
    try {
      pkg.createPart(PackagingURIHelper.createPartName(partUri),
          ContentTypes.CORE_PROPERTIES_PART);
      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]: you try to add more than one core properties relationship in the package !", e.getMessage());
    }
    pkg.revert();
  }
View Full Code Here

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

    OutputStream out = new FileOutputStream(file);
    workbook.write(out);
    out.close();
   
    // Check the package contains what we'd expect it to
    OPCPackage pkg = OPCPackage.open(file.toString());
    PackagePart wbRelPart =
      pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
    assertNotNull(wbRelPart);
    assertTrue(wbRelPart.isRelationshipPart());
    assertEquals(ContentTypes.RELATIONSHIPS_PART, wbRelPart.getContentType());
   
    PackagePart wbPart =
      pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
    // Links to the three sheets, shared strings and styles
    assertTrue(wbPart.hasRelationships());
    assertEquals(5, wbPart.getRelationships().size());
   
    // Load back the XSSFWorkbook
View Full Code Here

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

    XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
    assertNotNull(workbook.getSharedStringSource());
    assertNotNull(workbook.getStylesSource());
   
    // And check a few low level bits too
    OPCPackage pkg = OPCPackage.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
    PackagePart wbPart =
      pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
   
    // Links to the three sheets, shared, styles and themes
    assertTrue(wbPart.hasRelationships());
    assertEquals(6, wbPart.getRelationships().size());
View Full Code Here

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

    /**
     * We should carry vba macros over after save
     */
    public void test45431() throws Exception {
        XSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("45431.xlsm");
        OPCPackage pkg = wb.getPackage();
        assertTrue(wb.isMacroEnabled());

        // Check the various macro related bits can be found
        PackagePart vba = pkg.getPart(
                PackagingURIHelper.createPartName("/xl/vbaProject.bin")
        );
        assertNotNull(vba);
        // And the drawing bit
        PackagePart drw = pkg.getPart(
                PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
        );
        assertNotNull(drw);


        // Save and re-open, both still there
        XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
        OPCPackage nPkg = nwb.getPackage();
        assertTrue(nwb.isMacroEnabled());

        vba = nPkg.getPart(
                PackagingURIHelper.createPartName("/xl/vbaProject.bin")
        );
        assertNotNull(vba);
        drw = nPkg.getPart(
                PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
        );
        assertNotNull(drw);

        // And again, just to be sure
        nwb = XSSFTestDataSamples.writeOutAndReadBack(nwb);
        nPkg = nwb.getPackage();
        assertTrue(nwb.isMacroEnabled());

        vba = nPkg.getPart(
                PackagingURIHelper.createPartName("/xl/vbaProject.bin")
        );
        assertNotNull(vba);
        drw = nPkg.getPart(
                PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
        );
        assertNotNull(drw);
    }
View Full Code Here

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

    /**
     * We should carry vba macros over after save
     */
    public void test45431() throws Exception {
        XSSFWorkbook wb = getTestDataProvider().openSampleWorkbook("45431.xlsm");
        OPCPackage pkg = wb.getPackage();
        assertTrue(wb.isMacroEnabled());

        // Check the various macro related bits can be found
        PackagePart vba = pkg.getPart(
                PackagingURIHelper.createPartName("/xl/vbaProject.bin")
        );
        assertNotNull(vba);
        // And the drawing bit
        PackagePart drw = pkg.getPart(
                PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
        );
        assertNotNull(drw);


        // Save and re-open, both still there
        XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
        OPCPackage nPkg = nwb.getPackage();
        assertTrue(nwb.isMacroEnabled());

        vba = nPkg.getPart(
                PackagingURIHelper.createPartName("/xl/vbaProject.bin")
        );
        assertNotNull(vba);
        drw = nPkg.getPart(
                PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
        );
        assertNotNull(drw);

        // And again, just to be sure
        nwb = XSSFTestDataSamples.writeOutAndReadBack(nwb);
        nPkg = nwb.getPackage();
        assertTrue(nwb.isMacroEnabled());

        vba = nPkg.getPart(
                PackagingURIHelper.createPartName("/xl/vbaProject.bin")
        );
        assertNotNull(vba);
        drw = nPkg.getPart(
                PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
        );
        assertNotNull(drw);
    }
View Full Code Here

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

  public void testCreatePartNameRelativeString()
      throws InvalidFormatException {
    PackagePartName partNameToValid = PackagingURIHelper
        .createPartName("/word/media/image1.gif");

    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(
        "media/image1.gif", partBase);
    assertTrue("The part name must be equal to "
        + partNameToValid.getName(), partNameToValid
        .equals(relativeName));
    pkg.revert();
  }
View Full Code Here

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

   */
  public void testCreatePartNameRelativeURI() throws Exception {
    PackagePartName partNameToValid = PackagingURIHelper
        .createPartName("/word/media/image1.gif");

    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
        .equals(relativeName));
    pkg.revert();
  }
View Full Code Here

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

     * @see org.apache.poi.xssf.extractor.XSSFExcelExtractor#getText()
     */
    @Override
    protected void buildXHTML(XHTMLContentHandler xhtml) throws SAXException,
            XmlException, IOException {
       OPCPackage container = extractor.getPackage();
      
       ReadOnlySharedStringsTable strings;
       XSSFReader.SheetIterator iter;
       XSSFReader xssfReader;
       StylesTable styles;
View Full Code Here

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

    private static MediaType detectOfficeOpenXML(ZipFile zip, TikaInputStream stream) {
        try {
            if (zip.getEntry("_rels/.rels") != null
                    || zip.getEntry("[Content_Types].xml") != null) {
                // Use POI to open and investigate it for us
                OPCPackage pkg = OPCPackage.open(stream.getFile().getPath(), PackageAccess.READ);
                stream.setOpenContainer(pkg);

                // Detect based on the open OPC Package
                return detectOfficeOpenXML(pkg);
            } else {
View Full Code Here

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

public final class TestXWPFDocument extends TestCase {

  public void testContainsMainContentType() throws Exception {
    XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
    OPCPackage pack = doc.getPackage();

    boolean found = false;
    for(PackagePart part : pack.getParts()) {
      if(part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
        found = true;
      }
      if (false) {
        // successful tests should be silent
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.