Example usage for javax.xml XMLConstants DEFAULT_NS_PREFIX

List of usage examples for javax.xml XMLConstants DEFAULT_NS_PREFIX

Introduction

In this page you can find the example usage for javax.xml XMLConstants DEFAULT_NS_PREFIX.

Prototype

String DEFAULT_NS_PREFIX

To view the source code for javax.xml XMLConstants DEFAULT_NS_PREFIX.

Click Source Link

Document

Prefix to use to represent the default XML Namespace.

Usage

From source file:org.xchain.framework.jxpath.JXPathValidator.java

static void validatePrefix(String prefix, NamespaceContext xmlns) {
    if ((prefix != null) && (!XMLConstants.DEFAULT_NS_PREFIX.equals(prefix))
            && XMLConstants.NULL_NS_URI.equals(xmlns.getNamespaceURI(prefix))) {
        throw new JXPathException("The prefix '" + prefix + "' is not defined in the current context.");
    }/*from  www.j a va  2s.  c o  m*/
}

From source file:org.xchain.framework.util.JXPathContextUtil.java

public static void validate(String value, NamespaceContext namespaceContext) {
    Matcher matcher = uriLocalNamePattern.matcher(value);
    if (matcher.matches()) {
        // this is valid, so return.
        return;// www  . j  a v a2  s. c  om
    }

    matcher = prefixLocalNamePattern.matcher(value);
    if (matcher.matches()) {
        String prefix = matcher.group(1);

        if (prefix != null && !XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)
                && XMLConstants.NULL_NS_URI.equals(namespaceContext.getNamespaceURI(prefix))) {
            throw new JXPathException(
                    "There is not namespace mapping for the prefix of qname '" + value + "'.");
        }
        return;
    }

    matcher = localNamePattern.matcher(value);
    if (matcher.matches()) {
        return;
    }

    throw new JXPathException("There is a syntax error in the qname '" + value + "'.");
}