Java Code Examples for javax.xml.XMLConstants#XML_NS_URI

The following examples show how to use javax.xml.XMLConstants#XML_NS_URI . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleNamespaceContext.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public String getNamespaceURI(String prefix) {
	Assert.notNull(prefix, "No prefix given");
	if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
		return XMLConstants.XML_NS_URI;
	}
	else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
		return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
	}
	else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
		return this.defaultNamespaceUri;
	}
	else if (this.prefixToNamespaceUri.containsKey(prefix)) {
		return this.prefixToNamespaceUri.get(prefix);
	}
	return "";
}
 
Example 2
Source File: UnmarshallingContext.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private String resolveNamespacePrefix( String prefix ) {
    if(prefix.equals("xml"))
        return XMLConstants.XML_NS_URI;

    for( int i=nsLen-2; i>=0; i-=2 ) {
        if(prefix.equals(nsBind[i]))
            return nsBind[i+1];
    }

    if(environmentNamespaceContext!=null)
        // temporary workaround until Zephyr fixes 6337180
        return environmentNamespaceContext.getNamespaceURI(prefix.intern());

    // by default, the default ns is bound to "".
    // but allow environmentNamespaceContext to take precedence
    if(prefix.equals(""))
        return "";

    // unresolved. error.
    return null;
}
 
Example 3
Source File: DomXPathNamespaceResolver.java    From camunda-spin with Apache License 2.0 6 votes vote down vote up
public String getNamespaceURI(String prefix) {
  ensureNotNull("Prefix", prefix);

  if(prefix.equals(XMLConstants.XML_NS_PREFIX)) {
    return XMLConstants.XML_NS_URI;
  }

  if(prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
    return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
  }

  /**
   * TODO: This only works for the root element. Every child element with a 'xmlns'-attribute will be ignored
   * So you need to specify an own prefix for the child elements default namespace uri
   */
  if(prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
    return element.namespace();
  }

  if(namespaces.containsKey(prefix)) {
    return namespaces.get(prefix);
  } else {
    return XMLConstants.NULL_NS_URI;
  }
}
 
Example 4
Source File: BaseNsContext.java    From woodstox with Apache License 2.0 6 votes vote down vote up
@Override
public final String getNamespaceURI(String prefix)
{
    /* First the known offenders; invalid args, 2 predefined xml namespace
     * prefixes
     */
    if (prefix == null) {
        throw new IllegalArgumentException(ErrorConsts.ERR_NULL_ARG);
    }
    if (prefix.length() > 0) {
        if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
            return XMLConstants.XML_NS_URI;
        }
        if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
            return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
        }
    }
    return doGetNamespaceURI(prefix);
}
 
Example 5
Source File: CityGMLNamespaceContext.java    From citygml4j with Apache License 2.0 6 votes vote down vote up
public String getNamespaceURI(String prefix) {
	if (prefix == null)
		throw new IllegalArgumentException("namespace prefix may not be null.");

	if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
		String tmp = namespaces.get(prefix);
		if (tmp != null)
			return tmp;
	}

	if (prefix.equals(XMLConstants.XML_NS_PREFIX))
		return XMLConstants.XML_NS_URI;

	if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
		return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;

	Iterator<Entry<String, String>> iter = namespaces.entrySet().iterator();
	while (iter.hasNext()) {
		Entry<String, String> entry = iter.next();
		if (entry.getValue().equals(prefix))
			return entry.getKey();
	}

	return XMLConstants.NULL_NS_URI;
}
 
Example 6
Source File: ModuleNamespaceContext.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getPrefix(final String namespaceURI) {
    checkArgument(namespaceURI != null);

    switch (namespaceURI) {
        case YangConstants.RFC6020_YIN_NAMESPACE_STRING:
            return XMLConstants.DEFAULT_NS_PREFIX;
        case XMLConstants.XML_NS_URI:
            return XMLConstants.XML_NS_PREFIX;
        case XMLConstants.XMLNS_ATTRIBUTE_NS_URI:
            return XMLConstants.XMLNS_ATTRIBUTE;
        default:
            final List<@NonNull String> prefixes = namespaceToPrefix.get(namespaceURI);
            return prefixes.isEmpty() ? null : prefixes.get(0);
    }
}
 
