Search in sources :

Example 26 with CDATASection

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();
    }
}
Also used : CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element) OutputStreamWriter(java.io.OutputStreamWriter) Document(org.w3c.dom.Document) BeanConverter(net.sf.sdedit.ui.components.configuration.BeanConverter) PrintWriter(java.io.PrintWriter)

Example 27 with CDATASection

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.");
    }
}
Also used : CDATASection(org.w3c.dom.CDATASection) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 28 with CDATASection

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);
    }
}
Also used : XmlResource(org.eclipse.sapphire.modeling.xml.XmlResource) CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) JSONException(org.json.JSONException) Document(org.w3c.dom.Document)

Example 29 with CDATASection

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(&lt;a&gt;, "b")</pre>
 * creates
 * <pre>
 * &lt;a&gt;&lt;[!CDATA[b]]&gt;&lt;/a&gt;
 * </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);
}
Also used : CDATASection(org.w3c.dom.CDATASection) Document(org.w3c.dom.Document)

Example 30 with CDATASection

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;
}
Also used : CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element) Color(java.awt.Color) File(java.io.File) Font(java.awt.Font)

Aggregations

CDATASection (org.w3c.dom.CDATASection)38 Element (org.w3c.dom.Element)19 Node (org.w3c.dom.Node)15 Document (org.w3c.dom.Document)14 NodeList (org.w3c.dom.NodeList)9 Text (org.w3c.dom.Text)9 Comment (org.w3c.dom.Comment)6 File (java.io.File)4 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 Transformer (javax.xml.transform.Transformer)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamResult (javax.xml.transform.stream.StreamResult)2