Examples of ContentTypeManager


Examples of org.apache.poi.openxml4j.opc.internal.ContentTypeManager

    if(targetFile.exists()) targetFile.delete();

    OPCPackage pkg = OPCPackage.create(targetFile);

    // Check it has content types for rels and xml
    ContentTypeManager ctm = getContentTypeManager(pkg);
    assertEquals(
        "application/xml",
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.xml")
        )
    );
    assertEquals(
        ContentTypes.RELATIONSHIPS_PART,
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.rels")
        )
    );
    assertNull(
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.txt")
        )
    );
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.ContentTypeManager

    public void testReplaceContentType() throws Exception {
        InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
        OPCPackage p = OPCPackage.open(is);

        ContentTypeManager mgr = getContentTypeManager(p);

        assertTrue(mgr.isContentTypeRegister("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"));
        assertFalse(mgr.isContentTypeRegister("application/vnd.ms-excel.sheet.macroEnabled.main+xml"));

        assertTrue(
                p.replaceContentType(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
                "application/vnd.ms-excel.sheet.macroEnabled.main+xml")
        );

        assertFalse(mgr.isContentTypeRegister("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"));
        assertTrue(mgr.isContentTypeRegister("application/vnd.ms-excel.sheet.macroEnabled.main+xml"));
    }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.ContentTypeManager

    if(targetFile.exists()) targetFile.delete();

    OPCPackage pkg = OPCPackage.create(targetFile);

    // Check it has content types for rels and xml
    ContentTypeManager ctm = getContentTypeManager(pkg);
    assertEquals(
        "application/xml",
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.xml")
        )
    );
    assertEquals(
        ContentTypes.RELATIONSHIPS_PART,
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.rels")
        )
    );
    assertNull(
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.txt")
        )
    );
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.ContentTypeManager

    if(targetFile.exists()) targetFile.delete();

    OPCPackage pkg = OPCPackage.create(targetFile);

    // Check it has content types for rels and xml
    ContentTypeManager ctm = getContentTypeManager(pkg);
    assertEquals(
        "application/xml",
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.xml")
        )
    );
    assertEquals(
        ContentTypes.RELATIONSHIPS_PART,
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.rels")
        )
    );
    assertNull(
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.txt")
        )
    );
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.ContentTypeManager

    if(targetFile.exists()) targetFile.delete();

    OPCPackage pkg = OPCPackage.create(targetFile);

    // Check it has content types for rels and xml
    ContentTypeManager ctm = getContentTypeManager(pkg);
    assertEquals(
        "application/xml",
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.xml")
        )
    );
    assertEquals(
        ContentTypes.RELATIONSHIPS_PART,
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.rels")
        )
    );
    assertNull(
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.txt")
        )
    );
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.ContentTypeManager

    if(targetFile.exists()) targetFile.delete();

    OPCPackage pkg = OPCPackage.create(targetFile);

    // Check it has content types for rels and xml
    ContentTypeManager ctm = getContentTypeManager(pkg);
    assertEquals(
        "application/xml",
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.xml")
        )
    );
    assertEquals(
        ContentTypes.RELATIONSHIPS_PART,
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.rels")
        )
    );
    assertNull(
        ctm.getContentType(
            PackagingURIHelper.createPartName("/foo.txt")
        )
    );
  }
View Full Code Here

Examples of org.apache.poi.openxml4j.opc.internal.ContentTypeManager

    public void testReplaceContentType() throws Exception {
        InputStream is = OpenXML4JTestDataSamples.openSampleStream("sample.xlsx");
        OPCPackage p = OPCPackage.open(is);

        ContentTypeManager mgr = getContentTypeManager(p);

        assertTrue(mgr.isContentTypeRegister("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"));
        assertFalse(mgr.isContentTypeRegister("application/vnd.ms-excel.sheet.macroEnabled.main+xml"));

        assertTrue(
                p.replaceContentType(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
                "application/vnd.ms-excel.sheet.macroEnabled.main+xml")
        );

        assertFalse(mgr.isContentTypeRegister("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"));
        assertTrue(mgr.isContentTypeRegister("application/vnd.ms-excel.sheet.macroEnabled.main+xml"));
    }
View Full Code Here

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

  public AltChunkType getAltChunkType() {
    return altChunkType;
  }

  public void registerInContentTypeManager() {
    ContentTypeManager ctm = this.getPackage().getContentTypeManager();
    if (altChunkType != null) {
      ctm.addDefaultContentType(altChunkType.getExtension(), altChunkType.getContentType());
    }
  }
View Full Code Here

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

    ImageInfo info = ensureFormatIsSupported(tmpImageFile, bytes, true);
   
    // In the absence of an exception, tmpImageFile now contains an image
    // Word will accept
   
    ContentTypeManager ctm = opcPackage.getContentTypeManager();
   
    // Ensure the relationships part exists
        if (sourcePart.getRelationshipsPart() == null) {
      RelationshipsPart.createRelationshipsPartForPart(sourcePart);
        }

    String proposedRelId = sourcePart.getRelationshipsPart().getNextId();
       
        String ext = info.getMimeType().substring(info.getMimeType().indexOf("/") + 1);
   
//    System.out.println(ext);
   
    BinaryPartAbstractImage imagePart =
                (BinaryPartAbstractImage) ctm.newPartForContentType(
        info.getMimeType(),
                createImageName(opcPackage, sourcePart, proposedRelId, ext), null);
       
        log.debug("created part " + imagePart.getClass().getName()
                + " with name " + imagePart.getPartName().toString());
View Full Code Here

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

  @Deprecated
  public static BinaryPartAbstractImage createImagePart(
      OpcPackage opcPackage,
      Part sourcePart, byte[] bytes, String mime, String ext) throws Exception {
   
    ContentTypeManager ctm = opcPackage.getContentTypeManager();
   
    // Ensure the relationships part exists
        if (sourcePart.getRelationshipsPart() == null) {
      RelationshipsPart.createRelationshipsPartForPart(sourcePart);
        }

    String proposedRelId = sourcePart.getRelationshipsPart().getNextId();
           
    BinaryPartAbstractImage imagePart =
                (BinaryPartAbstractImage) ctm.newPartForContentType(
        mime,
                createImageName(opcPackage, sourcePart, proposedRelId, ext), null);
       
        log.debug("created part " + imagePart.getClass().getName()
                + " with name " + imagePart.getPartName().toString());
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.