@Override public void setDocument(Document document) { this.document = document; df = document.createDocumentFragment(); }
/** * Constructor for XMLFragment object. */ public XMLFragment() { doc = JAXPUtils.getDocumentBuilder().newDocument(); fragment = doc.createDocumentFragment(); }
private DocumentFragment emptyFragment() throws TransformerException { Document document = XmlUtils.getNewDocumentBuilder().newDocument(); return document.createDocumentFragment(); } }
private DocumentFragment result(Document document) { if (outputType== RunFontActionType.DISCOVERY) { /* Avoid * Exception in thread "main" java.lang.NullPointerException at com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(Unknown Source) at com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(Unknown Source) at com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(Unknown Source) at org.docx4j.fonts.RunFontSelector.result(RunFontSelector.java:202) at org.docx4j.fonts.RunFontSelector.fontSelector(RunFontSelector.java:366) */ return null; } DocumentFragment docfrag = document.createDocumentFragment(); docfrag.appendChild(document.getDocumentElement()); return docfrag; }
/** * Method createDocumentFragment * * * NEEDSDOC (createDocumentFragment) @return */ synchronized public DTM createDocumentFragment() { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); Node df = doc.createDocumentFragment(); return getDTM(new DOMSource(df), true, null, false, false); } catch (Exception e) { throw new DTMException(e); } }
/** * Method createDocumentFragment * * * NEEDSDOC (createDocumentFragment) @return */ synchronized public DTM createDocumentFragment() { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); Node df = doc.createDocumentFragment(); return getDTM(new DOMSource(df), true, null, false, false); } catch (Exception e) { throw new DTMException(e); } }
private static void createPlaceholderFragment() throws Exception { // create it - one time operation InputStream is; try { is = ResourceUtils.getResourceViaProperty("docx4j.model.datastorage.placeholder" , placeholderResource); } catch (IOException e) { log.info("No resource on classpath for property docx4j.model.datastorage.placeholder; falling back to using org/docx4j/model/datastorage/placeholder.xml"); is = ResourceUtils.getResource(placeholderResourceFallback); } Document tmpDoc = XmlUtils.getNewDocumentBuilder().parse(is); placeholderFragment = tmpDoc.createDocumentFragment(); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), placeholderFragment); }
/** * A customised XSLT might just want the <style> element, because it customises * the rest of the <head> element. * * @param conversionContext * @return */ public static DocumentFragment appendStyleElement(HTMLConversionContext conversionContext) { // Create a DOM document to take the results Document document = XmlUtils.getNewDocumentBuilder().newDocument(); StringBuilder buffer = new StringBuilder(10240); // <style.. Element element = createStyleElement(conversionContext, document, buffer); if (element == null) { return null; } document.appendChild(element); DocumentFragment docfrag = document.createDocumentFragment(); docfrag.appendChild(document.getDocumentElement()); return docfrag; }
@Override public Node toNode(WordprocessingMLPackage wmlPackage, SdtPr sdtPr, HashMap<String, String> tagMap, NodeIterator childResults) throws TransformerException { try { // Create a DOM builder and parse the fragment Document document = XmlUtils.getNewDocumentBuilder().newDocument(); DocumentFragment docfrag = document.createDocumentFragment(); return attachContents(docfrag, docfrag, childResults); } catch (Exception e) { throw new TransformerException(e); } }
/** * A customised XSLT might just want the <script> element, because it customises * the rest of the <head> element. * * @param conversionContext * @return */ public static DocumentFragment appendScriptElement(HTMLConversionContext conversionContext) { // This method is necessary, since it is how the customised XSLT // actually invokes ConversionHTMLScriptElementHandler // Create a DOM document to take the results Document document = XmlUtils.getNewDocumentBuilder().newDocument(); StringBuilder buffer = new StringBuilder(10240); // <script.. Element element = createScriptElement(conversionContext, document, buffer); if (element == null) { return null; } document.appendChild(element); DocumentFragment docfrag = document.createDocumentFragment(); docfrag.appendChild(document.getDocumentElement()); return docfrag; }
@Override public Node toNode(WordprocessingMLPackage wmlPackage, SdtPr sdtPr, HashMap<String, String> tagMap, Node resultSoFar) throws TransformerException { // Implemented just in case user explicitly invokes IdentityHandler.. try { // Create a DOM builder and parse the fragment Document document = XmlUtils.getNewDocumentBuilder().newDocument(); DocumentFragment docfrag = document.createDocumentFragment(); return attachContents(docfrag, docfrag, resultSoFar); } catch (Exception e) { throw new TransformerException(e); } } }
public DocumentFragment message(AbstractConversionContext context, String message) { if (!context.getLog().isDebugEnabled()) return null; String documentFragment = getOutputPrefix() + message + getOutputSuffix(); context.getLog().debug(documentFragment); StringReader reader = new StringReader(documentFragment); InputSource inputSource = new InputSource(reader); Document doc = null; try { doc = XmlUtils.getNewDocumentBuilder().parse(inputSource); } catch (Exception e) { context.getLog().error(e.getMessage(),e); } reader.close(); DocumentFragment docfrag = doc.createDocumentFragment(); docfrag.appendChild(doc.getDocumentElement()); return docfrag; }
@Override public Node toNode(WordprocessingMLPackage wmlPackage, SdtPr sdtPr, HashMap<String, String> tagMap, NodeIterator childResults) throws TransformerException { try { // Create a DOM builder and parse the fragment Document document = XmlUtils.getNewDocumentBuilder().newDocument(); DocumentFragment docfrag = document.createDocumentFragment(); Element xhtmlDiv = this.createDiv(document, docfrag, sdtPr, tagMap); return attachContents(docfrag, xhtmlDiv, childResults); } catch (Exception e) { throw new TransformerException(e); } }
@Override public Node toNode(WordprocessingMLPackage wmlPackage, SdtPr sdtPr, HashMap<String, String> tagMap, Node resultSoFar) throws TransformerException { try { // Create a DOM builder and parse the fragment Document document = XmlUtils.getNewDocumentBuilder().newDocument(); DocumentFragment docfrag = document.createDocumentFragment(); Element xhtmlDiv = this.createDiv(document, docfrag, sdtPr, tagMap); return attachContents(docfrag, xhtmlDiv, resultSoFar); } catch (Exception e) { throw new TransformerException(e); } } }
return d.createDocumentFragment(); DocumentFragment docfrag = d.createDocumentFragment(); docfrag.appendChild(d.getDocumentElement());
DocumentFragment docfrag = document.createDocumentFragment();
@Override public Node toNode(WordprocessingMLPackage wmlPackage, SdtPr sdtPr, HashMap<String, String> tagMap, Node resultSoFar) throws TransformerException { try { // Create a DOM builder and parse the fragment Document document = XmlUtils.getNewDocumentBuilder().newDocument(); DocumentFragment docfrag = document.createDocumentFragment(); Node contents = resultSoFar; Node firstP = getNodeByName("p", contents ); // NB, this first p could be one which another Handler inserted; // caveat emptor. Element xhtmlDiv = this.createDiv(document, docfrag, firstP ); return attachContents(docfrag, xhtmlDiv, contents); } catch (Exception e) { throw new TransformerException(e); } }
/** * for XSLFOExporterNonXSLT * @since 3.0 */ public static DocumentFragment createXslFoImgE20( AbstractWmlConversionContext context, Object wpInline) { Part sourcePart = context.getCurrentPart(); WordXmlPictureE20 converter = createWordXmlPictureFromE20(context.getWmlPackage(), context.getImageHandler(), wpInline, sourcePart); Document d = converter.createXslFoImageElement(); DocumentFragment docfrag = d.createDocumentFragment(); docfrag.appendChild(d.getDocumentElement()); return docfrag; }
@Override public Node toNode(WordprocessingMLPackage wmlPackage, SdtPr sdtPr, HashMap<String, String> tagMap, NodeIterator childResults) throws TransformerException { try { // Create a DOM builder and parse the fragment Document document = XmlUtils.getNewDocumentBuilder().newDocument(); DocumentFragment docfrag = document.createDocumentFragment(); Node contents = childResults.nextNode(); // We want to copy the direct/adhoc formatting from the first p; // but that's not a w:p anymore; its an HTML p so .. Node firstP = getNodeByName("p", contents ); Element xhtmlDiv = this.createDiv(document, docfrag, firstP ); return attachContents(docfrag, xhtmlDiv, contents); } catch (Exception e) { throw new TransformerException(e); } }
/** Extension function to create an XSL FO <fo:external-graphic> element * from "E2.0 images" * //w:drawing/wp:inline * |//w:drawing/wp:anchor * @param wmlPackage * @param imageDirPath * @param pictureData * @param picSize * @param picLink * @param linkData * @return */ public static DocumentFragment createXslFoImgE20( AbstractWmlConversionContext context, NodeIterator wpInline) { Part sourcePart = context.getCurrentPart(); WordXmlPictureE20 converter = createWordXmlPictureFromE20(context.getWmlPackage(), context.getImageHandler(), wpInline, sourcePart); Document d = converter.createXslFoImageElement(); DocumentFragment docfrag = d.createDocumentFragment(); docfrag.appendChild(d.getDocumentElement()); return docfrag; }