Example 7
Source File: SimpleNamespaceContext.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public String getNamespaceURI(String prefix) {
	Assert.notNull(prefix, "prefix is null");
	if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
		return XMLConstants.XML_NS_URI;
	}
	else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
		return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
	}
	else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
		return defaultNamespaceUri;
	}
	else if (prefixToNamespaceUri.containsKey(prefix)) {
		return prefixToNamespaceUri.get(prefix);
	}
	return "";
}
 
Example 8
Source File: UnmarshallingContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private String resolveNamespacePrefix( String prefix ) {
    if(prefix.equals("xml"))
        return XMLConstants.XML_NS_URI;

    for( int i=nsLen-2; i>=0; i-=2 ) {
        if(prefix.equals(nsBind[i]))
            return nsBind[i+1];
    }

    if(environmentNamespaceContext!=null)
        // temporary workaround until Zephyr fixes 6337180
        return environmentNamespaceContext.getNamespaceURI(prefix.intern());

    // by default, the default ns is bound to "".
    // but allow environmentNamespaceContext to take precedence
    if(prefix.equals(""))
        return "";

    // unresolved. error.
    return null;
}
 
Example 9
Source File: PlutoWebXmlRewriter.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
public String getNamespaceURI(String prefix)
{
    if (prefix == null)
    {
        throw new NullPointerException("Null prefix");
    }
    else if (this.prefix.equals(prefix))
    {
        return namespaceURI;
    }
    else if ("xml".equals(prefix))
    {
        return XMLConstants.XML_NS_URI;
    }
    return XMLConstants.NULL_NS_URI;
}
 
Example 10
Source File: EditableNamespaceContext.java    From java-client-api with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the URI for a namespace binding.
 */
@Override
public String getNamespaceURI(String prefix) {
  // per javax.xml.namespace.NamespaceContext doc
  if (prefix == null)
    throw new IllegalArgumentException("Cannot get namespace URI for null prefix");
  if (XMLConstants.XML_NS_PREFIX.equals(prefix))
    return XMLConstants.XML_NS_URI;
  if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix))
    return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;

  String namespaceURI = bindings.get(prefix);

  // per javax.xml.namespace.NamespaceContext doc
  return (namespaceURI != null) ? namespaceURI : XMLConstants.NULL_NS_URI;
}
 
Example 11
Source File: SimpleNamespaceContext.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String getNamespaceURI(String prefix) {
	Assert.notNull(prefix, "No prefix given");
	if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
		return XMLConstants.XML_NS_URI;
	}
	else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
		return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
	}
	else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
		return this.defaultNamespaceUri;
	}
	else if (this.prefixToNamespaceUri.containsKey(prefix)) {
		return this.prefixToNamespaceUri.get(prefix);
	}
	return "";
}
 
Example 12
Source File: StreamReaderBufferProcessor.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"StringEquality"})
public String getNamespaceURI(String prefix) {
    if (prefix == null) {
        throw new IllegalArgumentException("Prefix cannot be null");
    }

    /*
     * If the buffer was created using string interning
     * intern the prefix and check for reference equality
     * rather than using String.equals();
     */
    if (_stringInterningFeature) {
        prefix = prefix.intern();

        // Find the most recently declared prefix
        for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
            if (prefix == _namespaceAIIsPrefix[i]) {
                return _namespaceAIIsNamespaceName[i];
            }
        }
    } else {
        // Find the most recently declared prefix
        for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
            if (prefix.equals(_namespaceAIIsPrefix[i])) {
                return _namespaceAIIsNamespaceName[i];
            }
        }
    }

    // Check for XML-based prefixes
    if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
        return XMLConstants.XML_NS_URI;
    } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    }

    return null;
}
 
Example 13
Source File: StreamReaderBufferProcessor.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"StringEquality"})
public String getNamespaceURI(String prefix) {
    if (prefix == null) {
        throw new IllegalArgumentException("Prefix cannot be null");
    }

    /*
     * If the buffer was created using string interning
     * intern the prefix and check for reference equality
     * rather than using String.equals();
     */
    if (_stringInterningFeature) {
        prefix = prefix.intern();

        // Find the most recently declared prefix
        for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
            if (prefix == _namespaceAIIsPrefix[i]) {
                return _namespaceAIIsNamespaceName[i];
            }
        }
    } else {
        // Find the most recently declared prefix
        for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
            if (prefix.equals(_namespaceAIIsPrefix[i])) {
                return _namespaceAIIsNamespaceName[i];
            }
        }
    }

    // Check for XML-based prefixes
    if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
        return XMLConstants.XML_NS_URI;
    } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    }

    return null;
}
 
