本文整理匯總了Java中org.w3c.dom.Node.ENTITY_REFERENCE_NODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Node.ENTITY_REFERENCE_NODE屬性的具體用法?Java Node.ENTITY_REFERENCE_NODE怎麽用?Java Node.ENTITY_REFERENCE_NODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.ENTITY_REFERENCE_NODE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNextElementSibling
/**
* @see <a
* href="http://www.w3.org/TR/2008/REC-ElementTraversal-20081222/#attribute-nextElementSibling">
* Element Traversal Specification</a>
*/
@Override
public final Element getNextElementSibling() {
Node n = getNextLogicalSibling(this);
while (n != null) {
switch (n.getNodeType()) {
case Node.ELEMENT_NODE:
return (Element) n;
case Node.ENTITY_REFERENCE_NODE:
final Element e = getFirstElementChild(n);
if (e != null) {
return e;
}
break;
}
n = getNextLogicalSibling(n);
}
return null;
}
示例2: visit
private void visit( Node n ) throws SAXException {
setCurrentLocation( n );
// if a case statement gets too big, it should be made into a separate method.
switch(n.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
String value = n.getNodeValue();
receiver.characters( value.toCharArray(), 0, value.length() );
break;
case Node.ELEMENT_NODE:
visit( (Element)n );
break;
case Node.ENTITY_REFERENCE_NODE:
receiver.skippedEntity(n.getNodeName());
break;
case Node.PROCESSING_INSTRUCTION_NODE:
ProcessingInstruction pi = (ProcessingInstruction)n;
receiver.processingInstruction(pi.getTarget(),pi.getData());
break;
}
}
示例3: getPreviousLogicalSibling
private Node getPreviousLogicalSibling(Node n) {
Node prev = n.getPreviousSibling();
// If "n" has no previous sibling and its parent is an entity reference node we
// need to continue the search through the previous siblings of the entity
// reference as these are logically siblings of the given node.
if (prev == null) {
Node parent = n.getParentNode();
while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
prev = parent.getPreviousSibling();
if (prev != null) {
break;
}
parent = parent.getParentNode();
}
}
return prev;
}
示例4: setReadOnly
/**
* Override default behavior so that if deep is true, children are also
* toggled.
* @see Node
* <P>
* Note: this will not change the state of an EntityReference or its
* children, which are always read-only.
*/
public void setReadOnly(boolean readOnly, boolean deep) {
super.setReadOnly(readOnly, deep);
if (deep) {
if (needsSyncChildren()) {
synchronizeChildren();
}
// Recursively set kids
for (ChildNode mykid = firstChild;
mykid != null;
mykid = mykid.nextSibling) {
if (mykid.getNodeType() != Node.ENTITY_REFERENCE_NODE) {
mykid.setReadOnly(readOnly,true);
}
}
}
}
示例5: setReadOnly
/**
* Override default behavior so that if deep is true, children are also
* toggled.
* @see Node
* <P>
* Note: this will not change the state of an EntityReference or its
* children, which are always read-only.
*/
public void setReadOnly(boolean readOnly, boolean deep) {
super.setReadOnly(readOnly, deep);
if (deep) {
if (needsSyncChildren()) {
synchronizeChildren();
}
if (hasStringValue()) {
return;
}
// Recursively set kids
for (ChildNode mykid = (ChildNode) value;
mykid != null;
mykid = mykid.nextSibling) {
if (mykid.getNodeType() != Node.ENTITY_REFERENCE_NODE) {
mykid.setReadOnly(readOnly,true);
}
}
}
}
示例6: getLastChild
/** Internal function.
* Return the last child Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
Node getLastChild(Node node) {
if (node == null) return null;
if ( !fEntityReferenceExpansion
&& node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
return null;
Node newNode = node.getLastChild();
if (newNode == null) return null;
int accept = acceptNode(newNode);
if (accept == NodeFilter.FILTER_ACCEPT)
return newNode;
else
if (accept == NodeFilter.FILTER_SKIP
&& newNode.hasChildNodes())
{
Node lChild = getLastChild(newNode);
if (lChild == null) {
return getPreviousSibling(newNode, node);
}
return lChild;
}
else
//if (accept == NodeFilter.REJECT_NODE)
{
return getPreviousSibling(newNode, node);
}
}
示例7: getTextContent
private static String getTextContent(Node node)
{
short nodeType = node.getNodeType();
if( nodeType == Node.ATTRIBUTE_NODE ||
nodeType == Node.PROCESSING_INSTRUCTION_NODE ||
nodeType == Node.COMMENT_NODE ||
nodeType == Node.TEXT_NODE ||
nodeType == Node.CDATA_SECTION_NODE )
{
return com.altova.CoreTypes.castToString(node.getNodeValue());
}
else
if( nodeType == Node.DOCUMENT_NODE ||
nodeType == Node.DOCUMENT_FRAGMENT_NODE ||
nodeType == Node.ELEMENT_NODE ||
nodeType == Node.ENTITY_REFERENCE_NODE )
{
String result = "";
Node child = node.getFirstChild();
for( ; child != null ; child = child.getNextSibling() )
{
short childNodeType = child.getNodeType();
if( childNodeType == Node.TEXT_NODE ||
childNodeType == Node.CDATA_SECTION_NODE ||
childNodeType == Node.ELEMENT_NODE ||
childNodeType == Node.ENTITY_REFERENCE_NODE )
{
result += getTextContent( child );
}
}
return result;
}
else
return "";
}
示例8: print
public void print(Node node) throws XMLStreamException {
switch (node.getNodeType()) {
case Node.DOCUMENT_NODE:
visitDocument((Document) node);
break;
case Node.DOCUMENT_FRAGMENT_NODE:
visitDocumentFragment((DocumentFragment) node);
break;
case Node.ELEMENT_NODE:
visitElement((Element) node);
break;
case Node.TEXT_NODE:
visitText((Text) node);
break;
case Node.CDATA_SECTION_NODE:
visitCDATASection((CDATASection) node);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
visitProcessingInstruction((ProcessingInstruction) node);
break;
case Node.ENTITY_REFERENCE_NODE:
visitReference((EntityReference) node);
break;
case Node.COMMENT_NODE:
visitComment((Comment) node);
break;
case Node.DOCUMENT_TYPE_NODE:
break;
case Node.ATTRIBUTE_NODE:
case Node.ENTITY_NODE:
default:
throw new XMLStreamException("Unexpected DOM Node Type "
+ node.getNodeType()
);
}
}
示例9: getNodeTypeFromCode
private String getNodeTypeFromCode(short code) {
String retval = null;
switch (code) {
case Node.ATTRIBUTE_NODE :
retval = "ATTRIBUTE_NODE"; break;
case Node.CDATA_SECTION_NODE :
retval = "CDATA_SECTION_NODE"; break;
case Node.COMMENT_NODE :
retval = "COMMENT_NODE"; break;
case Node.DOCUMENT_FRAGMENT_NODE :
retval = "DOCUMENT_FRAGMENT_NODE"; break;
case Node.DOCUMENT_NODE :
retval = "DOCUMENT_NODE"; break;
case Node.DOCUMENT_TYPE_NODE :
retval = "DOCUMENT_TYPE_NODE"; break;
case Node.ELEMENT_NODE :
retval = "ELEMENT_NODE"; break;
case Node.ENTITY_NODE :
retval = "ENTITY_NODE"; break;
case Node.ENTITY_REFERENCE_NODE :
retval = "ENTITY_REFERENCE_NODE"; break;
case Node.NOTATION_NODE :
retval = "NOTATION_NODE"; break;
case Node.PROCESSING_INSTRUCTION_NODE :
retval = "PROCESSING_INSTRUCTION_NODE"; break;
case Node.TEXT_NODE:
retval = "TEXT_NODE"; break;
}
return retval;
}
示例10: testEntities001
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the doc contains one entity and one entity
* reference, <br>
* <b>name</b>: entities <br>
* <b>value</b>: true. <br>
* <b>Expected results</b>: the entity and the entity reference are left
* unchanged
*/
@Test
public void testEntities001() {
Document doc = null;
try {
doc = loadDocument(null, test1_xml);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
DOMConfiguration config = doc.getDomConfig();
if (!config.canSetParameter("entities", Boolean.TRUE)) {
Assert.fail("setting 'entities' to true is not supported");
}
Element root = doc.getDocumentElement();
root.appendChild(doc.createEntityReference("x"));
config.setParameter("entities", Boolean.TRUE);
setHandler(doc);
doc.normalizeDocument();
Node child = root.getFirstChild();
if (child == null) {
Assert.fail("root has no child");
}
if (child.getNodeType() != Node.ENTITY_REFERENCE_NODE) {
Assert.fail("root's child is " + child + ", expected entity reference &x;");
}
if (doc.getDoctype() == null) {
Assert.fail("no doctype found");
}
if (doc.getDoctype().getEntities() == null) {
Assert.fail("no entitiy found");
}
if (doc.getDoctype().getEntities().getNamedItem("x") == null) {
Assert.fail("no entitiy with name 'x' found");
}
return; // Status.passed("OK");
}
示例11: getEntityRefValue
/**
* NON-DOM: compute string representation of the entity reference.
* This method is used to retrieve a string value for an attribute node that has child nodes.
* @return String representing a value of this entity ref. or
* null if any node other than EntityReference, Text is encountered
* during computation
*/
protected String getEntityRefValue (){
if (needsSyncChildren()){
synchronizeChildren();
}
String value = "";
if (firstChild != null){
if (firstChild.getNodeType() == Node.ENTITY_REFERENCE_NODE){
value = ((EntityReferenceImpl)firstChild).getEntityRefValue();
}
else if (firstChild.getNodeType() == Node.TEXT_NODE){
value = firstChild.getNodeValue();
}
else {
// invalid to have other types of nodes in attr value
return null;
}
if (firstChild.nextSibling == null){
return value;
}
else {
StringBuffer buff = new StringBuffer(value);
ChildNode next = firstChild.nextSibling;
while (next != null){
if (next.getNodeType() == Node.ENTITY_REFERENCE_NODE){
value = ((EntityReferenceImpl)next).getEntityRefValue();
}
else if (next.getNodeType() == Node.TEXT_NODE){
value = next.getNodeValue();
}
else {
// invalid to have other types of nodes in attr value
return null;
}
buff.append(value);
next = next.nextSibling;
}
return buff.toString();
}
}
return "";
}
示例12: writeAnyNode
/**
* Write any node.
*
* @param node
* the node
* @throws ShellException
* the shell exception
*/
protected void writeAnyNode(Node node) throws ShellException {
// is there anything to do?
if (node == null) {
return;
}
short type = node.getNodeType();
switch (type) {
case Node.DOCUMENT_NODE:
write((Document) node);
break;
case Node.DOCUMENT_TYPE_NODE:
write((DocumentType) node);
break;
case Node.ELEMENT_NODE:
write((Element) node);
break;
case Node.ENTITY_REFERENCE_NODE:
write((EntityReference) node);
break;
case Node.CDATA_SECTION_NODE:
write((CDATASection) node);
break;
case Node.TEXT_NODE:
write((Text) node);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
write((ProcessingInstruction) node);
break;
case Node.COMMENT_NODE:
write((Comment) node);
break;
default:
throw new ShellException(getString(
"RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
}
}
示例13: circumventBug2650internal
/**
* This is the work horse for {@link #circumventBug2650}.
*
* @param node
* @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">
* Namespace axis resolution is not XPath compliant </A>
*/
@SuppressWarnings("fallthrough")
private static void circumventBug2650internal(Node node) {
Node parent = null;
Node sibling = null;
final String namespaceNs = Constants.NamespaceSpecNS;
do {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE :
Element element = (Element) node;
if (!element.hasChildNodes()) {
break;
}
if (element.hasAttributes()) {
NamedNodeMap attributes = element.getAttributes();
int attributesLength = attributes.getLength();
for (Node child = element.getFirstChild(); child!=null;
child = child.getNextSibling()) {
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element childElement = (Element) child;
for (int i = 0; i < attributesLength; i++) {
Attr currentAttr = (Attr) attributes.item(i);
if (!namespaceNs.equals(currentAttr.getNamespaceURI())) {
continue;
}
if (childElement.hasAttributeNS(namespaceNs,
currentAttr.getLocalName())) {
continue;
}
childElement.setAttributeNS(namespaceNs,
currentAttr.getName(),
currentAttr.getNodeValue());
}
}
}
case Node.ENTITY_REFERENCE_NODE :
case Node.DOCUMENT_NODE :
parent = node;
sibling = node.getFirstChild();
break;
}
while ((sibling == null) && (parent != null)) {
sibling = parent.getNextSibling();
parent = parent.getParentNode();
}
if (sibling == null) {
return;
}
node = sibling;
sibling = node.getNextSibling();
} while (true);
}
示例14: getNamespaceForPrefix
/**
* Given an XML Namespace prefix and a context in which the prefix
* is to be evaluated, return the Namespace Name this prefix was
* bound to. Note that DOM Level 3 is expected to provide a version of
* this which deals with the DOM's "early binding" behavior.
*
* Default handling:
*
* @param prefix String containing namespace prefix to be resolved,
* without the ':' which separates it from the localname when used
* in a Node Name. The empty sting signifies the default namespace
* at this point in the document.
* @param namespaceContext Element which provides context for resolution.
* (We could extend this to work for other nodes by first seeking their
* nearest Element ancestor.)
*
* @return a String containing the Namespace URI which this prefix
* represents in the specified context.
*/
public String getNamespaceForPrefix(String prefix, Element namespaceContext)
{
int type;
Node parent = namespaceContext;
String namespace = null;
if (prefix.equals("xml"))
{
namespace = QName.S_XMLNAMESPACEURI; // Hardcoded, per Namespace spec
}
else if(prefix.equals("xmlns"))
{
// Hardcoded in the DOM spec, expected to be adopted by
// Namespace spec. NOTE: Namespace declarations _must_ use
// the xmlns: prefix; other prefixes declared as belonging
// to this namespace will not be recognized and should
// probably be rejected by parsers as erroneous declarations.
namespace = "http://www.w3.org/2000/xmlns/";
}
else
{
// Attribute name for this prefix's declaration
String declname=(prefix=="")
? "xmlns"
: "xmlns:"+prefix;
// Scan until we run out of Elements or have resolved the namespace
while ((null != parent) && (null == namespace)
&& (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
|| (type == Node.ENTITY_REFERENCE_NODE)))
{
if (type == Node.ELEMENT_NODE)
{
// Look for the appropriate Namespace Declaration attribute,
// either "xmlns:prefix" or (if prefix is "") "xmlns".
// TODO: This does not handle "implicit declarations"
// which may be created when the DOM is edited. DOM Level
// 3 will define how those should be interpreted. But
// this issue won't arise in freshly-parsed DOMs.
// NOTE: declname is set earlier, outside the loop.
Attr attr=((Element)parent).getAttributeNode(declname);
if(attr!=null)
{
namespace = attr.getNodeValue();
break;
}
}
parent = getParentOfNode(parent);
}
}
return namespace;
}
示例15: getNamespaceURI
public String getNamespaceURI(String prefix) {
Node parent = e;
String namespace = null;
if (prefix.equals("xml")) {
namespace = WellKnownNamespace.XML_NAMESPACE_URI;
} else {
int type;
while ((null != parent) && (null == namespace)
&& (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
|| (type == Node.ENTITY_REFERENCE_NODE))) {
if (type == Node.ELEMENT_NODE) {
if (parent.getNodeName().indexOf(prefix + ':') == 0)
return parent.getNamespaceURI();
NamedNodeMap nnm = parent.getAttributes();
for (int i = 0; i < nnm.getLength(); i++) {
Node attr = nnm.item(i);
String aname = attr.getNodeName();
boolean isPrefix = aname.startsWith("xmlns:");
if (isPrefix || aname.equals("xmlns")) {
int index = aname.indexOf(':');
String p = isPrefix ? aname.substring(index + 1) : "";
if (p.equals(prefix)) {
namespace = attr.getNodeValue();
break;
}
}
}
}
parent = parent.getParentNode();
}
}
return namespace;
}