Package org.docx4j.openpackaging.parts.WordprocessingML

Examples of org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart


        r = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n" + r;
      }
      //System.out.println(r);
     
      // .. create the part
      AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(
          getNewPartName("/chunk", ".xml", sourcePart.getRelationshipsPart()));
     
      afiPart.setBinaryData(r.getBytes("UTF-8"));
 
      afiPart.setAltChunkType(AltChunkType.Xml); // Flat OPC XML
     
     
      Relationship altChunkRel =sourcePart.addTargetPart(afiPart);
     
      // now that its attached to the package ..
      afiPart.registerInContentTypeManager();
     
 
      CTAltChunk ac = Context.getWmlObjectFactory()
          .createCTAltChunk();
      ac.setId(altChunkRel.getId());
View Full Code Here


          log.error("You need a docxFetcher (and the MergeDocx extension) to fetch components");
          return srcPackage;
        }

        // .. create the part
        AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(
            getNewPartName("/chunk", ".docx", srcPackage
                .getMainDocumentPart().getRelationshipsPart()));
        afiPart.setBinaryData(docxFetcher.getDocxFromIRI(iri));

        afiPart.setContentType(new ContentType(
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml")); // docx

        Relationship altChunkRel = srcPackage.getMainDocumentPart()
            .addTargetPart(afiPart);
        CTAltChunk ac = Context.getWmlObjectFactory()
View Full Code Here

    if (rel!=null && rel.getType().equals(Namespaces.AF) ) {
      // Could have just passed String relType
      // Null where used from BPAI, and a FlatOpcXmlImporter case.
      // Cases where rel is not available can prepare a suitable dummy
     
      AlternativeFormatInputPart afip =
        new AlternativeFormatInputPart(new PartName(partName) );
      afip.setContentType(new ContentType(contentType));
      return afip;
     
    } else if (rel!=null && rel.getType().equals(Namespaces.EMBEDDED_PKG) ) {
     
      EmbeddedPackagePart epp = new EmbeddedPackagePart(new PartName(partName) );
View Full Code Here

   * @see org.docx4j.openpackaging.parts.WordprocessingML.AltChunkInterface#addAltChunkOfTypeHTML(byte[])
   */
  @Override
  public AlternativeFormatInputPart addAltChunk(AltChunkType type, byte[] bytesthrows Docx4JException {
   
    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(type);
    Relationship altChunkRel = this.addTargetPart(afiPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // now that its attached to the package ..
    afiPart.registerInContentTypeManager();
   
    afiPart.setBinaryData(bytes);    
   
    // .. the bit in document body
    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    if (this instanceof ContentAccessor) {
View Full Code Here

   * @see org.docx4j.openpackaging.parts.WordprocessingML.AltChunkInterface#addAltChunkOfTypeHTML(java.io.InputStream)
   */
  @Override
  public AlternativeFormatInputPart addAltChunk(AltChunkType type, InputStream is)   throws Docx4JException {
   
    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(type);
    Relationship altChunkRel = this.addTargetPart(afiPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // now that its attached to the package ..
    afiPart.registerInContentTypeManager();   
   
    afiPart.setBinaryData(is);
   
    // .. the bit in document body
    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    if (this instanceof ContentAccessor) {
View Full Code Here

   */
  @Override
  public AlternativeFormatInputPart addAltChunk(AltChunkType type, byte[] bytes,
      ContentAccessor attachmentPoint)   throws Docx4JException {
   
    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(type);
    Relationship altChunkRel = this.addTargetPart(afiPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // now that its attached to the package ..
    afiPart.registerInContentTypeManager();
   
    afiPart.setBinaryData(bytes);    
   
    // .. the bit in document body
    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    attachmentPoint.getContent().add(ac);
View Full Code Here

   */
  @Override
  public AlternativeFormatInputPart addAltChunk(AltChunkType type, InputStream is,
      ContentAccessor attachmentPoint) throws Docx4JException {
   
    AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(type);
    Relationship altChunkRel = this.addTargetPart(afiPart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);
    // now that its attached to the package ..
    afiPart.registerInContentTypeManager();   
   
    afiPart.setBinaryData(is);
   
    // .. the bit in document body
    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    attachmentPoint.getContent().add(ac);
View Full Code Here

    CTAltChunk altChunk;
    boolean encounteredDocxAltChunk = false;
    for (LocatedChunk locatedChunk : bf.getAltChunks()) {
     
      altChunk = locatedChunk.getAltChunk();
      AlternativeFormatInputPart afip
        =  (AlternativeFormatInputPart)clonedPart.getRelationshipsPart().getPart(
            altChunk.getId() );
     
      // Can we process it?
      AltChunkType type = afip.getAltChunkType();

      if (type.equals(AltChunkType.Xhtml) ) {
       
        XHTMLImporter xHTMLImporter= null;
          try {
            Class<?> xhtmlImporterClass = Class.forName("org.docx4j.convert.in.xhtml.XHTMLImporterImpl");
            Constructor<?> ctor = xhtmlImporterClass.getConstructor(WordprocessingMLPackage.class);
            xHTMLImporter = (XHTMLImporter) ctor.newInstance(clonePkg);
          } catch (Exception e) {
              log.error("docx4j-XHTMLImport jar not found. Please add this to your classpath.");
          log.error(e.getMessage(), e);
          return null;
          }   
       
              List<Object> results = null;
        try {
         
          results = xHTMLImporter.convert(toString(afip.getBuffer()), null);
         
        } catch (Exception e) {
          log.error(e.getMessage(), e);
          // Skip this one
          continue;
        }
       
        int index = locatedChunk.getIndex();
        locatedChunk.getContentList().remove(index); // handles case where it is nested eg in a tc
        locatedChunk.getContentList().addAll(index, results)
       
        log.info("Converted altChunk of type XHTML ");
       
      } else if (type.equals(AltChunkType.Mht) ) {
        log.warn("Skipping altChunk of type MHT ");
        continue;
      } else if (type.equals(AltChunkType.Xml) ) {
        log.warn("Skipping altChunk of type XML "); // what does Word do??
        continue;
      } else if (type.equals(AltChunkType.TextPlain) ) {
       
        String result= null;
        try {
          result = toString(afip.getBuffer());
        } catch (UnsupportedEncodingException e) {
          log.error(e.getMessage(), e);
          // Skip this one
          continue;
        }
View Full Code Here

        }
    }

    public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher matcher) {
        try {
            AlternativeFormatInputPart afiPart = new AlternativeFormatInputPart(new PartName("/" + UUID.randomUUID().toString() + ".html"));
            afiPart.setBinaryData(paramValue.toString().getBytes());
            afiPart.setContentType(new ContentType("text/html"));
            Relationship altChunkRel = wordPackage.getMainDocumentPart().addTargetPart(afiPart);
            CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
            ac.setId(altChunkRel.getId());
            R run = (R) text.getParent();
            run.getContent().add(ac);
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.parts.WordprocessingML.AlternativeFormatInputPart

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.