本文整理匯總了Java中org.w3c.dom.DOMException.NAMESPACE_ERR屬性的典型用法代碼示例。如果您正苦於以下問題:Java DOMException.NAMESPACE_ERR屬性的具體用法?Java DOMException.NAMESPACE_ERR怎麽用?Java DOMException.NAMESPACE_ERR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.w3c.dom.DOMException
的用法示例。
在下文中一共展示了DOMException.NAMESPACE_ERR屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createExpression
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
* prefixes within the XPath expression into appropriate namespace URIs
* . If this is specified as <code>null</code>, any namespace prefix
* within the expression will result in <code>DOMException</code>
* being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
* INVALID_EXPRESSION_ERR: Raised if the expression is not legal
* according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
* NAMESPACE_ERR: Raised if the expression contains namespace prefixes
* which cannot be resolved by the specified
* <code>XPathNSResolver</code>.
*
* @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
*/
public XPathExpression createExpression(
String expression,
XPathNSResolver resolver)
throws XPathException, DOMException {
try {
// If the resolver is null, create a dummy prefix resolver
XPath xpath = new XPath(expression,null,
((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
XPath.SELECT);
return new XPathExpressionImpl(xpath, m_doc);
} catch (TransformerException e) {
// Need to pass back exception code DOMException.NAMESPACE_ERR also.
// Error found in DOM Level 3 XPath Test Suite.
if(e instanceof XPathStylesheetDOM3Exception)
throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
else
throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());
}
}
示例2: setName
private void setName(String namespaceURI, String qname){
CoreDocumentImpl ownerDocument = ownerDocument();
String prefix;
// DOM Level 3: namespace URI is never empty string.
this.namespaceURI = namespaceURI;
if (namespaceURI !=null) {
this.namespaceURI = (namespaceURI.length() == 0)? null
: namespaceURI;
}
int colon1 = qname.indexOf(':');
int colon2 = qname.lastIndexOf(':');
ownerDocument.checkNamespaceWF(qname, colon1, colon2);
if (colon1 < 0) {
// there is no prefix
localName = qname;
if (ownerDocument.errorChecking) {
ownerDocument.checkQName(null, localName);
if (qname.equals("xmlns") && (namespaceURI == null
|| !namespaceURI.equals(NamespaceContext.XMLNS_URI))
|| (namespaceURI!=null && namespaceURI.equals(NamespaceContext.XMLNS_URI)
&& !qname.equals("xmlns"))) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
}
else {
prefix = qname.substring(0, colon1);
localName = qname.substring(colon2+1);
ownerDocument.checkQName(prefix, localName);
ownerDocument.checkDOMNSErr(prefix, namespaceURI);
}
}
示例3: createElementNS
/**
* Creates an element of the given qualified name and namespace URI.
* <br>Per [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
* , applications must use the value <code>null</code> as the
* namespaceURI parameter for methods if they wish to have no namespace.
* @param namespaceURI The namespace URI of the element to create.
* @param qualifiedName The qualified name of the element type to
* instantiate.
* @return A new <code>Element</code> object with the following
* attributes:
* <table border='1' cellpadding='3'>
* <tr>
* <th>Attribute</th>
* <th>Value</th>
* </tr>
* <tr>
* <td valign='top' rowspan='1' colspan='1'><code>Node.nodeName</code></td>
* <td valign='top' rowspan='1' colspan='1'>
* <code>qualifiedName</code></td>
* </tr>
* <tr>
* <td valign='top' rowspan='1' colspan='1'><code>Node.namespaceURI</code></td>
* <td valign='top' rowspan='1' colspan='1'>
* <code>namespaceURI</code></td>
* </tr>
* <tr>
* <td valign='top' rowspan='1' colspan='1'><code>Node.prefix</code></td>
* <td valign='top' rowspan='1' colspan='1'>prefix, extracted
* from <code>qualifiedName</code>, or <code>null</code> if there is
* no prefix</td>
* </tr>
* <tr>
* <td valign='top' rowspan='1' colspan='1'><code>Node.localName</code></td>
* <td valign='top' rowspan='1' colspan='1'>local name, extracted from
* <code>qualifiedName</code></td>
* </tr>
* <tr>
* <td valign='top' rowspan='1' colspan='1'><code>Element.tagName</code></td>
* <td valign='top' rowspan='1' colspan='1'>
* <code>qualifiedName</code></td>
* </tr>
* </table>
* @exception DOMException
* INVALID_CHARACTER_ERR: Raised if the specified
* <code>qualifiedName</code> is not an XML name according to the XML
* version in use specified in the <code>Document.xmlVersion</code>
* attribute.
* <br>NAMESPACE_ERR: Raised if the <code>qualifiedName</code> is a
* malformed qualified name, if the <code>qualifiedName</code> has a
* prefix and the <code>namespaceURI</code> is <code>null</code>, or
* if the <code>qualifiedName</code> has a prefix that is "xml" and
* the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/XML/1998/namespace'>
* http://www.w3.org/XML/1998/namespace</a>" [<a href='http://www.w3.org/TR/1999/REC-xml-names-19990114/'>XML Namespaces</a>]
* , or if the <code>qualifiedName</code> or its prefix is XMLNS and
* the <code>namespaceURI</code> is different from "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>", or if the <code>namespaceURI</code> is "<a href='http://www.w3.org/2000/xmlns/'>http://www.w3.org/2000/xmlns/</a>" and neither the <code>qualifiedName</code> nor its prefix is XMLNS.
* <br>NOT_SUPPORTED_ERR: Always thrown if the current document does not
* support the <code>"XML"</code> feature, since namespaces were
* defined by XML.
* @since DOM Level 2
*/
public org.w3c.dom.Element createElementNS(String namespaceURI, String qualifiedName) {
Element ret = new Element(qualifiedName);
String prefix = ret.getPrefix();
if (prefix != null) {
if (namespaceURI == null) {
throw new DOMException(DOMException.NAMESPACE_ERR, null);
}
ret.appendAttribute(new Attribute("xmlns:"+prefix, namespaceURI)); //NOI18N
} else {
ret = new Element(ret.getLocalName());
if (namespaceURI != null && ! namespaceURI.equals(XMLConstants.NULL_NS_URI)) {
ret.appendAttribute(new Attribute(XMLNS, namespaceURI));
}
}
return ret;
}
示例4: if
/**
* Call user data handlers to let them know the nodes they are related to
* are being deleted. The alternative would be to do that on Node but
* because the nodes are used as the keys we have a reference to them that
* prevents them from being gc'ed until the document is. At the same time,
* doing it here has the advantage of avoiding a finalize() method on Node,
* which would affect all nodes and not just the ones that have a user
* data.
*/
// Temporarily comment out this method, because
// 1. It seems that finalizers are not guaranteed to be called, so the
// functionality is not implemented.
// 2. It affects the performance greatly in multi-thread environment.
// -SG
/*public void finalize() {
if (userData == null) {
return;
}
Enumeration nodes = userData.keys();
while (nodes.hasMoreElements()) {
Object node = nodes.nextElement();
Hashtable t = (Hashtable) userData.get(node);
if (t != null && !t.isEmpty()) {
Enumeration keys = t.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
UserDataRecord r = (UserDataRecord) t.get(key);
if (r.fHandler != null) {
r.fHandler.handle(UserDataHandler.NODE_DELETED,
key, r.fData, null, null);
}
}
}
}
}*/
protected final void checkNamespaceWF( String qname, int colon1,
int colon2) {
if (!errorChecking) {
return;
}
// it is an error for NCName to have more than one ':'
// check if it is valid QName [Namespace in XML production 6]
// :camera , nikon:camera:minolta, camera:
if (colon1 == 0 || colon1 == qname.length() - 1 || colon2 != colon1) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
示例5: if
/**
* Call user data handlers to let them know the nodes they are related to
* are being deleted. The alternative would be to do that on Node but
* because the nodes are used as the keys we have a reference to them that
* prevents them from being gc'ed until the document is. At the same time,
* doing it here has the advantage of avoiding a finalize() method on Node,
* which would affect all nodes and not just the ones that have a user
* data.
*/
// Temporarily comment out this method, because
// 1. It seems that finalizers are not guaranteed to be called, so the
// functionality is not implemented.
// 2. It affects the performance greatly in multi-thread environment.
// -SG
/*public void finalize() {
if (userData == null) {
return;
}
Enumeration nodes = userData.keys();
while (nodes.hasMoreElements()) {
Object node = nodes.nextElement();
Hashtable t = (Hashtable) userData.get(node);
if (t != null && !t.isEmpty()) {
Enumeration keys = t.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
UserDataRecord r = (UserDataRecord) t.get(key);
if (r.fHandler != null) {
r.fHandler.handle(UserDataHandler.NODE_DELETED,
key, r.fData, null, null);
}
}
}
}
}*/
protected final void checkNamespaceWF( String qname, int colon1,
int colon2) {
if (!errorChecking) {
return;
}
// it is an error for NCName to have more than one ':'
// check if it is valid QName [Namespace in XML production 6]
// :camera , nikon:camera:minolta, camera:
if (colon1 == 0 || colon1 == qname.length() - 1 || colon2 != colon1) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
示例6: setPrefix
/**
* Introduced in DOM Level 2. <p>
*
* The namespace prefix of this node, or null if it is unspecified. When
* this node is of any type other than ELEMENT_NODE and ATTRIBUTE_NODE
* this is always null and setting it has no effect.<p>
*
* For nodes created with a DOM Level 1 method, such as createElement from
* the Document interface, this is null.<p>
*
* Note that setting this attribute changes the nodeName attribute, which
* holds the qualified name, as well as the tagName and name attributes of
* the Element and Attr interfaces, when applicable.<p>
*
* @throws INVALID_CHARACTER_ERR Raised if the specified
* prefix contains an invalid character.
*
* @since WD-DOM-Level-2-19990923
* @see AttrNSImpl
* @see ElementNSImpl
*/
public void setPrefix(String prefix)
throws DOMException
{
throw new DOMException(DOMException.NAMESPACE_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR", null));
}
示例7: getNamespaceForPrefix
/**
* @exception DOMException
* NAMESPACE_ERR: Always throws this exceptionn
*
* @see com.sun.org.apache.xml.internal.utils.PrefixResolver#getNamespaceForPrefix(String, Node)
*/
public String getNamespaceForPrefix(String prefix, Node context) {
String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_RESOLVER, null);
throw new DOMException(DOMException.NAMESPACE_ERR, fmsg); // Unable to resolve prefix with null prefix resolver.
}