Package org.docx4j.openpackaging.contenttype

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


    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

  @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

      return createImagePart(
           opcPackage,
           sourcePart,  bytes);
    }
   
    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

        final byte[] locByte = new byte[1];

        //We are in the case that image is not load (no byte Array) so isLoad is false
        ImageInfo info = ensureFormatIsSupported(imageFile, locByte, false);

        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);

        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

   
    log.debug("Incoming url for linked image: " + url.toString() );
   
        ImageInfo info = ensureFormatIsSupported(url, null, null, false); // final param doesn't matter in this case

    ContentTypeManager ctm = opcPackage.getContentTypeManager();
    String proposedRelId = sourcePart.getRelationshipsPart().getNextId();
    // In order to ensure unique part name,
    // idea is to use the relId, which ought to be unique
        String ext = info.getMimeType().substring(info.getMimeType().indexOf("/") + 1);
   
    BinaryPartAbstractImage imagePart =
                (BinaryPartAbstractImage) ctm.newPartForContentType(
        info.getMimeType(),
                createImageName(opcPackage, sourcePart, proposedRelId, ext), null);
   
    // NB: contents never populated
       
View Full Code Here

  /**
   * It is often useful to see this [Content_Types].xml
   */
  public static void printContentTypes(org.docx4j.openpackaging.packages.OpcPackage p) {
   
    ContentTypeManager ctm = p.getContentTypeManager();
    //ctm.listTypes();
    System.out.println(
        ctm.toString() );   
  }
View Full Code Here

   
    String path_in = System.getProperty("user.dir") + "/src/test/resources/parts/";
   
    // Need to know how what type of part to map to   
    InputStream in = new FileInputStream(path_in + "[Content_Types].xml");
    ContentTypeManager externalCtm = new ContentTypeManager();
    externalCtm.parseContentTypesFile(in);
   
    // Example of a part which become a rel of the word document
    in = new FileInputStream(path_in + "settings.xml");
    attachForeignPart(wordMLPackage, wordMLPackage.getMainDocumentPart(),
        externalCtm, "word/settings.xml", in);
View Full Code Here

   
    Part foreignPart = Load.getRawPart(is, foreignCtm,  resolvedPartUri, null);
      // the null means this won't work for an AlternativeFormatInputPart
    attachmentPoint.addTargetPart(foreignPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // Add content type
    ContentTypeManager packageCtm = wordMLPackage.getContentTypeManager();
    packageCtm.addOverrideContentType(foreignPart.getPartName().getURI(), foreignPart.getContentType());
   
    System.out.println("Attached foreign part: " + resolvedPartUri);
   
  }
View Full Code Here

      ZipOutputStream out = new ZipOutputStream(realOS);
     
     
      // 3. Save [Content_Types].xml
      ContentTypeManager ctm = p.getContentTypeManager();
          out.putNextEntry(new ZipEntry("[Content_Types].xml"));
          ctm.marshal(out);
          out.closeEntry();
         
      // 4. Start with _rels/.rels

//      <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.contenttype.ContentTypeManager

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.