public synchronized void setDefaultNamespace(String nsURI) throws XMLStreamException { peekNamespaceStack().setDefaultNamespace(nsURI); }
/** * Declares a namespace binding in this context. * * @param prefix The namespace prefix. * @param nsURI The namespace URI. * @return The previously declared namespace uri, or <code>null</code> if * the prefix wasn't previously declared in this context. */ public String setPrefix(String prefix, String nsURI) { if (prefix == null) { throw new NullPointerException("Namespace Prefix was null"); } else if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { return setDefaultNamespace(nsURI); } else if (prefix.equals(XMLConstants.XML_NS_PREFIX)) { throw new IllegalArgumentException("Attempt to map 'xml' prefix"); } else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) { throw new IllegalArgumentException("Attempt to map 'xmlns' prefix"); } else if (nsURI != null) { if (nsURI.equals(XMLConstants.XML_NS_URI)) { throw new IllegalArgumentException("Attempt to map 'xml' uri"); } else if (nsURI.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) { throw new IllegalArgumentException("Attempt to map 'xmlns' uri"); } else { return (String) namespaces.put(prefix, nsURI); } } else { // put the empty string to record an undefined prefix return (String) namespaces.put(prefix, ""); } }
/** * Adds a namespace declaration to this context with the specified prefix and * namespace uri. * * @param prefix The namespace prefix. * @param nsURI The namespace uri. */ public void putNamespace(String prefix, String nsURI) { if (isReadOnly()) { throw new IllegalStateException("ElementContext is readOnly"); } if (namespacePrefixes == null) { namespacePrefixes = new ArrayList(); } if (prefix.length() == 0) { // default namespace namespacePrefixes.add(prefix); super.setDefaultNamespace(nsURI); } else { namespacePrefixes.add(prefix); super.setPrefix(prefix, nsURI); } }