Package org.apache.poi.openxml4j.opc

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


     */
    protected static OPCPackage newPackage() {
        try {
            OPCPackage pkg = OPCPackage.create(PackageHelper.createTempFile());
            // Main part
            PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
            // Create main part relationship
            pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
            // Create main document part
            pkg.createPart(corePartName, XWPFRelation.DOCUMENT.getContentType());

View Full Code Here


        PackageRelationshipCollection prc =
          corePart.getRelationshipsByType(_relation);
        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();
        }
        log.log(POILogger.WARN, "No part " + _defaultName + " found");
        return null;
View Full Code Here

     */
    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());

View Full Code Here

  /**
   * Test method getExtension().
   */
  public void testGetExtension() throws Exception{
    PackagePartName name1 = PackagingURIHelper.createPartName("/doc/props/document.xml");
    PackagePartName name2 = PackagingURIHelper.createPartName("/root/document");
    assertEquals("xml", name1.getExtension());
    assertEquals("", name2.getExtension());
  }
View Full Code Here

   * Test the addition of several default and override content types.
   */
  public void testContentTypeAddition() throws Exception {
    ContentTypeManager ctm = new ZipContentTypeManager(null, null);

    PackagePartName name1 = PackagingURIHelper
        .createPartName("/foo/foo.XML");
    PackagePartName name2 = PackagingURIHelper
        .createPartName("/foo/foo2.xml");
    PackagePartName name3 = PackagingURIHelper
        .createPartName("/foo/doc.rels");
    PackagePartName name4 = PackagingURIHelper
        .createPartName("/foo/doc.RELS");

    // Add content types
    ctm.addContentType(name1, "foo-type1");
    ctm.addContentType(name2, "foo-type2");
View Full Code Here

   * Test the addition then removal of content types.
   */
  public void testContentTypeRemoval() throws Exception {
    ContentTypeManager ctm = new ZipContentTypeManager(null, null);

    PackagePartName name1 = PackagingURIHelper
        .createPartName("/foo/foo.xml");
    PackagePartName name2 = PackagingURIHelper
        .createPartName("/foo/foo2.xml");
    PackagePartName name3 = PackagingURIHelper
        .createPartName("/foo/doc.rels");
    PackagePartName name4 = PackagingURIHelper
        .createPartName("/foo/doc.RELS");

    // Add content types
    ctm.addContentType(name1, "foo-type1");
    ctm.addContentType(name2, "foo-type2");
View Full Code Here

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

    Package pkg = Package.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

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

    Package pkg = Package.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

    String[] partName1 = { "/word/document.xml", "/docProps/core.xml",
        "/rels/.rels" };
    String[] partName2 = { "/WORD/DocUment.XML", "/docProps/core.xml",
        "/rels/.rels" };
    for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
      PackagePartName p1 = PackagingURIHelper
          .createPartName(partName1[i]);
      PackagePartName p2 = PackagingURIHelper
          .createPartName(partName2[i]);
      assertTrue(p1.equals(p2));
      assertTrue(p1.compareTo(p2) == 0);
      assertTrue(p1.hashCode() == p2.hashCode());
    }
  }
View Full Code Here

    String[] partName1 = { "/word/document.xml", "/docProps/core.xml",
        "/rels/.rels" };
    String[] partName2 = { "/WORD/DocUment.XML2", "/docProp/core.xml",
        "/rels/rels" };
    for (int i = 0; i < partName1.length || i < partName2.length; ++i) {
      PackagePartName p1 = PackagingURIHelper
          .createPartName(partName1[i]);
      PackagePartName p2 = PackagingURIHelper
          .createPartName(partName2[i]);
      assertFalse(p1.equals(p2));
      assertFalse(p1.compareTo(p2) == 0);
      assertFalse(p1.hashCode() == p2.hashCode());
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.openxml4j.opc.PackagePartName

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.