Package org.docx4j.openpackaging.contenttype

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


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

       
    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

//    org.docx4j.xmlPackage.Package wmlPackageEl = (org.docx4j.xmlPackage.Package)je.getValue();
    org.docx4j.xmlPackage.Package wmlPackageEl = (org.docx4j.xmlPackage.Package)XmlUtils.unwrap(result.getResult());
   
    org.docx4j.convert.in.FlatOpcXmlImporter xmlPackage = new org.docx4j.convert.in.FlatOpcXmlImporter( wmlPackageEl);
   
    ContentTypeManager ctm = new ContentTypeManager();
   
    Part tmpDocPart = xmlPackage.getRawPart(ctm,  "/word/document.xml", null);
    Part tmpStylesPart = xmlPackage.getRawPart(ctm,  "/word/styles.xml", null);
   
    // This code assumes all the existing rels etc of
View Full Code Here

  public static void apply(WordprocessingMLPackage otherPackage,
      Alterations alterations) throws Docx4JException, JAXBException {
   
    if (alterations.getContentTypes()!=null) {
      log.info("replacing [Content_Types].xml");
      ContentTypeManager newCTM = new ContentTypeManager();
      newCTM.parseContentTypesFile(
          new ByteArrayInputStream(alterations.getContentTypes()));
      otherPackage.setContentTypeManager(newCTM);
    }
   
    if (alterations.isEmpty() ) return;
View Full Code Here

//  public HashMap unusedJCRNodes = null;
 
  public NodeMapper nodeMapper = null;
 
  public LoadFromJCR(NodeMapper nodeMapper) {
    this(new ContentTypeManager(), nodeMapper );
  }
View Full Code Here

   
    // Create skeletal package, including a MainPresentationPart and a SlideLayoutPart
    PresentationMLPackage presentationMLPackage = PresentationMLPackage.createPackage();
   
    if (MACRO_ENABLE) {
      ContentTypeManager ctm = presentationMLPackage.getContentTypeManager();
      ctm.removeContentType(new PartName("/ppt/presentation.xml") );
      ctm.addOverrideContentType(new URI("/ppt/presentation.xml"), ContentTypes.PRESENTATIONML_MACROENABLED);
    }
    
    // Need references to these parts to create a slide
    // Please note that these parts *already exist* - they are
    // created by createPackage() above.  See that method
View Full Code Here

      
        p.getTargetPartStore().setOutputStream(realOS);
      

      // 3. Save [Content_Types].xml
      ContentTypeManager ctm = p.getContentTypeManager();
      p.getTargetPartStore().saveContentTypes(ctm);
     
      // 4. Start with _rels/.rels

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

  public OpcPackage get() throws Docx4JException {
   
    long startTime = System.currentTimeMillis();       

    // 1. Get [Content_Types].xml
    ContentTypeManager ctm = new ContentTypeManager();
    InputStream is = null;
    try {
      is = partStore.loadPart("[Content_Types].xml");   
      ctm.parseContentTypesFile(is);
    } catch (Docx4JException e) {
      throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e);
    } catch (NullPointerException e) {
      throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e);
    } finally {
      IOUtils.closeQuietly(is);
    }
   
    // .. now find the name of the main part
    RelationshipsPart rp = RelationshipsPart.createPackageRels();
    populatePackageRels(rp);
   
    String mainPartName = PackageRelsUtil.getNameOfMainPart(rp);
    PartName mainPartNameObj;
    if (mainPartName.startsWith("/")) {
      // OpenXML SDK 2.0 writes Target="/word/document.xml" (note leading "/")
      mainPartNameObj = new PartName(mainPartName);
    } else {
      // Microsoft Word, docx4j etc write Target="word/document.xml"
      mainPartNameObj = new PartName("/" + mainPartName);
    }
    String pkgContentType = ctm.getContentType(mainPartNameObj);

    // 2. Create a new Package; this'll return the appropriate subclass
    OpcPackage p = ctm.createPackage(pkgContentType);
    log.info("Instantiated package of type " + p.getClass().getName() );
    p.setSourcePartStore(partStore);

    p.setRelationships(rp);
    rp.setSourceP(p); //
View Full Code Here

     
//          // Create the ZIP file
//          ZipOutputStream out = new ZipOutputStream(new FileOutputStream(filepath));

      // 3. Get [Content_Types].xml
      ContentTypeManager ctm = p.getContentTypeManager();
      org.w3c.dom.Document w3cDoc = XmlUtils.getNewDocumentBuilder().newDocument();
     
      ctm.marshal( w3cDoc );
     
      saveRawXmlPart(jcrSession, baseNode, "[Content_Types].xml", w3cDoc);
     
         
      // 4. Start with _rels/.rels
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.