Example 14
Source File: StreamReaderBufferProcessor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"StringEquality"})
public String getNamespaceURI(String prefix) {
    if (prefix == null) {
        throw new IllegalArgumentException("Prefix cannot be null");
    }

    /*
     * If the buffer was created using string interning
     * intern the prefix and check for reference equality
     * rather than using String.equals();
     */
    if (_stringInterningFeature) {
        prefix = prefix.intern();

        // Find the most recently declared prefix
        for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
            if (prefix == _namespaceAIIsPrefix[i]) {
                return _namespaceAIIsNamespaceName[i];
            }
        }
    } else {
        // Find the most recently declared prefix
        for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
            if (prefix.equals(_namespaceAIIsPrefix[i])) {
                return _namespaceAIIsNamespaceName[i];
            }
        }
    }

    // Check for XML-based prefixes
    if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
        return XMLConstants.XML_NS_URI;
    } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    }

    return null;
}
 
Example 15
Source File: BijectiveNsMap.java    From woodstox with Apache License 2.0 5 votes vote down vote up
public static BijectiveNsMap createEmpty()
{
    String[] strs = new String[DEFAULT_ARRAY_SIZE];

    strs[0] = XMLConstants.XML_NS_PREFIX;
    strs[1] = XMLConstants.XML_NS_URI;
    strs[2] = XMLConstants.XMLNS_ATTRIBUTE;
    strs[3] = XMLConstants.XMLNS_ATTRIBUTE_NS_URI;

    // Let's consider pre-defined ones to be 'out of scope', i.e.
    // conceptually be part of (missing) parent's mappings.
    return new BijectiveNsMap(4, strs);
}
 
Example 16
Source File: StreamReaderBufferProcessor.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"StringEquality"})
public String getNamespaceURI(String prefix) {
    if (prefix == null) {
        throw new IllegalArgumentException("Prefix cannot be null");
    }

    /*
     * If the buffer was created using string interning
     * intern the prefix and check for reference equality
     * rather than using String.equals();
     */
    if (_stringInterningFeature) {
        prefix = prefix.intern();

        // Find the most recently declared prefix
        for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
            if (prefix == _namespaceAIIsPrefix[i]) {
                return _namespaceAIIsNamespaceName[i];
            }
        }
    } else {
        // Find the most recently declared prefix
        for (int i = _namespaceAIIsEnd - 1; i >=0; i--) {
            if (prefix.equals(_namespaceAIIsPrefix[i])) {
                return _namespaceAIIsNamespaceName[i];
            }
        }
    }

    // Check for XML-based prefixes
    if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
        return XMLConstants.XML_NS_URI;
    } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    }

    return null;
}
 
Example 17
Source File: NamespaceContextImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public String getNamespaceURI(String prefix) {
    Node parent = e;
    String namespace = null;
    final String prefixColon = prefix + ':';

    if (prefix.equals("xml")) {
        namespace = XMLConstants.XML_NS_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().startsWith(prefixColon))
                    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();
        }
    }

    if(prefix.equals(""))
        return "";  // default namespace
    return namespace;
}
 
Example 18
Source File: NamespaceContextImpl.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public String getNamespaceURI(String prefix) {
    Node parent = e;
    String namespace = null;
    final String prefixColon = prefix + ':';

    if (prefix.equals("xml")) {
        namespace = XMLConstants.XML_NS_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().startsWith(prefixColon))
                    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();
        }
    }

    if(prefix.equals(""))
        return "";  // default namespace
    return namespace;
}
 
Example 19
Source File: NamespaceContextImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public String getNamespaceURI(String prefix) {
    Node parent = e;
    String namespace = null;
    final String prefixColon = prefix + ':';

    if (prefix.equals("xml")) {
        namespace = XMLConstants.XML_NS_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().startsWith(prefixColon))
                    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();
        }
    }

    if(prefix.equals(""))
        return "";  // default namespace
    return namespace;
}
 
Example 20
Source File: NamespaceContextImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public String getNamespaceURI(String prefix) {
    Node parent = e;
    String namespace = null;
    final String prefixColon = prefix + ':';

    if (prefix.equals("xml")) {
        namespace = XMLConstants.XML_NS_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().startsWith(prefixColon))
                    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();
        }
    }

    if(prefix.equals(""))
        return "";  // default namespace
    return namespace;
}