Examples of ContentTypeManager


Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

      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

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

        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

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

   
    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

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

  /**
   * 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

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

   
    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

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

   
    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

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

      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

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

   
    // 2. Create a new Package
    //    Eventually, you'll also be able to create an Excel package etc
    //    but only the WordML package exists at present
   
    ctm = new ContentTypeManager();
   
    ctm.addDefaultContentType("rels", "application/vnd.openxmlformats-package.relationships+xml");
    ctm.addDefaultContentType("xml", "application/xml");

    // Later, we'll add each content type to ctm as an override as we encounter it
View Full Code Here

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

   */
  public OpcPackage() {
    try {
      this.setPartName(new PartName("/", false));
     
      contentTypeManager = new ContentTypeManager();
    } catch (Exception e) {
      log.error(e.getMessage());
      // TODO: handle exception
    }
  }
View Full Code Here

Examples of org.docx4j.openpackaging.contenttype.ContentTypeManager

       
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(dotx));
    // NB: clone here if your use case requires it
   
    // Replace dotx content type with docx
    ContentTypeManager ctm = wordMLPackage.getContentTypeManager();
   
    // Get <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml"/>
    CTOverride override = ctm.getOverrideContentType().get(new URI("/word/document.xml")); // note this assumption
    if (dotx.endsWith("dotm")) // // macro enabled?     
    {
      override.setContentType(org.docx4j.openpackaging.contenttype.ContentTypes.WORDPROCESSINGML_DOCUMENT_MACROENABLED)
    } else {
      override.setContentType(org.docx4j.openpackaging.contenttype.ContentTypes.WORDPROCESSINGML_DOCUMENT)
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.