本文整理匯總了Java中org.w3c.dom.Node.getNamespaceURI方法的典型用法代碼示例。如果您正苦於以下問題:Java Node.getNamespaceURI方法的具體用法?Java Node.getNamespaceURI怎麽用?Java Node.getNamespaceURI使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.getNamespaceURI方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFirstChildElementNS
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Finds and returns the first child node with the given qualified name. */
public static Element getFirstChildElementNS(Node parent,
String uri, String localpart) {
// search for node
Node child = parent.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childURI = child.getNamespaceURI();
if (childURI != null && childURI.equals(uri) &&
child.getLocalName().equals(localpart)) {
return (Element)child;
}
}
child = child.getNextSibling();
}
// not found
return null;
}
示例2: decorateIfRequired
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static BeanDefinitionHolder decorateIfRequired(Node node, BeanDefinitionHolder originalDef,
ParserContext parserContext) {
String namespaceUri = node.getNamespaceURI();
if (!parserContext.getDelegate().isDefaultNamespace(namespaceUri) && !isRFC124Namespace(namespaceUri)) {
NamespaceHandler handler =
parserContext.getReaderContext().getNamespaceHandlerResolver().resolve(namespaceUri);
if (handler != null) {
return handler.decorate(node, originalDef, new ParserContext(parserContext.getReaderContext(),
parserContext.getDelegate()));
} else if (namespaceUri.startsWith("http://www.springframework.org/")) {
parserContext.getReaderContext().error(
"Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]",
node);
} else {
// A custom namespace, not to be handled by Spring - maybe "xml:...".
}
}
return originalDef;
}
示例3: getLastChildElementNS
import org.w3c.dom.Node; //導入方法依賴的package包/類
/** Finds and returns the last child node with the given qualified name. */
public static Element getLastChildElementNS(Node parent,
String uri, String localpart) {
// search for node
Node child = parent.getLastChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childURI = child.getNamespaceURI();
if (childURI != null && childURI.equals(uri) &&
child.getLocalName().equals(localpart)) {
return (Element)child;
}
}
child = child.getPreviousSibling();
}
// not found
return null;
}
示例4: parseProjectFiles
import org.w3c.dom.Node; //導入方法依賴的package包/類
private String[] parseProjectFiles(Node projectFilesNode) {
ArrayList<String> paths = new ArrayList<String>();
if (projectFilesNode != null) {
String nsUri = projectFilesNode.getNamespaceURI();
for(Node child = projectFilesNode.getFirstChild();
child != null;
child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE &&
nsUri.equals(child.getNamespaceURI()) &&
RepoConstants.NODE_PATH.equals(child.getLocalName())) {
String path = child.getTextContent();
if (path != null) {
path = path.trim();
if (path.length() > 0) {
paths.add(path);
}
}
}
}
}
return paths.toArray(new String[paths.size()]);
}
示例5: if
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
*
* @param listVector
* @param tempNode
* @param namespaceURI
* @param localname
* @param isNamespaceURIWildCard
* @param isLocalNameWildCard
*
* Private method to be used for recursive iterations to obtain elements by tag name
* and namespaceURI.
*/
private final void traverseChildren
(
Vector listVector,
Node tempNode,
String namespaceURI,
String localname,
boolean isNamespaceURIWildCard,
boolean isLocalNameWildCard)
{
if (tempNode == null)
{
return;
}
else
{
if (tempNode.getNodeType() == DTM.ELEMENT_NODE
&& (isLocalNameWildCard
|| tempNode.getLocalName().equals(localname)))
{
String nsURI = tempNode.getNamespaceURI();
if ((namespaceURI == null && nsURI == null)
|| isNamespaceURIWildCard
|| (namespaceURI != null && namespaceURI.equals(nsURI)))
{
listVector.add(tempNode);
}
}
if(tempNode.hasChildNodes())
{
NodeList nl = tempNode.getChildNodes();
for(int i = 0; i < nl.getLength(); i++)
{
traverseChildren(listVector, nl.item(i), namespaceURI, localname,
isNamespaceURIWildCard, isLocalNameWildCard);
}
}
}
}
示例6: getIndex
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Look up the index of an attribute by Namespace name.
*
* @param uri The Namespace URI, or the empty string if
* the name has no Namespace URI.
* @param localPart The attribute's local name.
* @return The index of the attribute, or -1 if it does not
* appear in the list.
*/
public int getIndex(String uri, String localPart)
{
for(int i=m_attrs.getLength()-1;i>=0;--i)
{
Node a=m_attrs.item(i);
String u=a.getNamespaceURI();
if( (u==null ? uri==null : u.equals(uri))
&&
a.getLocalName().equals(localPart) )
return i;
}
return -1;
}
示例7: spreadNamespaces
import org.w3c.dom.Node; //導入方法依賴的package包/類
public static void spreadNamespaces(Node node, String tns, boolean overwrite) {
Document doc = node instanceof Document ? (Document) node : node.getOwnerDocument();
boolean isParent = false;
while (node != null) {
Node next = null;
if (!isParent && node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNamespaceURI() == null) {
node = doc.renameNode(node, tns, node.getNodeName());
} else {
if (overwrite) {
tns = node.getNamespaceURI();
}
}
NamedNodeMap nodeMap = node.getAttributes();
int nodeMapLengthl = nodeMap.getLength();
for (int i = 0; i < nodeMapLengthl; i++) {
Node attr = nodeMap.item(i);
if (attr.getNamespaceURI() == null) {
doc.renameNode(attr, tns, attr.getNodeName());
}
}
}
isParent = (isParent || (next = node.getFirstChild()) == null) && (next = node.getNextSibling()) == null;
node = isParent ? node.getParentNode() : next;
if (isParent && node != null) {
if (overwrite) {
tns = node.getNamespaceURI();
}
}
}
}
示例8: selectNode
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* @param sibling
* @param uri
* @param nodeName
* @param number
* @return nodes with the constrain
*/
public static Element selectNode(Node sibling, String uri, String nodeName, int number) {
while (sibling != null) {
if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
&& sibling.getLocalName().equals(nodeName)) {
if (number == 0){
return (Element)sibling;
}
number--;
}
sibling = sibling.getNextSibling();
}
return null;
}
示例9: getIndex
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Look up the index of an attribute by Namespace name.
*
* @param uri The Namespace URI, or the empty string if
* the name has no Namespace URI.
* @param localPart The attribute's local name.
* @return The index of the attribute, or -1 if it does not
* appear in the list.
*/
public int getIndex(String uri, String localPart)
{
for(int i=m_attrs.getLength()-1;i>=0;--i)
{
Node a=m_attrs.item(i);
String u=a.getNamespaceURI();
if( (u==null ? uri==null : u.equals(uri))
&&
a.getLocalName().equals(localPart) )
return i;
}
return -1;
}
示例10: lookupNamespaceURI
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Looks up the namespace URI associated with the given prefix starting at the given element. This method differs
* from the {@link Node#lookupNamespaceURI(java.lang.String)} in that it only those namespaces declared by an xmlns
* attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
* call like {@link Document#createElementNS(java.lang.String, java.lang.String)} even if the resulting element
* doesn't have an namespace delcaration attribute.
*
* @param startingElement the starting element
* @param stopingElement the ancestor of the starting element that serves as the upper-bound, inclusive, for the
* search
* @param prefix the prefix to look up
*
* @return the namespace URI for the given prefer or null
*/
public static String lookupNamespaceURI(Element startingElement, Element stopingElement, String prefix) {
String namespaceURI;
// This code is a modified version of the lookup code within Xerces
if (startingElement.hasAttributes()) {
NamedNodeMap map = startingElement.getAttributes();
int length = map.getLength();
for (int i = 0; i < length; i++) {
Node attr = map.item(i);
String attrPrefix = attr.getPrefix();
String value = attr.getNodeValue();
namespaceURI = attr.getNamespaceURI();
if (namespaceURI != null && namespaceURI.equals(XMLConstants.XMLNS_NS)) {
// at this point we are dealing with DOM Level 2 nodes only
if (prefix == null && attr.getNodeName().equals(XMLConstants.XMLNS_PREFIX)) {
// default namespace
return value;
} else if (attrPrefix != null && attrPrefix.equals(XMLConstants.XMLNS_PREFIX)
&& attr.getLocalName().equals(prefix)) {
// non default namespace
return value;
}
}
}
}
if (startingElement != stopingElement) {
Element ancestor = getElementAncestor(startingElement);
if (ancestor != null) {
return lookupNamespaceURI(ancestor, stopingElement, prefix);
}
}
return null;
}
示例11: lookupPrefix
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Looks up the namespace prefix associated with the given URI starting at the given element. This method differs
* from the {@link Node#lookupPrefix(java.lang.String)} in that it only those namespaces declared by an xmlns
* attribute are inspected. The Node method also checks the namespace a particular node was created in by way of a
* call like {@link Document#createElementNS(java.lang.String, java.lang.String)} even if the resulting element
* doesn't have an namespace delcaration attribute.
*
* @param startingElement the starting element
* @param stopingElement the ancestor of the starting element that serves as the upper-bound, inclusive, for the
* search
* @param namespaceURI the uri to look up
*
* @return the prefix for the given namespace URI
*/
public static String lookupPrefix(Element startingElement, Element stopingElement, String namespaceURI) {
String namespace;
// This code is a modified version of the lookup code within Xerces
if (startingElement.hasAttributes()) {
NamedNodeMap map = startingElement.getAttributes();
int length = map.getLength();
for (int i = 0; i < length; i++) {
Node attr = map.item(i);
String attrPrefix = attr.getPrefix();
String value = attr.getNodeValue();
namespace = attr.getNamespaceURI();
if (namespace != null && namespace.equals(XMLConstants.XMLNS_NS)) {
// DOM Level 2 nodes
if (attr.getNodeName().equals(XMLConstants.XMLNS_PREFIX)
|| (attrPrefix != null && attrPrefix.equals(XMLConstants.XMLNS_PREFIX))
&& value.equals(namespaceURI)) {
String localname = attr.getLocalName();
String foundNamespace = startingElement.lookupNamespaceURI(localname);
if (foundNamespace != null && foundNamespace.equals(namespaceURI)) {
return localname;
}
}
}
}
}
if (startingElement != stopingElement) {
Element ancestor = getElementAncestor(startingElement);
if (ancestor != null) {
return lookupPrefix(ancestor, stopingElement, namespaceURI);
}
}
return null;
}
示例12: updateQName
import org.w3c.dom.Node; //導入方法依賴的package包/類
protected final void updateQName (Node node, QName qname){
String prefix = node.getPrefix();
String namespace = node.getNamespaceURI();
String localName = node.getLocalName();
// REVISIT: the symbols are added too often: start/endElement
// and in the namespaceFixup. Should reduce number of calls to symbol table.
qname.prefix = (prefix!=null && prefix.length()!=0)?fSymbolTable.addSymbol(prefix):null;
qname.localpart = (localName != null)?fSymbolTable.addSymbol(localName):null;
qname.rawname = fSymbolTable.addSymbol(node.getNodeName());
qname.uri = (namespace != null)?fSymbolTable.addSymbol(namespace):null;
}
示例13: createException
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* This should be called from the client side to throw an {@link Exception} for a given soap mesage
*/
public Throwable createException(Map<QName, CheckedExceptionImpl> exceptions) throws JAXBException {
DetailType dt = getDetail();
Node detail = null;
if(dt != null) detail = dt.getDetail(0);
//return ProtocolException if the detail is not present or there is no checked exception
if(detail == null || exceptions == null){
// No soap detail, doesnt look like its a checked exception
// throw a protocol exception
return attachServerException(getProtocolException());
}
//check if the detail is a checked exception, if not throw a ProtocolException
QName detailName = new QName(detail.getNamespaceURI(), detail.getLocalName());
CheckedExceptionImpl ce = exceptions.get(detailName);
if (ce == null) {
//No Checked exception for the received detail QName, throw a SOAPFault exception
return attachServerException(getProtocolException());
}
if (ce.getExceptionType().equals(ExceptionType.UserDefined)) {
return attachServerException(createUserDefinedException(ce));
}
Class exceptionClass = ce.getExceptionClass();
try {
Constructor constructor = exceptionClass.getConstructor(String.class, (Class) ce.getDetailType().type);
Exception exception = (Exception) constructor.newInstance(getFaultString(), getJAXBObject(detail, ce));
return attachServerException(exception);
} catch (Exception e) {
throw new WebServiceException(e);
}
}
示例14: selectNodes
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* @param sibling
* @param uri
* @param nodeName
* @return nodes with the constraint
*/
public static Element[] selectNodes(Node sibling, String uri, String nodeName) {
List<Element> list = new ArrayList<Element>();
while (sibling != null) {
if (sibling.getNamespaceURI() != null && sibling.getNamespaceURI().equals(uri)
&& sibling.getLocalName().equals(nodeName)) {
list.add((Element)sibling);
}
sibling = sibling.getNextSibling();
}
return list.toArray(new Element[list.size()]);
}
示例15: getNamespaceForPrefix
import org.w3c.dom.Node; //導入方法依賴的package包/類
/**
* Given a namespace, get the corrisponding prefix.
* Warning: This will not work correctly if namespaceContext
* is an attribute node.
* @param prefix Prefix to resolve.
* @param namespaceContext Node from which to start searching for a
* xmlns attribute that binds a prefix to a namespace.
* @return Namespace that prefix resolves to, or null if prefix
* is not bound.
*/
public String getNamespaceForPrefix(String prefix,
org.w3c.dom.Node namespaceContext)
{
Node parent = namespaceContext;
String namespace = null;
if (prefix.equals("xml"))
{
namespace = Constants.S_XMLNAMESPACEURI;
}
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;
}