List of usage examples for org.w3c.dom Document createCDATASection
public CDATASection createCDATASection(String data) throws DOMException;
CDATASection
node whose value is the specified string. From source file:main.java.vasolsim.common.GenericUtils.java
/** * Creates a cdata node within a created element and then attaches the date to a parent. * * @param elementName the name for the new element * @param nodeData the data for the new text node * @param parentElement the parent element * @param doc the document (root) *///from ww w. j av a 2 s .c o m public static void appendCDATASubNode(String elementName, String nodeData, Element parentElement, Document doc) { Element subElement = doc.createElement(elementName); subElement.appendChild(doc.createCDATASection(nodeData)); parentElement.appendChild(subElement); }
From source file:de.betterform.xml.xforms.model.constraints.RelevanceSelector.java
private static void addChildren(Element relevantElement, Node instanceNode) { Document ownerDocument = relevantElement.getOwnerDocument(); NodeList instanceChildren = instanceNode.getChildNodes(); for (int index = 0; index < instanceChildren.getLength(); index++) { Node instanceChild = (Node) instanceChildren.item(index); if (isEnabled(instanceChild)) { switch (instanceChild.getNodeType()) { case Node.TEXT_NODE: /* rather not, otherwise we cannot follow specs when * serializing to multipart/form-data for example */*from w w w . jav a2 s. co m*/ // denormalize text for better whitespace handling during serialization List list = DOMWhitespace.denormalizeText(instanceChild.getNodeValue()); for (int item = 0; item < list.size(); item++) { relevantElement.appendChild(ownerDocument.createTextNode(list.get(item).toString())); } */ relevantElement.appendChild(ownerDocument.createTextNode(instanceChild.getNodeValue())); break; case Node.CDATA_SECTION_NODE: relevantElement.appendChild(ownerDocument.createCDATASection(instanceChild.getNodeValue())); break; case Node.ELEMENT_NODE: addElement(relevantElement, instanceChild); break; default: // ignore break; } } } }
From source file:com.adaptris.core.services.jdbc.XmlPayloadTranslatorImpl.java
protected Node createTextNode(Document doc, String value, boolean isCDATA) { String munged = stripIllegalXmlChars() ? XmlHelper.stripIllegalXmlCharacters(value) : value; if (isCDATA) { return doc.createCDATASection(munged); }/*from w w w . j ava2 s . co m*/ return doc.createTextNode(munged); }
From source file:com.enonic.esl.xml.XMLTool.java
/** * Create a CDATA section in a XML DOM./*from ww w. j a v a 2 s. c o m*/ * * @param doc The owner document. * @param root The element the CDATA should be created below. * @param cdata The CDATA content. * @return CDATASection */ public static CDATASection createCDATASection(Document doc, Element root, String cdata) { CDATASection cdataSection; if (cdata != null) { cdataSection = doc.createCDATASection(StringUtil.replaceECC(cdata)); root.appendChild(cdataSection); } else { cdataSection = doc.createCDATASection(""); root.appendChild(cdataSection); } return cdataSection; }
From source file:com.twinsoft.convertigo.engine.util.XMLUtils.java
public static String getCDataText(String s) { String cdataText = ""; try {/*from w ww . j av a 2 s .c o m*/ if (!s.equals("")) { Document dom = createDom("java"); Element root = dom.createElement("root"); CDATASection cDATASection = dom.createCDATASection(s); root.appendChild(cDATASection); dom.appendChild(root); cdataText = prettyPrintElement(root, true, true); cdataText = cdataText.replaceAll("<root>", ""); cdataText = cdataText.replaceAll("</root>", ""); String cdataStart = "<![CDATA["; if (cdataText.startsWith(cdataStart)) { int i = cdataText.substring(cdataStart.length()).indexOf(cdataStart); if (i < 0) { cdataText = cdataText.replaceAll("<!\\[CDATA\\[", ""); cdataText = cdataText.replaceAll("\\]\\]>", ""); } } } } catch (ParserConfigurationException e) { } return cdataText; }
From source file:it.greenvulcano.gvesb.virtual.http.HTTPCallOperation.java
private void dumpPart(Part p, Element msg, Document doc) throws Exception { Element content = null;// w w w. j a v a2 s .c om if (p.isMimeType("text/plain")) { content = doc.createElement("PlainMessage"); Text body = doc.createTextNode((String) p.getContent()); content.appendChild(body); } else if (p.isMimeType("text/html")) { content = doc.createElement("HTMLMessage"); CDATASection body = doc.createCDATASection((String) p.getContent()); content.appendChild(body); } else if (p.isMimeType("multipart/*")) { Multipart mp = (Multipart) p.getContent(); int count = mp.getCount(); content = doc.createElement("Multipart"); for (int i = 0; i < count; i++) { dumpPart(mp.getBodyPart(i), content, doc); } } else if (p.isMimeType("message/rfc822")) { content = doc.createElement("NestedMessage"); dumpPart((Part) p.getContent(), content, doc); } else { content = doc.createElement("EncodedContent"); DataHandler dh = p.getDataHandler(); OutputStream os = new ByteArrayOutputStream(); Base64EncodingOutputStream b64os = new Base64EncodingOutputStream(os); dh.writeTo(b64os); b64os.flush(); b64os.close(); content.appendChild(doc.createTextNode(os.toString())); } msg.appendChild(content); String filename = p.getFileName(); if (filename != null) { content.setAttribute("file-name", filename); } String ct = p.getContentType(); if (ct != null) { content.setAttribute("content-type", ct); } String desc = p.getDescription(); if (desc != null) { content.setAttribute("description", desc); } }
From source file:com.twinsoft.convertigo.beans.steps.SequenceStep.java
@Override public Element toXml(Document document) throws EngineException { Element element = super.toXml(document); // Storing the sequence WSDL type try {// w w w . j a va 2s . c o m Element wsdlTypeElement = document.createElement("wsdltype"); if (wsdlType != null) { CDATASection cDATASection = document.createCDATASection(wsdlType); wsdlTypeElement.appendChild(cDATASection); element.appendChild(wsdlTypeElement); } } catch (NullPointerException e) { // Silently ignore } return element; }
From source file:com.fiorano.openesb.application.aps.ApplicationContext.java
/** * Returns the xml string equivalent of this object. * * @param document the input Document object * @return element node/*from www. j a va2 s . c o m*/ * @exception FioranoException if an error occurs while creating the element * node. * @since Tifosi2.0 */ Node toJXMLString(Document document) throws FioranoException { Node root0 = document.createElement("ApplicationContext"); Node node; if (!StringUtils.isEmpty(m_structure)) { Element elem = document.createElement("Structure"); CDATASection cdata = document.createCDATASection(m_structure); elem.appendChild(cdata); root0.appendChild(elem); } if (!StringUtils.isEmpty(m_defaultInstance)) { node = XMLDmiUtil.getNodeObject("DefaultInstance", m_defaultInstance, document); if (node != null) root0.appendChild(node); } if (!StringUtils.isEmpty(m_rootElement)) { node = XMLDmiUtil.getNodeObject("RootElement", m_rootElement, document); if (node != null) root0.appendChild(node); } if (!StringUtils.isEmpty(m_rootElementNamespace)) { node = XMLDmiUtil.getNodeObject("RootElementNamespace", m_rootElementNamespace, document); if (node != null) root0.appendChild(node); } node = XMLDmiUtil.getNodeObject("StructureType", String.valueOf(m_structureType), document); if (node != null) root0.appendChild(node); return root0; }
From source file:ambit.data.qmrf.QMRFAttachment.java
public Element toXML(Document document) throws XMLException { Element element = document.createElement(getName()); element.setAttribute(attribute_filetype, filetype); element.setAttribute(attribute_description, description); element.setAttribute(attribute_url, url); if (getEmbedded()) { try {//from w w w . j a v a 2 s . c o m if (content == null) { content = retrieveContent(); } System.out.println("encoding"); byte[] encoded = Base64.encodeBase64(content.toString().getBytes(UTF8charset)); CDATASection cdata = document.createCDATASection(new String(encoded, UTF8charset)); if (cdata != null) element.appendChild(cdata); } catch (Exception x) { x.printStackTrace(); setEmbedded(false); } } else setEmbedded(false); if (getEmbedded()) element.setAttribute(attribute_embedded, Answer.YES.toString()); else element.setAttribute(attribute_embedded, Answer.NO.toString()); return element; }
From source file:com.twinsoft.convertigo.beans.steps.TransactionStep.java
@Override public Element toXml(Document document) throws EngineException { Element element = super.toXml(document); // Storing the transaction WSDL type try {/*w w w. ja va 2 s.co m*/ Element wsdlTypeElement = document.createElement("wsdltype"); if (wsdlType != null) { CDATASection cDATASection = document.createCDATASection(wsdlType); wsdlTypeElement.appendChild(cDATASection); element.appendChild(wsdlTypeElement); } } catch (NullPointerException e) { // Silently ignore } return element; }