use of org.w3c.dom.CDATASection in project abstools by abstools.
the class DiagramLoader method saveDiagram.
/**
* Saves a diagram specification (and a configuration), using a stream.
*
* @param source
* the source text of the diagram
* @param configuration
* a configuration of the diagram, or null if it is to be saved
* without a configuration (as plain text)
* @param stream
* the stream to use for saving the diagram source and
* configuration
* @param encoding
* the encoding to be used
*
* @throws IOException
* @throws XMLException
*/
public static void saveDiagram(String source, Bean<Configuration> configuration, OutputStream stream, String encoding) throws IOException, XMLException {
if (configuration != null) {
Document document = DocUtil.newDocument();
Element root = document.createElement("diagram");
document.appendChild(root);
BeanConverter converter = new BeanConverter(configuration, document);
Element sourceElem = document.createElement("source");
CDATASection sourceNode = document.createCDATASection(source);
sourceElem.appendChild(sourceNode);
root.appendChild(sourceElem);
Element configurationNode = converter.createElement("configuration");
root.appendChild(configurationNode);
DocUtil.writeDocument(document, encoding, stream);
} else {
OutputStreamWriter osw = new OutputStreamWriter(stream, encoding);
PrintWriter pw = new PrintWriter(osw);
pw.print(source);
pw.flush();
}
}
use of org.w3c.dom.CDATASection in project webtools.sourceediting by eclipse.
the class CDATASectionTest4 method testModel.
public void testModel() {
IDOMModel model = createHTMLModel();
assertNotNull(model);
IDOMDocument document = model.getDocument();
assertNotNull(document);
Element html = document.createElement("html");
html.setAttribute("xmlns:jsp", "http://java.sun.com/JSP/Page");
Element head = document.createElement("head");
Element script = document.createElement("script");
script.setAttribute("type", "text/javascript");
CDATASection cdataSection = document.createCDATASection("test");
try {
document.appendChild(html);
html.appendChild(head);
head.appendChild(script);
script.appendChild(cdataSection);
} catch (Exception e) {
fail("Did not permit CDATA section in script element.");
}
}
use of org.w3c.dom.CDATASection in project liferay-ide by liferay.
the class WorkflowNodeMetadataResource method saveMetadata.
public void saveMetadata() {
XmlResource xmlResource = parent().adapt(XmlResource.class);
XmlElement xmlElement = xmlResource.getXmlElement();
XmlElement metadataElement = xmlElement.getChildElement("metadata", true);
Element domElement = metadataElement.getDomNode();
try {
Document document = domElement.getOwnerDocument();
CDATASection cdata = document.createCDATASection(this._metadata.toJSONString());
CoreUtil.removeChildren(domElement);
domElement.insertBefore(cdata, null);
} catch (JSONException jsone) {
KaleoCore.logError(jsone);
}
}
use of org.w3c.dom.CDATASection in project ant by apache.
the class DOMUtils method appendCDATA.
/**
* Adds a nested CDATA section.
*
* <p>This means
* <pre>appendCDATA(<a>, "b")</pre>
* creates
* <pre>
* <a><[!CDATA[b]]></a>
* </pre>
*
* @param parent element that will receive the new element as child.
* @param content text content.
*
* @since Ant 1.6.3
*/
public static void appendCDATA(Element parent, String content) {
Document doc = parent.getOwnerDocument();
CDATASection c = doc.createCDATASection(content);
parent.appendChild(c);
}
use of org.w3c.dom.CDATASection in project abstools by abstools.
the class BeanConverter method convertProperty.
private Element convertProperty(PropertyDescriptor property) {
Element elem = document.createElement("property");
elem.setAttribute("name", property.getName());
Object value = bean.getValue(property.getName());
if (value instanceof String) {
CDATASection cdata = document.createCDATASection((String) value);
elem.appendChild(cdata);
} else if (value instanceof Integer) {
elem.setAttribute("value", value.toString());
} else if (value instanceof Boolean) {
elem.setAttribute("value", value.toString());
} else if (value instanceof Font) {
Font font = (Font) value;
elem.setAttribute("family", font.getFamily());
elem.setAttribute("style", String.valueOf(font.getStyle()));
elem.setAttribute("size", String.valueOf(font.getSize()));
} else if (value instanceof File) {
elem.setAttribute("value", ((File) value).getAbsolutePath());
} else if (value instanceof Color) {
elem.setAttribute("value", "" + ((Color) value).getRGB());
} else {
throw new IllegalArgumentException("unknown property type: " + value.getClass().getName());
}
return elem;
}
Aggregations