Java Code Examples for javax.xml.XMLConstants#XMLNS_ATTRIBUTE_NS_URI

The following examples show how to use javax.xml.XMLConstants#XMLNS_ATTRIBUTE_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: 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 2
Source File: MapBasedNamespaceContext.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public String getNamespaceURI(String prefix) {
	if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
		if (defaultNamespaceURI == null) {
			return XMLConstants.NULL_NS_URI;
		} else {
			return defaultNamespaceURI;
		}
	} else 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 (prefix == null) {
		throw new IllegalArgumentException("Null prefix not allowed");
	} else {
		String uri = idNamespacesMap.get(prefix);
		if (uri == null) {
			return XMLConstants.NULL_NS_URI;
		} else {
			return uri;
		}
	}
}
 
Example 3
Source File: DOMNamespaceContext.java    From jlibs with Apache License 2.0 6 votes vote down vote up
@Override
public String getNamespaceURI(String prefix){
    if(prefix==null)
        throw new IllegalArgumentException("prefix is null");
    else 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{
        Attr attr = DOMUtil.findNamespaceDeclarationForPrefix(node, prefix);
        if(attr!=null)
            return attr.getNodeValue();
        else if(XMLConstants.DEFAULT_NS_PREFIX.equals(prefix))
            return XMLConstants.NULL_NS_URI;
        else
            return null;
    }
}
 
Example 4
Source File: XMLHelper.java    From ph-commons with Apache License 2.0 6 votes vote down vote up
/**
 * Get the full qualified attribute name to use for the given namespace
 * prefix. The result will e.g. be <code>xmlns</code> or
 * <code>{http://www.w3.org/2000/xmlns/}xmlns:foo</code>.
 *
 * @param sNSPrefix
 *        The namespace prefix to build the attribute name from. May be
 *        <code>null</code> or empty.
 * @return If the namespace prefix is empty (if it equals
 *         {@link XMLConstants#DEFAULT_NS_PREFIX} or <code>null</code>) than
 *         "xmlns" is returned, else "xmlns:<i>prefix</i>" is returned.
 */
@Nonnull
public static QName getXMLNSAttrQName (@Nullable final String sNSPrefix)
{
  if (sNSPrefix != null)
    ValueEnforcer.isFalse (sNSPrefix.contains (CXML.XML_PREFIX_NAMESPACE_SEP_STR),
                           () -> "prefix is invalid: " + sNSPrefix);

  if (sNSPrefix == null || sNSPrefix.equals (XMLConstants.DEFAULT_NS_PREFIX))
  {
    // Default (empty) namespace prefix
    return new QName (XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE);
  }
  // Named XML namespace prefix
  return new QName (XMLConstants.XMLNS_ATTRIBUTE_NS_URI, sNSPrefix, XMLConstants.XMLNS_ATTRIBUTE);
}
 
Example 5
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 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: StringNamespaceContext.java    From XACML with MIT License 6 votes vote down vote up
@Override
public String getNamespaceURI(String prefix) {
	if (prefix == null) {
		throw new IllegalArgumentException();
	} else if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
		if (defaultNamespace == null) {
			return XMLConstants.NULL_NS_URI;
		} else {
			return defaultNamespace.getNamespace();
		}
	} else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
		return XMLConstants.XML_NS_URI;
	} else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
		return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
	} else if (namespaceMap.get(prefix) == null) {
		return XMLConstants.NULL_NS_URI;
	} else {
		return namespaceMap.get(prefix).getNamespace();
	}
}
 
Example 8
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 9
Source File: UnmarshallingContext.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getNamespaceURI(String prefix) {
    if (prefix == null)
        throw new IllegalArgumentException();
    if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;

    return resolveNamespacePrefix(prefix);
}
 
Example 10
Source File: InputElementStack.java    From woodstox with Apache License 2.0 5 votes vote down vote up
@Override
public final String getNamespaceURI(String prefix)
{
    if (prefix == null) {
        throw new IllegalArgumentException(ErrorConsts.ERR_NULL_ARG);
    }
    if (prefix.length() == 0) {
        if (mDepth == 0) { // unexpected... but let's not err at this point
            /* 07-Sep-2007, TSa: Default/"no namespace" does map to
             *    "URI" of empty String.
             */
            return XmlConsts.DEFAULT_NAMESPACE_URI;
        }
        return mCurrElement.mDefaultNsURI;
    }
    if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
        return XMLConstants.XML_NS_URI;
    }
    if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    }
    /* Ok, need to find the match, if any; starting from end of the
     * list of active namespaces. Note that we can not count on prefix
     * being interned/canonicalized.
     */
    return mNamespaces.findLastNonInterned(prefix);
}
 
Example 11
Source File: UnmarshallingContext.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getNamespaceURI(String prefix) {
    if (prefix == null)
        throw new IllegalArgumentException();
    if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;

    return resolveNamespacePrefix(prefix);
}
 
Example 12
Source File: InferringNamespaceContext.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public String getNamespaceURI(String prefix) {
	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;
	} else {
		return inferNamespaceURI(prefix);
	}
}
 
Example 13
Source File: StreamReaderBufferProcessor.java    From jdk8u60 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: WstxSAXParser.java    From woodstox with Apache License 2.0 5 votes vote down vote up
@Override
public String getURI(int index)
{
    if (index < mAttrCount) {
        if (index < 0) {
            return null;
        }
        String uri = mAttrCollector.getURI(index);
        return (uri == null) ? "" : uri;
    }
    if ((index - mAttrCount) < mNsCount) {
        return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
    }
    return null;
}
 
Example 15
Source File: ModuleNamespaceContext.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Iterator<String> getPrefixes(final String namespaceURI) {
    checkArgument(namespaceURI != null);

    switch (namespaceURI) {
        case YangConstants.RFC6020_YIN_NAMESPACE_STRING:
            return Iterators.singletonIterator(XMLConstants.DEFAULT_NS_PREFIX);
        case XMLConstants.XML_NS_URI:
            return Iterators.singletonIterator(XMLConstants.XML_NS_PREFIX);
        case XMLConstants.XMLNS_ATTRIBUTE_NS_URI:
            return Iterators.singletonIterator(XMLConstants.XMLNS_ATTRIBUTE);
        default:
            return namespaceToPrefix.get(namespaceURI).iterator();
    }
}
 
Example 16
Source File: StreamReaderBufferProcessor.java    From openjdk-8-source 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: NamespaceImpl.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/** Creates a new instance of NamespaceImpl */
public NamespaceImpl(String namespaceURI) {
    super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null);
    init();
}
 
Example 18
Source File: NamespaceImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/** Creates a new instance of NamespaceImpl */
public NamespaceImpl(String namespaceURI) {
    super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null);
    init();
}
 
Example 19
Source File: NamespaceImpl.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/** Creates a new instance of NamespaceImpl */
public NamespaceImpl(String namespaceURI) {
    super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null);
    init();
}
 
Example 20
Source File: NamespaceImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/** Creates a new instance of NamespaceImpl */
public NamespaceImpl(String namespaceURI) {
    super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null);
    init();
}