Search in sources :

Example 6 with CDATASection

use of org.w3c.dom.CDATASection in project zm-mailbox by Zimbra.

the class W3cDomUtil method toHierarchy.

private static Element toHierarchy(Node node, ElementFactory factory) {
    Element elt = factory.createElement(dom4jQNameForNode(node));
    makeAttributes(elt, node);
    StringBuilder content = new StringBuilder();
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        switch(child.getNodeType()) {
            case Node.ELEMENT_NODE:
                elt.addElement(nodeToElement(child, factory));
                break;
            case Node.TEXT_NODE:
                content.append(child.getNodeValue());
                break;
            case Node.CDATA_SECTION_NODE:
                CDATASection cdata = (CDATASection) child;
                content.append(cdata.getData());
                break;
        }
    }
    String textContent = content.toString();
    if (!textContent.trim().equals("")) {
        elt.setText(textContent);
    }
    return elt;
}
Also used : CDATASection(org.w3c.dom.CDATASection) Node(org.w3c.dom.Node)

Example 7 with CDATASection

use of org.w3c.dom.CDATASection in project intellij-community by JetBrains.

the class IntentionDump method main.

@Override
public void main(String[] args) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element intentions = document.createElement("Intentions");
        document.appendChild(intentions);
        while (((IntentionManagerImpl) IntentionManager.getInstance()).hasActiveRequests()) {
            TimeoutUtil.sleep(100);
        }
        for (IntentionActionMetaData actionMetaData : IntentionManagerSettings.getInstance().getMetaData()) {
            Element intention = document.createElement("Intention");
            intention.setAttribute("categories", StringUtil.join(actionMetaData.myCategory, ","));
            intention.setAttribute("name", actionMetaData.getFamily());
            Element description = document.createElement("description");
            CDATASection descriptionSection = document.createCDATASection(escapeCDATA(actionMetaData.getDescription().getText()));
            description.appendChild(descriptionSection);
            intention.appendChild(description);
            TextDescriptor[] beforeDescriptors = actionMetaData.getExampleUsagesBefore();
            if (beforeDescriptors.length > 0) {
                Element before = document.createElement("before");
                CDATASection beforeSection = document.createCDATASection(escapeCDATA(beforeDescriptors[0].getText()));
                before.appendChild(beforeSection);
                intention.appendChild(before);
            }
            TextDescriptor[] afterDescriptors = actionMetaData.getExampleUsagesAfter();
            if (afterDescriptors.length > 0) {
                Element after = document.createElement("after");
                CDATASection afterSection = document.createCDATASection(escapeCDATA(afterDescriptors[0].getText()));
                after.appendChild(afterSection);
                intention.appendChild(after);
            }
            intentions.appendChild(intention);
        }
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(document);
        final String path = args.length == 2 ? args[1] : PathManager.getHomePath() + File.separator + "AllIntentions.xml";
        StreamResult console = new StreamResult(new File(path));
        transformer.transform(source, console);
        System.exit(0);
    } catch (ParserConfigurationException | IOException | TransformerException e) {
        // noinspection CallToPrintStackTrace
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) TextDescriptor(com.intellij.codeInsight.intention.impl.config.TextDescriptor) IOException(java.io.IOException) Document(org.w3c.dom.Document) IntentionManagerImpl(com.intellij.codeInsight.intention.impl.config.IntentionManagerImpl) CDATASection(org.w3c.dom.CDATASection) DocumentBuilder(javax.xml.parsers.DocumentBuilder) IntentionActionMetaData(com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 8 with CDATASection

use of org.w3c.dom.CDATASection in project webservices-axiom by apache.

the class TestCreateCDATASection method runTest.

protected void runTest() throws Throwable {
    Document document = dbf.newDocumentBuilder().newDocument();
    CDATASection cdataSection = document.createCDATASection("content");
    assertEquals("content", cdataSection.getData());
    assertSame(document, cdataSection.getOwnerDocument());
}
Also used : CDATASection(org.w3c.dom.CDATASection) Document(org.w3c.dom.Document)

Example 9 with CDATASection

use of org.w3c.dom.CDATASection in project webservices-axiom by apache.

the class TestCreateOMTextCDATASectionWithParent method runTest.

@Override
protected void runTest() throws Throwable {
    OMFactory factory = metaFactory.getOMFactory();
    OMElement parent = factory.createOMElement("test", null);
    OMText text = factory.createOMText(parent, "cdata section content", OMNode.CDATA_SECTION_NODE);
    assertTrue(text instanceof CDATASection);
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) CDATASection(org.w3c.dom.CDATASection) OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement)

Example 10 with CDATASection

use of org.w3c.dom.CDATASection in project camel by apache.

the class DocumentationEnricher method addDocumentation.

private void addDocumentation(Element item, String textContent) {
    Element annotation = document.createElement(Constants.XS_ANNOTATION_ELEMENT_NAME);
    Element documentation = document.createElement(Constants.XS_DOCUMENTATION_ELEMENT_NAME);
    documentation.setAttribute("xml:lang", "en");
    CDATASection cdataDocumentationText = document.createCDATASection(formatTextContent(item, textContent));
    documentation.appendChild(cdataDocumentationText);
    annotation.appendChild(documentation);
    if (item.getFirstChild() != null) {
        item.insertBefore(annotation, item.getFirstChild());
    } else {
        item.appendChild(annotation);
    }
}
Also used : CDATASection(org.w3c.dom.CDATASection) Element(org.w3c.dom.Element)

Aggregations

CDATASection (org.w3c.dom.CDATASection)16 Element (org.w3c.dom.Element)6 Document (org.w3c.dom.Document)5 Node (org.w3c.dom.Node)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 File (java.io.File)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Transformer (javax.xml.transform.Transformer)2 TransformerException (javax.xml.transform.TransformerException)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamResult (javax.xml.transform.stream.StreamResult)2 OMText (org.apache.axiom.om.OMText)2 DocumentType (org.w3c.dom.DocumentType)2 NodeList (org.w3c.dom.NodeList)2 Text (org.w3c.dom.Text)2 IntentionActionMetaData (com.intellij.codeInsight.intention.impl.config.IntentionActionMetaData)1 IntentionManagerImpl (com.intellij.codeInsight.intention.impl.config.IntentionManagerImpl)1 TextDescriptor (com.intellij.codeInsight.intention.impl.config.TextDescriptor)1 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1