Refine search
currentNode.insertBefore(newNode, m_nextSibling); else currentNode.appendChild(newNode); m_docFrag.insertBefore(newNode, m_nextSibling); else m_docFrag.appendChild(newNode); short type = newNode.getNodeType(); if (m_doc.getDocumentElement() != null) m_doc.insertBefore(newNode, m_nextSibling); else m_doc.appendChild(newNode);
Element div = df.getOwnerDocument().createElement("div"); div.setAttribute("style", "position:absolute; left:" + xy.width + "px; top:" + xy.height + "px;"); Node img = df.getFirstChild(); df.removeChild(img); df.appendChild(div); div.appendChild(img);
Document document = XmlUtils.getNewDocumentBuilder().newDocument(); Element headEl = document.createElement("head"); Element meta = document.createElement("meta"); Element element = null; StringBuilder buffer = new StringBuilder(10240); document.appendChild(headEl); meta.setAttribute("http-equiv", "Content-Type"); meta.setAttribute("content", "text/html; charset=utf-8"); headEl.appendChild(meta); DocumentFragment docfrag = document.createDocumentFragment(); docfrag.appendChild(document.getDocumentElement());
Document document = XmlUtils.getNewDocumentBuilder().newDocument(); Node xhtmlP = document.createElement("p"); document.appendChild(xhtmlP); Tree<AugmentedStyle> pTree = styleTree.getParagraphStylesTree(); org.docx4j.model.styles.Node<AugmentedStyle> asn = pTree.get(pStyleVal); ((Element)xhtmlP).setAttribute("class", StyleTree.getHtmlClassAttributeValue(pTree, asn) ); ((Element)xhtmlP).setAttribute("style", inlineStyle.toString() ); if (n.getNodeType()==Node.DOCUMENT_NODE) { log.debug("handling DOCUMENT_NODE"); NodeList nodes = n.getChildNodes(); if (nodes != null) { for (int i=0; i<nodes.getLength(); i++) { if (((Node)nodes.item(i)).getLocalName().equals("span") && ! ((Node)nodes.item(i)).hasChildNodes() ) { DocumentFragment docfrag = document.createDocumentFragment(); docfrag.appendChild(document.getDocumentElement());
Document document = XmlUtils.getNewDocumentBuilder().newDocument(); Element xhtmlBlock = document.createElement(htmlElementName); document.appendChild(xhtmlBlock); org.docx4j.model.styles.Node<AugmentedStyle> asn = pTree.get(pStyleVal); String classVal = StyleTree.getHtmlClassAttributeValue(pTree, asn); xhtmlBlock.setAttribute("class", classVal); xhtmlBlock.getNodeName().equals("li")); if (!inlineStyle.toString().equals("") ) { xhtmlBlock.setAttribute("style", inlineStyle.toString() ); if (xhtmlBlock.getNodeName().equals("p") && n.hasChildNodes() && n.getChildNodes().item(0).getLocalName().equals("span")) { Text t = document.createTextNode("\u00A0"); //= =   xhtmlBlock.appendChild(t); DocumentFragment docfrag = document.createDocumentFragment(); docfrag.appendChild(document.getDocumentElement());
/** * 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 Element setRichText(String richText) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(new EntityResolverImpl()); org.w3c.dom.Document doc = db.parse(new InputSource(new StringReader(Strings.concat(XML_DECL, XML_DOCTYPE, XML_ROOT_START, richText, XML_ROOT_END)))); Node richTextNode = ownerDoc.getDocument().importNode(doc.getDocumentElement(), true); DocumentFragment richTextFragment = ownerDoc.getDocument().createDocumentFragment(); while (richTextNode.hasChildNodes()) { richTextFragment.appendChild(richTextNode.removeChild(richTextNode.getFirstChild())); } removeChildren(); node.appendChild(richTextFragment); } catch (ParserConfigurationException e) { throw new BugError(e); } catch (SAXException e) { throw new DomException("Invalid fragment source."); } catch (IOException e) { throw new BugError(e); } return this; }
@Test public void testHtmlTag() throws Exception { Document doc = documentProvider.createDocument(null, null, null); // Create a mock tag; the name doesn't truly matter Element tag = doc.createElement("test"); tag.setAttribute("code", "${code}"); processor.expressionResults = ImmutableMap.of( "${code}", "Hello <b>World</b>!"); DocumentFragment fragment = doc.createDocumentFragment(); handler.process(fragment, tag, processor); assertEquals(3, fragment.getChildNodes().getLength()); assertEquals("b", fragment.getChildNodes().item(1).getNodeName()); } }
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; }
private Element createDiv(Document document, DocumentFragment docfrag, Node n) throws ParserConfigurationException, IOException, SAXException, JAXBException { // log.debug("Node is: " + n.getNodeName() ); Element xhtmlDiv = document.createElement("div"); xhtmlDiv.setAttribute("style", ((Element)n).getAttribute("style") ); docfrag.appendChild(xhtmlDiv); return xhtmlDiv; }
Text theChar = doc.createTextNode( new String(hexStringToByteArray(value) ) ); DocumentFragment docfrag = doc.createDocumentFragment(); docfrag.appendChild( theChar ); Element span = doc.createElement("span"); docfrag.appendChild(span); span.setAttribute("style", "font-family: '" + pf.getName() + "'" ); span.appendChild( theChar );
Document tmpDoc = XmlUtils.marshaltoW3CDomDocument(run); DocumentFragment docfrag = tmpDoc.createDocumentFragment(); org.w3c.dom.Element wtr = tmpDoc.createElementNS(Namespaces.NS_WORD12, "tr"); docfrag.appendChild(wtr); org.w3c.dom.Element wtc = tmpDoc.createElementNS(Namespaces.NS_WORD12, "tc"); wtr.appendChild(wtc); org.w3c.dom.Element wp = tmpDoc.createElementNS(Namespaces.NS_WORD12, "p"); wtc.appendChild(wp); wp.appendChild(tmpDoc.getDocumentElement()); return docfrag; org.w3c.dom.Element wtc = tmpDoc.createElementNS(Namespaces.NS_WORD12, "tc"); docfrag.appendChild(wtc); org.w3c.dom.Element wp = tmpDoc.createElementNS(Namespaces.NS_WORD12, "p"); org.w3c.dom.Element wp = tmpDoc.createElementNS(Namespaces.NS_WORD12, "p"); docfrag.appendChild(wp); wp.appendChild(tmpDoc.getDocumentElement());
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; }
d=makeErr( "[null node?!]" ); } else { log.debug("Handling " + n.getNodeName()); if (n.getNodeName().equals("p:cxnSp") ) { log.info("** TODO " + n.getNodeName() ); d=makeErr( "[" + n.getNodeName() + "]" ); docfrag = d.createDocumentFragment(); docfrag.appendChild(d.getDocumentElement()); return docfrag;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.parse("sample1.xml"); DocumentFragment frag1 = doc.createDocumentFragment(); Element param = (Element)doc.getElementsByTagName("param5").item(0); while (param.hasChildNodes()) { frag1.appendChild(param.getFirstChild()); }
String rootTagname; doc = (Document) load("hc_staff", true); docElem = doc.getDocumentElement(); rootNS = docElem.getNamespaceURI(); rootTagname = docElem.getTagName(); docAlt = (Document) load("hc_staff", true); docFrag = doc.createDocumentFragment(); elem = doc.createElementNS(rootNS, rootTagname); elemAlt = docAlt.createElementNS(rootNS, rootTagname); appendedChild = docFrag.appendChild(elem); inserted = docFrag.insertBefore(elemAlt, elem); } catch (DOMException ex) { success = (ex.code == DOMException.WRONG_DOCUMENT_ERR);
Node appendedChild; doc = (Document) load("hc_staff", true); docFrag = doc.createDocumentFragment(); elem = doc.createElementNS("http://www.w3.org/1999/xhtml", "body"); pi = doc.createProcessingInstruction("PITarget", "PIData"); comment = doc.createComment("Comment"); txt = doc.createTextNode("Text"); cdata = doc.createCDATASection("CDATA"); eRef = doc.createEntityReference("alpha"); appendedChild = docFrag.appendChild(elem); appendedChild = docFrag.appendChild(pi); appendedChild = docFrag.appendChild(comment); appendedChild = docFrag.appendChild(txt); appendedChild = docFrag.appendChild(cdata); appendedChild = docFrag.appendChild(eRef); inserted = docFrag.insertBefore(comment, pi); inserted = docFrag.insertBefore(txt, comment); inserted = docFrag.insertBefore(cdata, txt); inserted = docFrag.insertBefore(eRef, cdata); insertedVal = inserted.getNodeName(); assertEquals("nodeinsertbefore11_Ent1", "alpha", insertedVal);
/** * The function is to judge if the pushed content type march the type of content being pushed/replaced * @param targetClassAttribute the class attribute of target element which is being pushed * @param content pushedContent * @return boolean: if type match, return true, else return false */ private boolean isPushedTypeMatch(final DitaClass targetClassAttribute, final DocumentFragment content) { DitaClass clazz = null; if (content.hasChildNodes()) { final NodeList nodeList = content.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { final Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { final Element elem = (Element) node; clazz = new DitaClass(elem.getAttribute(ATTRIBUTE_NAME_CLASS)); break; // get type of the target element } } } return targetClassAttribute.matches(clazz); }
try { Document document = XmlUtils.getNewDocumentBuilder().newDocument(); DocumentFragment docfrag = document.createDocumentFragment(); Element xhtmlDiv = document.createElement("ol"); docfrag.appendChild(xhtmlDiv); return attachContents(docfrag, xhtmlDiv, resultSoFar); Element xhtmlDiv = document.createElement("ul"); docfrag.appendChild(xhtmlDiv); return attachContents(docfrag, xhtmlDiv, resultSoFar);
private Node appendNewChild(XMLStreamReader reader, boolean wrapped, Document contextDocument, XMLStreamWriter writer, Element element) throws XMLStreamException { StaxUtils.copy(reader, writer); DocumentFragment result = contextDocument.createDocumentFragment(); Node child = element.getFirstChild(); if (wrapped) { child = child.getFirstChild(); } if (child != null && child.getNextSibling() == null) { return child; } while (child != null) { Node nextChild = child.getNextSibling(); result.appendChild(child); child = nextChild; } return result; }