📄 namespacenode.java
字号:
/*
* $Header: /cvsroot/ozone/ozone/modules/xml/dom4j/src/org/jaxen/dom/NamespaceNode.java,v 1.1 2003/11/02 18:33:52 per_nyfelt Exp $
* $Revision: 1.1 $
* $Date: 2003/11/02 18:33:52 $
*
* ====================================================================
*
* Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions, and the disclaimer that follows
* these conditions in the documentation and/or other materials
* provided with the distribution.
*
* 3. The name "Jaxen" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact license@jaxen.org.
*
* 4. Products derived from this software may not be called "Jaxen", nor
* may "Jaxen" appear in their name, without prior written permission
* from the Jaxen Project Management (pm@jaxen.org).
*
* In addition, we request (but do not require) that you include in the
* end-user documentation provided with the redistribution and/or in the
* software itself an acknowledgement equivalent to the following:
* "This product includes software developed by the
* Jaxen Project (http://www.jaxen.org/)."
* Alternatively, the acknowledgment may be graphical using the logos
* available at http://www.jaxen.org/
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* ====================================================================
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jaxen Project and was originally
* created by bob mcwhirter <bob@werken.com> and
* James Strachan <jstrachan@apache.org>. For more information on the
* Jaxen Project, please see <http://www.jaxen.org/>.
*
* $Id: NamespaceNode.java,v 1.1 2003/11/02 18:33:52 per_nyfelt Exp $
*/
////////////////////////////////////////////////////////////////////
// Inner class for a Namespace node.
////////////////////////////////////////////////////////////////////
package org.jaxen.dom;
import org.jaxen.pattern.Pattern;
import org.w3c.dom.*;
/**
* Extension DOM2 node type for a Namespace Declaration.
*
* <p>This class implements the DOM2 {@link Node} interface to
* allow Namespace declarations to be included in the result
* set of an XPath selectNodes operation, even though DOM2 does
* not model Namespace declarations as separate nodes.</p>
*
* <p>While all of the methods are implemented with reasonable
* defaults, there will be some unexpected surprises, so users are
* advised to test for NamespaceNodes and filter them out from the
* result sets as early as possible:</p>
*
* <ol>
*
* <li>The {@link #getNodeType} method returns {@link #NAMESPACE_NODE},
* which is not one of the usual DOM2 node types. Generic code may
* fall unexpectedly out of switch statements, for example.</li>
*
* <li>The {@link #getOwnerDocument} method returns the owner document
* of the parent node, but that owner document will know nothing about
* the Namespace node.</p>
*
* <li>The {@link #isSupported} method always returns false.</li>
*
* </ol>
*
* <p>All attempts to modify a NamespaceNode will fail with a {@link
* DOMException} ({@link
* DOMException#NO_MODIFICATION_ALLOWED_ERR}).</p>
*
* <p>This class has only protected constructors, so that it can be
* instantiated only by {@link DocumentNavigator}.</p>
*
* @author David Megginson
* @see DocumentNavigator
*/
public class NamespaceNode implements Node {
////////////////////////////////////////////////////////////////////
// Constants.
////////////////////////////////////////////////////////////////////
/**
* Constant: this is a NamespaceNode.
*
* @see #getNodeType
*/
public final static short NAMESPACE_NODE = Pattern.NAMESPACE_NODE;
////////////////////////////////////////////////////////////////////
// Protected Constructors.
////////////////////////////////////////////////////////////////////
/**
* Constructor.
*
* @param parent The DOM node to which the Namespace is attached.
* @param uri The Namespace URI as a string.
*/
public NamespaceNode(Node parent, String name, String value) {
this.parent = parent;
this.name = name;
this.value = value;
}
/**
* Constructor.
*
* @param parent The DOM node to which the Namespace is attached.
* @param attribute The DOM attribute object containing the
* Namespace declaration.
*/
NamespaceNode(Node parent, Node attribute) {
String name = attribute.getNodeName();
if (name.equals("xmlns"))
this.name = "";
else
this.name = name.substring(6); // the part after "xmlns:"
this.parent = parent;
this.value = attribute.getNodeValue();
}
////////////////////////////////////////////////////////////////////
// Implementation of org.w3c.dom.Node.
////////////////////////////////////////////////////////////////////
/**
* Get the Namespace prefix.
*
* @return The Namespace prefix, or "" for the default Namespace.
*/
public String getNodeName() {
return name;
}
/**
* Get the Namespace URI.
*
* @return The Namespace URI.
*/
public String getNodeValue() {
return value;
}
/**
* Change the Namespace URI (always fails).
*
* @param value The new URI.
* @exception DOMException always thrown.
*/
public void setNodeValue(String value)
throws DOMException {
no_mods();
}
/**
* Get the node type.
*
* @return Always {@link #NAMESPACE_NODE}.
*/
public short getNodeType() {
return NAMESPACE_NODE;
}
/**
* Get the parent node.
*
* <p>This method returns the element that was queried for Namespaces
* in effect, <em>not</em> necessarily the actual element containing
* the Namespace declaration.</p>
*
* @return The parent node (not null).
*/
public Node getParentNode() {
return parent;
}
/**
* Get the list of child nodes.
*
* @return An empty node list.
*/
public NodeList getChildNodes() {
return new EmptyNodeList();
}
/**
* Get the first child node.
*
* @return Always null.
*/
public Node getFirstChild() {
return null;
}
/**
* Get the last child node.
*
* @return Always null.
*/
public Node getLastChild() {
return null;
}
/**
* Get the previous sibling node.
*
* @return Always null.
*/
public Node getPreviousSibling() {
return null;
}
/**
* Get the next sibling node.
*
* @return Always null.
*/
public Node getNextSibling() {
return null;
}
/**
* Get the attribute nodes.
*
* @return Always null.
*/
public NamedNodeMap getAttributes() {
return null;
}
/**
* Get the owner document.
*
* @return The owner document <em>of the parent node</em>.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -