本文整理汇总了Java中mf.org.w3c.dom.Node.CDATA_SECTION_NODE属性的典型用法代码示例。如果您正苦于以下问题:Java Node.CDATA_SECTION_NODE属性的具体用法?Java Node.CDATA_SECTION_NODE怎么用?Java Node.CDATA_SECTION_NODE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类mf.org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.CDATA_SECTION_NODE属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasTextOnlyChildren
/**
* Check if an EntityReference node has Text Only child nodes
*
* @param node
* @return true - Contains text only children
*/
private boolean hasTextOnlyChildren(Node node) {
Node child = node;
if (child == null) {
return false;
}
child = child.getFirstChild();
while (child != null) {
int type = child.getNodeType();
if (type == Node.ENTITY_REFERENCE_NODE) {
return hasTextOnlyChildren(child);
}
else if (type != Node.TEXT_NODE
&& type != Node.CDATA_SECTION_NODE
&& type != Node.ENTITY_REFERENCE_NODE) {
return false;
}
child = child.getNextSibling();
}
return true;
}
示例2: getChildText
/**
* Returns the concatenated child text of the specified node.
* This method only looks at the immediate children of type
* <code>Node.TEXT_NODE</code> or the children of any child
* node that is of type <code>Node.CDATA_SECTION_NODE</code>
* for the concatenation.
*
* @param node The node to look at.
*/
public static String getChildText(Node node) {
// is there anything to do?
if (node == null) {
return null;
}
// concatenate children text
StringBuffer str = new StringBuffer();
Node child = node.getFirstChild();
while (child != null) {
short type = child.getNodeType();
if (type == Node.TEXT_NODE) {
str.append(child.getNodeValue());
}
else if (type == Node.CDATA_SECTION_NODE) {
str.append(getChildText(child));
}
child = child.getNextSibling();
}
// return text value
return str.toString();
}
示例3: getWholeTextForward
/**
* Concatenates the text of all logically-adjacent text nodes to the
* right of this node
* @param node
* @param buffer
* @param parent
* @return true - if execution was stopped because the type of node
* other than EntityRef, Text, CDATA is encountered, otherwise
* return false
*/
private boolean getWholeTextForward(Node node, StringBuffer buffer, Node parent){
// boolean to indicate whether node is a child of an entity reference
boolean inEntRef = false;
if (parent!=null) {
inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
}
while (node != null) {
short type = node.getNodeType();
if (type == Node.ENTITY_REFERENCE_NODE) {
if (getWholeTextForward(node.getFirstChild(), buffer, node)){
return true;
}
}
else if (type == Node.TEXT_NODE ||
type == Node.CDATA_SECTION_NODE) {
((NodeImpl)node).getTextContent(buffer);
}
else {
return true;
}
node = node.getNextSibling();
}
// if the parent node is an entity reference node, must
// check nodes to the right of the parent entity reference node for logically adjacent
// text nodes
if (inEntRef) {
getWholeTextForward(parent.getNextSibling(), buffer, parent.getParentNode());
return true;
}
return false;
}
示例4: getWholeTextBackward
/**
* Concatenates the text of all logically-adjacent text nodes to the left of
* the node
* @param node
* @param buffer
* @param parent
* @return true - if execution was stopped because the type of node
* other than EntityRef, Text, CDATA is encountered, otherwise
* return false
*/
private boolean getWholeTextBackward(Node node, StringBuffer buffer, Node parent){
// boolean to indicate whether node is a child of an entity reference
boolean inEntRef = false;
if (parent!=null) {
inEntRef = parent.getNodeType()==Node.ENTITY_REFERENCE_NODE;
}
while (node != null) {
short type = node.getNodeType();
if (type == Node.ENTITY_REFERENCE_NODE) {
if (getWholeTextBackward(node.getLastChild(), buffer, node)){
return true;
}
}
else if (type == Node.TEXT_NODE ||
type == Node.CDATA_SECTION_NODE) {
((TextImpl)node).insertTextContent(buffer);
}
else {
return true;
}
node = node.getPreviousSibling();
}
// if the parent node is an entity reference node, must
// check nodes to the left of the parent entity reference node for logically adjacent
// text nodes
if (inEntRef) {
getWholeTextBackward(parent.getPreviousSibling(), buffer, parent.getParentNode());
return true;
}
return false;
}
示例5: checkIndex
void checkIndex(Node refNode, int offset) throws DOMException
{
if (offset < 0) {
throw new DOMException(
DOMException.INDEX_SIZE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
}
int type = refNode.getNodeType();
// If the node contains text, ensure that the
// offset of the range is <= to the length of the text
if (type == Node.TEXT_NODE
|| type == Node.CDATA_SECTION_NODE
|| type == Node.COMMENT_NODE
|| type == Node.PROCESSING_INSTRUCTION_NODE) {
if (offset > refNode.getNodeValue().length()) {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
}
}
else {
// Since the node is not text, ensure that the offset
// is valid with respect to the number of child nodes
if (offset > refNode.getChildNodes().getLength()) {
throw new DOMException(DOMException.INDEX_SIZE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null));
}
}
}
示例6: toString
public String toString(){
if( fDetach) {
throw new DOMException(
DOMException.INVALID_STATE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null));
}
Node node = fStartContainer;
Node stopNode = fEndContainer;
StringBuffer sb = new StringBuffer();
if (fStartContainer.getNodeType() == Node.TEXT_NODE
|| fStartContainer.getNodeType() == Node.CDATA_SECTION_NODE
) {
if (fStartContainer == fEndContainer) {
sb.append(fStartContainer.getNodeValue().substring(fStartOffset, fEndOffset));
return sb.toString();
}
sb.append(fStartContainer.getNodeValue().substring(fStartOffset));
node=nextNode (node,true); //fEndContainer!=fStartContainer
}
else { //fStartContainer is not a TextNode
node=node.getFirstChild();
if (fStartOffset>0) { //find a first node within a range, specified by fStartOffset
int counter=0;
while (counter<fStartOffset && node!=null) {
node=node.getNextSibling();
counter++;
}
}
if (node == null) {
node = nextNode(fStartContainer,false);
}
}
if ( fEndContainer.getNodeType()!= Node.TEXT_NODE &&
fEndContainer.getNodeType()!= Node.CDATA_SECTION_NODE ){
int i=fEndOffset;
stopNode = fEndContainer.getFirstChild();
while( i>0 && stopNode!=null ){
--i;
stopNode = stopNode.getNextSibling();
}
if ( stopNode == null )
stopNode = nextNode( fEndContainer, false );
}
while (node != stopNode) { //look into all kids of the Range
if (node == null) break;
if (node.getNodeType() == Node.TEXT_NODE
|| node.getNodeType() == Node.CDATA_SECTION_NODE) {
sb.append(node.getNodeValue());
}
node = nextNode(node, true);
}
if (fEndContainer.getNodeType() == Node.TEXT_NODE
|| fEndContainer.getNodeType() == Node.CDATA_SECTION_NODE) {
sb.append(fEndContainer.getNodeValue().substring(0,fEndOffset));
}
return sb.toString();
}
示例7: beginNode
/** Do processing for the start of a node. */
private void beginNode(Node node) {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
fCurrentElement = node;
// push namespace context
fNamespaceContext.pushContext();
// start element
fillQName(fElementQName, node);
processAttributes(node.getAttributes());
fSchemaValidator.startElement(fElementQName, fAttributes, null);
break;
case Node.TEXT_NODE:
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.setIgnoringCharacters(true);
sendCharactersToValidator(node.getNodeValue());
fDOMValidatorHandler.setIgnoringCharacters(false);
fDOMValidatorHandler.characters((Text) node);
}
else {
sendCharactersToValidator(node.getNodeValue());
}
break;
case Node.CDATA_SECTION_NODE:
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.setIgnoringCharacters(true);
fSchemaValidator.startCDATA(null);
sendCharactersToValidator(node.getNodeValue());
fSchemaValidator.endCDATA(null);
fDOMValidatorHandler.setIgnoringCharacters(false);
fDOMValidatorHandler.cdata((CDATASection) node);
}
else {
fSchemaValidator.startCDATA(null);
sendCharactersToValidator(node.getNodeValue());
fSchemaValidator.endCDATA(null);
}
break;
case Node.PROCESSING_INSTRUCTION_NODE:
/**
* The validator does nothing with processing instructions so bypass it.
* Send the ProcessingInstruction node directly to the result builder.
*/
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.processingInstruction((ProcessingInstruction) node);
}
break;
case Node.COMMENT_NODE:
/**
* The validator does nothing with comments so bypass it.
* Send the Comment node directly to the result builder.
*/
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.comment((Comment) node);
}
break;
case Node.DOCUMENT_TYPE_NODE:
/**
* Send the DocumentType node directly to the result builder.
*/
if (fDOMValidatorHandler != null) {
fDOMValidatorHandler.doctypeDecl((DocumentType) node);
}
break;
default: // Ignore other node types.
break;
}
}
示例8: traverseNode
/**
* Utility method for traversing a single node.
* Does not properly handle a text node containing both the
* start and end offsets. Such nodes should
* have been previously detected and been routed to traverseCharacterDataNode.
*
* @param n The node to be traversed.
*
* @param isFullySelected
* Set to true if the node is fully selected. Should be
* false otherwise.
* Note that although the DOM 2 specification says that a
* text node that is boththe start and end container is not
* selected, we treat it here as if it were partially
* selected.
*
* @param isLeft Is true if we are traversing the node as part of navigating
* the "left boundary" of the range. If this value is false,
* it implies we are navigating the "right boundary" of the
* range.
*
* @param how Specifies what type of traversal is being
* requested (extract, clone, or delete).
* Legal values for this argument are:
*
* <ol>
* <li><code>EXTRACT_CONTENTS</code> - will simply
* return the original node.
*
* <li><code>CLONE_CONTENTS</code> - will leave the
* context tree of the range undisturbed, but will
* return a cloned node.
*
* <li><code>DELETE_CONTENTS</code> - will delete the
* node from it's parent, but will return null.
* </ol>
*
* @return Returns a node that is the result of visiting the node.
* If the traversal operation is
* <code>DELETE_CONTENTS</code> the return value is null.
*/
private Node traverseNode( Node n, boolean isFullySelected, boolean isLeft, int how )
{
if ( isFullySelected ) {
return traverseFullySelected( n, how );
}
final short nodeType = n.getNodeType();
if (nodeType == Node.TEXT_NODE ||
nodeType == Node.CDATA_SECTION_NODE ||
nodeType == Node.COMMENT_NODE ||
nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
return traverseCharacterDataNode( n, isLeft, how );
}
return traversePartiallySelected( n, how );
}
示例9: getNodeType
/**
* A short integer indicating what type of node this is. The named
* constants for this value are defined in the org.w3c.dom.Node interface.
*/
public short getNodeType() {
return Node.CDATA_SECTION_NODE;
}