本文整理汇总了Java中org.w3c.dom.CDATASection类的典型用法代码示例。如果您正苦于以下问题:Java CDATASection类的具体用法?Java CDATASection怎么用?Java CDATASection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CDATASection类属于org.w3c.dom包,在下文中一共展示了CDATASection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCDATA
import org.w3c.dom.CDATASection; //导入依赖的package包/类
public void testCDATA() throws Exception {
Document doc = XMLUtil.createDocument("root", null, null, null);
Element e = doc.createElement("sometag");
doc.getDocumentElement().appendChild(e);
String cdataContent = "!&<>*\n[[]]";
CDATASection cdata = doc.createCDATASection(cdataContent);
e.appendChild(cdata);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLUtil.write(doc, baos, "UTF-8");
String data = baos.toString("UTF-8").replace("\r\n", "\n");
assertTrue("Can't find CDATA section", data.indexOf("<![CDATA[" + cdataContent + "]]>") != -1);
// parse the data back to DOM
Document doc2 = XMLUtil.parse(new InputSource(new ByteArrayInputStream(baos.toByteArray())), false, false, null, null);
NodeList nl = doc2.getElementsByTagName("sometag");
assertEquals("Wrong number of <sometag/> elements", 1, nl.getLength());
nl = nl.item(0).getChildNodes();
assertEquals("Wrong number of <sometag/> child elements", 1, nl.getLength());
Node child = nl.item(0);
assertTrue("Expecting CDATASection node", child instanceof CDATASection);
assertEquals("Wrong CDATASection content", cdataContent, ((CDATASection) child).getNodeValue());
}
示例2: collectCDATASections
import org.w3c.dom.CDATASection; //导入依赖的package包/类
private static void collectCDATASections(Node node, Set<String> cdataQNames) {
if (node instanceof CDATASection) {
Node parent = node.getParentNode();
if (parent != null) {
String uri = parent.getNamespaceURI();
if (uri != null) {
cdataQNames.add("{" + uri + "}" + parent.getNodeName()); //NOI18N
} else {
cdataQNames.add(parent.getNodeName());
}
}
}
NodeList children = node.getChildNodes();
for(int i = 0; i < children.getLength(); i++) {
collectCDATASections(children.item(i), cdataQNames);
}
}
示例3: write
import org.w3c.dom.CDATASection; //导入依赖的package包/类
/**
* Write.
*
* @param node
* the node
*/
protected void write(CDATASection node) {
printWriter.print("<![CDATA["); //$NON-NLS-1$
String data = node.getNodeValue();
// XML parsers normalize line endings to '\n'. We should write
// it out as it was in the original to avoid whitespace commits
// on some version control systems
int len = (data != null) ? data.length() : 0;
for (int i = 0; i < len; i++) {
char c = data.charAt(i);
if (c == '\n') {
printWriter.print(System.getProperty("line.separator")); //$NON-NLS-1$
} else {
printWriter.print(c);
}
}
printWriter.print("]]>"); //$NON-NLS-1$
printWriter.flush();
}
示例4: toXml
import org.w3c.dom.CDATASection; //导入依赖的package包/类
@Override
public Element toXml(Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the transaction WSDL type
try {
Element wsdlTypeElement = document.createElement("wsdltype");
if (wsdlType != null) {
CDATASection cDATASection = document.createCDATASection(wsdlType);
wsdlTypeElement.appendChild(cDATASection);
element.appendChild(wsdlTypeElement);
}
} catch (NullPointerException e) {
// Silently ignore
}
return element;
}
示例5: toXml
import org.w3c.dom.CDATASection; //导入依赖的package包/类
@Override
public Element toXml(Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the sequence WSDL type
try {
Element wsdlTypeElement = document.createElement("wsdltype");
if (wsdlType != null) {
CDATASection cDATASection = document.createCDATASection(wsdlType);
wsdlTypeElement.appendChild(cDATASection);
element.appendChild(wsdlTypeElement);
}
}
catch(NullPointerException e) {
// Silently ignore
}
return element;
}
示例6: createStepNodeValue
import org.w3c.dom.CDATASection; //导入依赖的package包/类
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
stepNode.setAttribute("key", key.isEmpty() ? "empty_key":StringUtils.normalize(key));
if (!key.isEmpty()) {
Object object = value.getObject(this);
if (object != null) {
if ((object instanceof NodeList) && value.isUseSource()) {
OutputFilter outputFilter = sequence.new OutputFilter(OutputOption.UsefullOnly);
object = Sequence.ouputDomView((NodeList) object,outputFilter);
}
getSequence().context.httpSession.setAttribute(key, object);
// Simple objects
if ((object instanceof Boolean) || (object instanceof Integer) || (object instanceof Double)
|| (object instanceof Float) || (object instanceof Character) || (object instanceof Long)
|| (object instanceof Short) || (object instanceof Byte) || (object instanceof String)) {
stepNode.setTextContent(ParameterUtils.toString(object));
}
// Complex objects
else {
CDATASection cDATASection = doc.createCDATASection(ParameterUtils.toString(object));
stepNode.appendChild(cDATASection);
}
}
}
}
示例7: toXml
import org.w3c.dom.CDATASection; //导入依赖的package包/类
@Override
public Element toXml(Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the transaction "default" flag
element.setAttribute("default", new Boolean(isDefault).toString());
// Storing the transaction handlers
try {
Element handlersElement = document.createElement("handlers");
if (handlers != null) {
CDATASection cDATASection = document.createCDATASection(handlers);
handlersElement.appendChild(cDATASection);
element.appendChild(handlersElement);
}
}
catch(NullPointerException e) {
// Silently ignore
}
return element;
}
示例8: toXml
import org.w3c.dom.CDATASection; //导入依赖的package包/类
@Override
public Element toXml(org.w3c.dom.Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the docdata
try {
Element dataElement = document.createElement("docdata");
if (docdata != null) {
CDATASection cDATASection = document.createCDATASection(docdata);
dataElement.appendChild(cDATASection);
element.appendChild(dataElement);
}
}
catch(NullPointerException e) {
// Silently ignore
}
return element;
}
示例9: toXml
import org.w3c.dom.CDATASection; //导入依赖的package包/类
@Override
public Element toXml(Document document) throws EngineException {
Element element = super.toXml(document);
// Storing the transaction WSDL type
try {
Element wsdlTypeElement = document.createElement("wsdltype");
if (wsdlType != null) {
CDATASection cDATASection = document.createCDATASection(wsdlType);
wsdlTypeElement.appendChild(cDATASection);
element.appendChild(wsdlTypeElement);
}
} catch(NullPointerException e) {
// Silently ignore
}
return element;
}
示例10: isCDATASectionWellFormed
import org.w3c.dom.CDATASection; //导入依赖的package包/类
/**
* Checks if an CDATASection node is well-formed, by checking it's data
* for well-formedness. Note that the presence of a CDATA termination mark
* in the contents of a CDATASection is handled by the parameter
* spli-cdata-sections
*
* @param data The contents of the comment node
*/
protected void isCDATASectionWellFormed(CDATASection node) {
// Does the data valid XML character data
Character invalidChar = isWFXMLChar(node.getData());
//if (!isWFXMLChar(node.getData(), invalidChar)) {
if (invalidChar != null) {
String msg =
Utils.messages.createMessage(
MsgKey.ER_WF_INVALID_CHARACTER_IN_CDATA,
new Object[] { Integer.toHexString(Character.getNumericValue(invalidChar.charValue())) });
if (fErrorHandler != null) {
fErrorHandler.handleError(
new DOMErrorImpl(
DOMError.SEVERITY_FATAL_ERROR,
msg,
MsgKey.ER_WF_INVALID_CHARACTER,
null,
null,
null));
}
}
}
示例11: moveToChild
import org.w3c.dom.CDATASection; //导入依赖的package包/类
protected int moveToChild(final int currentChild) {
content = getCurrentElement().getChildNodes().item(currentChild);
if (content instanceof Text) {
return CHARACTERS;
} else if (content instanceof Element) {
return START_ELEMENT;
} else if (content instanceof CDATASection) {
return CDATA;
} else if (content instanceof Comment) {
return CHARACTERS;
} else if (content instanceof EntityReference) {
return ENTITY_REFERENCE;
}
throw new IllegalStateException();
}
示例12: getTextValue
import org.w3c.dom.CDATASection; //导入依赖的package包/类
private String getTextValue(Node node) {
if (node == null)
return null;
StringBuffer b = new StringBuffer();
if (node.getNodeType() == Node.TEXT_NODE) {
return ((Text) node).getData();
} else if (node.getNodeType() == Node.CDATA_SECTION_NODE) {
return ((CDATASection) node).getData();
} else {
Node child = node.getFirstChild();
while (child != null) {
b.append(getTextValue(child));
child = child.getNextSibling();
}
}
return b.toString();
}
示例13: appendNode
import org.w3c.dom.CDATASection; //导入依赖的package包/类
public static void appendNode(Node node, StringBuffer buf) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
appendElement((Element) node, buf);
break;
case Node.TEXT_NODE:
appendText((Text) node, buf);
break;
case Node.CDATA_SECTION_NODE:
appendCDATASection((CDATASection) node, buf);
break;
case Node.ENTITY_REFERENCE_NODE:
appendEntityReference((EntityReference) node, buf);
break;
}
}
示例14: replaceTextWithCData
import org.w3c.dom.CDATASection; //导入依赖的package包/类
/**
* Replace all text values of a {@link Node} with CDATA values.
*
* @param doc
* the document to update
*
* @param node
* the node to update
*/
public static void replaceTextWithCData( Document doc, Node node )
{
if (node instanceof Text)
{
Text text = (Text) node;
CDATASection cdata = doc.createCDATASection( text.getTextContent() );
Element parent = (Element) text.getParentNode();
parent.replaceChild( cdata, text );
}
else if (node instanceof Element)
{
//LOGGER.debug( "ELEMENT " + element.getTagName() );
NodeList children = node.getChildNodes();
for (int i=0; i<children.getLength(); i++)
{
//LOGGER.debug( "> " + children.item( i ).getClass().getName() );
XmlUtils.replaceTextWithCData( doc, children.item( i ) );
}
}
}
示例15: visitNode
import org.w3c.dom.CDATASection; //导入依赖的package包/类
static <R> R visitNode(Node node, NodeVisitor<R> visitor) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE: return visitor.visitElement((Element) node);
case Node.ATTRIBUTE_NODE: return visitor.visitAttr((Attr) node);
case Node.TEXT_NODE: return visitor.visitText((Text) node);
case Node.CDATA_SECTION_NODE: return visitor.visitCDATASection((CDATASection) node);
case Node.ENTITY_REFERENCE_NODE: return visitor.visitEntityReference((EntityReference) node);
case Node.ENTITY_NODE: return visitor.visitEntity((Entity) node);
case Node.PROCESSING_INSTRUCTION_NODE:
return visitor.visitProcessingInstruction((ProcessingInstruction) node);
case Node.COMMENT_NODE: return visitor.visitComment((Comment) node);
case Node.DOCUMENT_NODE: return visitor.visitDocument((Document) node);
case Node.DOCUMENT_TYPE_NODE: return visitor.visitDocumentType((DocumentType) node);
case Node.DOCUMENT_FRAGMENT_NODE:
return visitor.visitDocumentFragment((DocumentFragment) node);
case Node.NOTATION_NODE: return visitor.visitNotation((Notation) node);
default: throw new RuntimeException();
}
}