Search in sources :

Example 11 with CDATASection

use of org.w3c.dom.CDATASection in project j2objc by google.

the class DOMBuilder method cdata.

/**
   * Receive notification of cdata.
   *
   * <p>The Parser will call this method to report each chunk of
   * character data.  SAX parsers may return all contiguous character
   * data in a single chunk, or they may split it into several
   * chunks; however, all of the characters in any single event
   * must come from the same external entity, so that the Locator
   * provides useful information.</p>
   *
   * <p>The application must not attempt to read from the array
   * outside of the specified range.</p>
   *
   * <p>Note that some parsers will report whitespace using the
   * ignorableWhitespace() method rather than this one (validating
   * parsers must do so).</p>
   *
   * @param ch The characters from the XML document.
   * @param start The start position in the array.
   * @param length The number of characters to read from the array.
   * @see #ignorableWhitespace
   * @see org.xml.sax.Locator
   */
public void cdata(char[] ch, int start, int length) throws org.xml.sax.SAXException {
    if (isOutsideDocElem() && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
        // avoid DOM006 Hierarchy request error
        return;
    String s = new String(ch, start, length);
    CDATASection section = (CDATASection) m_currentNode.getLastChild();
    section.appendData(s);
}
Also used : CDATASection(org.w3c.dom.CDATASection)

Example 12 with CDATASection

use of org.w3c.dom.CDATASection in project robovm by robovm.

the class DOMBuilder method cdata.

/**
   * Receive notification of cdata.
   *
   * <p>The Parser will call this method to report each chunk of
   * character data.  SAX parsers may return all contiguous character
   * data in a single chunk, or they may split it into several
   * chunks; however, all of the characters in any single event
   * must come from the same external entity, so that the Locator
   * provides useful information.</p>
   *
   * <p>The application must not attempt to read from the array
   * outside of the specified range.</p>
   *
   * <p>Note that some parsers will report whitespace using the
   * ignorableWhitespace() method rather than this one (validating
   * parsers must do so).</p>
   *
   * @param ch The characters from the XML document.
   * @param start The start position in the array.
   * @param length The number of characters to read from the array.
   * @see #ignorableWhitespace
   * @see org.xml.sax.Locator
   */
public void cdata(char[] ch, int start, int length) throws org.xml.sax.SAXException {
    if (isOutsideDocElem() && org.apache.xml.utils.XMLCharacterRecognizer.isWhiteSpace(ch, start, length))
        // avoid DOM006 Hierarchy request error
        return;
    String s = new String(ch, start, length);
    CDATASection section = (CDATASection) m_currentNode.getLastChild();
    section.appendData(s);
}
Also used : CDATASection(org.w3c.dom.CDATASection)

Example 13 with CDATASection

use of org.w3c.dom.CDATASection in project robovm by robovm.

the class NormalizeTest method assertChildren.

private void assertChildren(Element element, String... texts) {
    List<String> actual = new ArrayList<String>();
    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.TEXT_NODE) {
            actual.add(((Text) node).getData());
        } else if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
            actual.add("<![CDATA[" + ((CDATASection) node).getData() + "]]>");
        } else {
            actual.add("<" + node.getNodeName() + ">");
        }
    }
    assertEquals(Arrays.asList(texts), actual);
}
Also used : CDATASection(org.w3c.dom.CDATASection) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 14 with CDATASection

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

the class InspectionDump method main.

@Override
public void main(String[] args) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element inspections = document.createElement("Inspections");
        document.appendChild(inspections);
        List<InspectionToolWrapper> tools = InspectionToolRegistrar.getInstance().createTools();
        for (InspectionToolWrapper tool : tools) {
            Element inspection = document.createElement("Inspection");
            inspection.setAttribute("groupPath", StringUtil.join(tool.getGroupPath(), ";"));
            inspection.setAttribute("group", tool.getGroupDisplayName());
            inspection.setAttribute("name", tool.getDisplayName());
            inspection.setAttribute("level", tool.getDefaultLevel().getName());
            if (tool.getLanguage() != null) {
                inspection.setAttribute("language", tool.getLanguage());
            }
            Element description = document.createElement("description");
            CDATASection descriptionSection = document.createCDATASection(escapeCDATA(tool.loadDescription()));
            description.appendChild(descriptionSection);
            inspection.appendChild(description);
            inspections.appendChild(inspection);
        }
        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 + "AllInspections.xml";
        StreamResult console = new StreamResult(new File(path));
        transformer.transform(source, console);
        System.exit(0);
    } catch (ParserConfigurationException | 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) Document(org.w3c.dom.Document) CDATASection(org.w3c.dom.CDATASection) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 15 with CDATASection

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

the class W3cDomUtil method toFlattened.

private static Element toFlattened(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:
                // i.e. add textual representation of the XML
                content.append(W3cDomUtil.asXML(child, false));
                break;
            case Node.TEXT_NODE:
                content.append(child.getNodeValue());
                break;
            case Node.CDATA_SECTION_NODE:
                CDATASection cdata = (CDATASection) child;
                content.append(cdata.getData());
                break;
        }
    }
    return elt.setText(content.toString());
}
Also used : CDATASection(org.w3c.dom.CDATASection) Node(org.w3c.dom.Node)

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