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;
}
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);
}
}
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());
}
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);
}
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);
}
}
Aggregations