Package org.docx4j.model.datastorage

Examples of org.docx4j.model.datastorage.CustomXmlDataStorage


      }
     
     
    }
    else if (source instanceof CustomXmlDataStoragePart) {
      CustomXmlDataStorage dataStorage = ((CustomXmlDataStoragePart)source).getData().factory();
      dataStorage.setDocument(
          (Document)((CustomXmlDataStoragePart)source).getData().getDocument().cloneNode(true));
      ((CustomXmlDataStoragePart)destination).setData(dataStorage);
    }
    else if (source instanceof XmlPart) {
      ((XmlPart)destination).setDocument((Document)((XmlPart)source).getDocument().cloneNode(true));
View Full Code Here


            } else {
             
              log.warn("No known part after all for CustomXmlPart " + o.getClass().getName());

              CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory();         
              is.reset();
              data.setDocument(is); // Not necessarily JAXB, that's just our method name
              ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);           
             
            }
           
          } catch (javax.xml.bind.UnmarshalException ue) {
           
            // No ...
            CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory()
            is.reset();
            data.setDocument(is); // Not necessarily JAXB, that's just our method name
            ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);           
          }         
                   
        } else {
          // Shouldn't happen, since ContentTypeManagerImpl should
View Full Code Here

                           
            } else {
             
              log.warn("No known part after all for CustomXmlPart " + o.getClass().getName());

              CustomXmlDataStorage data = Load.getCustomXmlDataStorageClass().factory();

              // Copy el into a new document
              org.w3c.dom.Document doc = XmlUtils.getNewDocumentBuilder().newDocument();
              //XmlUtils.treeCopy(el, doc);
              org.w3c.dom.Node copy = doc.importNode(el, true);
              // Word doesn't like the xml namespace to be bound. At some point in a process
              // from docx -> package-> flatopc -> package -> docx, it is added to the custom xml root element.
              try {
                copy.getAttributes().removeNamedItemNS("http://www.w3.org/2000/xmlns/","xml");
              } catch (DOMException e) {}
              doc.appendChild(copy);             
              data.setDocument(doc);
             
              ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart) part)
                  .setData(data);
             
            }
           
          } catch (javax.xml.bind.UnmarshalException ue) {
           
            // No ...
            CustomXmlDataStorage data = Load.getCustomXmlDataStorageClass().factory();

            // Copy el into a new document
            org.w3c.dom.Document doc = XmlUtils.getNewDocumentBuilder().newDocument();
            //XmlUtils.treeCopy(el, doc);
            org.w3c.dom.Node copy = doc.importNode(el, true);
            try {
              copy.getAttributes().removeNamedItemNS("http://www.w3.org/2000/xmlns/","xml");
            } catch (DOMException e) {}
            doc.appendChild(copy);             
            data.setDocument(doc);
           
            ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart) part)
                .setData(data);
          }         
         
View Full Code Here

    //          w:storeItemID="{5448916C-134B-45E6-B8FE-88CC1FFC17C3}"/>
    //    </w:sdtPr>
    //    <w:sdtContent>   
   
    // Get the contents   
    CustomXmlDataStorage customXmlDataStorage = customXmlDataStoragePart.getData();
      // In a real program what you might do is populate this with your own data.
      // You could replace the whole part (as is done in https://github.com/plutext/OpenDoPE-WAR/blob/master/webapp-simple/src/main/java/org/opendope/webapp/SubmitBoth.java ),
        // or as we show below, just set some particular value
   
       
    // Change its contents.  Here we use XPath, but you could get the DOM document:
    //   ((CustomXmlDataStorageImpl)customXmlDataStorage).getDocument()
    // and do whatever ....
    ((CustomXmlDataStorageImpl)customXmlDataStorage).setNodeValueAtXPath("/myxml/element1", example_value_to_inject,
        "xmlns:ns0='http://your.namespace'"); // no prefix mappings required here, but that shows you how to do it

    System.out.println(XmlUtils.w3CDomNodeToString(customXmlDataStorage.getDocument()));
   
    // Apply the bindings
    BindingHandler bh = new BindingHandler(wordMLPackage);
    bh.applyBindings(wordMLPackage.getMainDocumentPart());
   
View Full Code Here

          log.debug("Detected BinaryPart " + part.getClass().getName() );
          ((BinaryPart)part).setBinaryData(is);
         
        } else if (part instanceof org.docx4j.openpackaging.parts.CustomXmlDataStoragePart ) {
         
          CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory();         
          data.setDocument(is); // Not necessarily JAXB, that's just our method name
          ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);         
                   
        } else {
          // Shouldn't happen, since ContentTypeManagerImpl should
          // return an instance of one of the above, or throw an
View Full Code Here

   
      org.docx4j.openpackaging.parts.CustomXmlDataStoragePart customXmlDataStoragePart =
        new org.docx4j.openpackaging.parts.CustomXmlDataStoragePart();
        // Defaults to /customXml/item1.xml
     
      CustomXmlDataStorage data = new CustomXmlDataStorageImpl();
      data.setDocument(createCustomXmlDocument());
     
      customXmlDataStoragePart.setData(data);
      parent.addTargetPart(customXmlDataStoragePart, AddPartBehaviour.RENAME_IF_NAME_EXISTS);

      return customXmlDataStoragePart;
View Full Code Here

                           
            } else {
             
              log.error("TODO: handle known CustomXmlPart part  " + o.getClass().getName());

              CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory();         
              is.reset();
              data.setDocument(is); // Not necessarily JAXB, that's just our method name
              ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);           
             
            }
           
          } catch (javax.xml.bind.UnmarshalException ue) {

            log.warn("No JAXB model for this CustomXmlDataStorage part; " + ue.getMessage()  );
           
            CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory()
            is.reset();
            data.setDocument(is); // Not necessarily JAXB, that's just our method name
            ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);           
          }         

        } else if (part instanceof org.docx4j.openpackaging.parts.XmlPart ) {
View Full Code Here

                           
            } else {
             
              log.error("TODO: handle known CustomXmlPart part  " + o.getClass().getName());

              CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory();         
              is.reset();
              data.setDocument(is); // Not necessarily JAXB, that's just our method name
              ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);           
             
            }
           
          } catch (javax.xml.bind.UnmarshalException ue) {

            log.warn("No JAXB model for this CustomXmlDataStorage part; " + ue.getMessage()  );
           
            CustomXmlDataStorage data = getCustomXmlDataStorageClass().factory()
            is.reset();
            data.setDocument(is); // Not necessarily JAXB, that's just our method name
            ((org.docx4j.openpackaging.parts.CustomXmlDataStoragePart)part).setData(data);           
          }         

        } else if (part instanceof org.docx4j.openpackaging.parts.XmlPart ) {
         
View Full Code Here

TOP

Related Classes of org.docx4j.model.datastorage.CustomXmlDataStorage

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.