📄 domdocument.java
字号:
* Name. * @deprecated This method is deprecated and may be removed in future * versions of GNU JAXP */ public static void verifyXmlName(String name) { // XXX why is this public? checkName(name, false); } static void checkName(String name, boolean xml11) { if (name == null) { throw new DomDOMException(DOMException.NAMESPACE_ERR, name, null, 0); } int len = name.length(); if (len == 0) { throw new DomDOMException(DOMException.NAMESPACE_ERR, name, null, 0); } // dog: rewritten to use the rules for XML 1.0 and 1.1 // Name start character char c = name.charAt(0); if (xml11) { // XML 1.1 if ((c < 0x0041 || c > 0x005a) && (c < 0x0061 || c > 0x007a) && c != ':' && c != '_' && (c < 0x00c0 || c > 0x00d6) && (c < 0x00d8 || c > 0x00f6) && (c < 0x00f8 || c > 0x02ff) && (c < 0x0370 || c > 0x037d) && (c < 0x037f || c > 0x1fff) && (c < 0x200c || c > 0x200d) && (c < 0x2070 || c > 0x218f) && (c < 0x2c00 || c > 0x2fef) && (c < 0x3001 || c > 0xd7ff) && (c < 0xf900 || c > 0xfdcf) && (c < 0xfdf0 || c > 0xfffd) && (c < 0x10000 || c > 0xeffff)) { throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, name, null, c); } } else { // XML 1.0 int type = Character.getType(c); switch (type) { case Character.LOWERCASE_LETTER: // Ll case Character.UPPERCASE_LETTER: // Lu case Character.OTHER_LETTER: // Lo case Character.TITLECASE_LETTER: // Lt case Character.LETTER_NUMBER: // Nl if ((c > 0xf900 && c < 0xfffe) || (c >= 0x20dd && c <= 0x20e0)) { // Compatibility area and Unicode 2.0 exclusions throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, name, null, c); } break; default: if (c != ':' && c != '_' && (c < 0x02bb || c > 0x02c1) && c != 0x0559 && c != 0x06e5 && c != 0x06e6) { throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, name, null, c); } } } // Subsequent characters for (int i = 1; i < len; i++) { c = name.charAt(i); if (xml11) { // XML 1.1 if ((c < 0x0041 || c > 0x005a) && (c < 0x0061 || c > 0x007a) && (c < 0x0030 || c > 0x0039) && c != ':' && c != '_' && c != '-' && c != '.' && (c < 0x00c0 || c > 0x00d6) && (c < 0x00d8 || c > 0x00f6) && (c < 0x00f8 || c > 0x02ff) && (c < 0x0370 || c > 0x037d) && (c < 0x037f || c > 0x1fff) && (c < 0x200c || c > 0x200d) && (c < 0x2070 || c > 0x218f) && (c < 0x2c00 || c > 0x2fef) && (c < 0x3001 || c > 0xd7ff) && (c < 0xf900 || c > 0xfdcf) && (c < 0xfdf0 || c > 0xfffd) && (c < 0x10000 || c > 0xeffff) && c != 0x00b7 && (c < 0x0300 || c > 0x036f) && (c < 0x203f || c > 0x2040)) { throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, name, null, c); } } else { // XML 1.0 int type = Character.getType(c); switch (type) { case Character.LOWERCASE_LETTER: // Ll case Character.UPPERCASE_LETTER: // Lu case Character.DECIMAL_DIGIT_NUMBER: // Nd case Character.OTHER_LETTER: // Lo case Character.TITLECASE_LETTER: // Lt case Character.LETTER_NUMBER: // Nl case Character.COMBINING_SPACING_MARK: // Mc case Character.ENCLOSING_MARK: // Me case Character.NON_SPACING_MARK: // Mn case Character.MODIFIER_LETTER: // Lm if ((c > 0xf900 && c < 0xfffe) || (c >= 0x20dd && c <= 0x20e0)) { // Compatibility area and Unicode 2.0 exclusions throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, name, null, c); } break; default: if (c != '-' && c != '.' && c != ':' && c != '_' && c != 0x0387 && (c < 0x02bb || c > 0x02c1) && c != 0x0559 && c != 0x06e5 && c != 0x06e6 && c != 0x00b7) { throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, name, null, c); } } } } // FIXME characters with a font or compatibility decomposition (i.e. // those with a "compatibility formatting tag" in field 5 of the // database -- marked by field 5 beginning with a "<") are not allowed. } // package private static void checkNCName(String name, boolean xml11) { checkName(name, xml11); int len = name.length(); int index = name.indexOf(':'); if (index != -1) { if (index == 0 || index == (len - 1) || name.lastIndexOf(':') != index) { throw new DomDOMException(DOMException.NAMESPACE_ERR, name, null, 0); } } } // package private static void checkChar(String value, boolean xml11) { char[] chars = value.toCharArray(); checkChar(chars, 0, chars.length, xml11); } static void checkChar(char[] buf, int off, int len, boolean xml11) { for (int i = 0; i < len; i++) { char c = buf[i]; // assume surrogate pairing checks out OK, for simplicity if ((c >= 0x0020 && c <= 0xd7ff) || (c == 0x000a || c == 0x000d || c == 0x0009) || (c >= 0xe000 && c <= 0xfffd) || (c >= 0x10000 && c <= 0x10ffff)) { continue; } if (xml11) { if ((c >= 0x0001 && c <= 0x001f) || (c >= 0x007f && c <= 0x0084) || (c >= 0x0086 && c <= 0x009f)) { continue; } } throw new DomDOMException(DOMException.INVALID_CHARACTER_ERR, new String(buf, off, len), null, c); } } /** * <b>DOM L1</b> * Returns a newly created element with the specified name. */ public Element createElement(String name) { Element element; if (checkingCharacters) { checkName(name, "1.1".equals(version)); } if (name.startsWith("xml:")) { element = createElementNS(null, name); } else { DomElement domElement = new DomElement(this, null, name); domElement.localName = null; element = domElement; } defaultAttributes(element, name); return element; } /** * <b>DOM L2</b> * Returns a newly created element with the specified name * and namespace information. */ public Element createElementNS(String namespaceURI, String name) { if (checkingCharacters) { checkNCName(name, "1.1".equals(version)); } if ("".equals(namespaceURI)) { namespaceURI = null; } if (name.startsWith("xml:")) { if (namespaceURI != null && !XMLConstants.XML_NS_URI.equals(namespaceURI)) { throw new DomDOMException(DOMException.NAMESPACE_ERR, "xml namespace is always " + XMLConstants.XML_NS_URI, this, 0); } namespaceURI = XMLConstants.XML_NS_URI; } else if (XMLConstants.XMLNS_ATTRIBUTE.equals(name) || name.startsWith("xmlns:")) { throw new DomDOMException(DOMException.NAMESPACE_ERR, "xmlns is reserved", this, 0); } else if (namespaceURI == null && name.indexOf(':') != -1) { throw new DomDOMException(DOMException.NAMESPACE_ERR, "prefixed name '" + name + "' needs a URI", this, 0); } Element element = new DomElement(this, namespaceURI, name); defaultAttributes(element, name); return element; } private void defaultAttributes(Element element, String name) { DomDoctype doctype = (DomDoctype) getDoctype(); if (doctype == null) { return; } // default any attributes that need it DTDElementTypeInfo info = doctype.getElementTypeInfo(name); if (info != null) { for (Iterator i = info.attributes(); i != null && i.hasNext(); ) { DTDAttributeTypeInfo attr = (DTDAttributeTypeInfo) i.next(); DomAttr node = (DomAttr) createAttribute(attr.name); String value = attr.value; if (value == null) { value = ""; } node.setValue(value); node.setSpecified(false); element.setAttributeNode(node); } } } /** * <b>DOM L1</b> * Returns a newly created document fragment. */ public DocumentFragment createDocumentFragment() { return new DomDocumentFragment(this); } /** * <b>DOM L1</b> * Returns a newly created text node with the specified value. */ public Text createTextNode(String value) { if (checkingCharacters) { checkChar(value, "1.1".equals(version)); } return new DomText(this, value); } /** * Returns a newly created text node with the specified value. */ public Text createTextNode(char[] buf, int off, int len) { if (checkingCharacters) { checkChar(buf, off, len, "1.1".equals(version)); } return new DomText(this, buf, off, len); } /** * <b>DOM L1</b> * Returns a newly created comment node with the specified value. */ public Comment createComment(String value) { if (checkingCharacters) { checkChar(value, "1.1".equals(version)); } return new DomComment(this, value); } /** * <b>DOM L1</b> * Returns a newly created CDATA section node with the specified value. */ public CDATASection createCDATASection(String value) { if (checkingCharacters) { checkChar(value, "1.1".equals(version)); } return new DomCDATASection(this, value); } /** * Returns a newly created CDATA section node with the specified value. */ public CDATASection createCDATASection(char[] buf, int off, int len) { if (checkingCharacters) { checkChar(buf, off, len, "1.1".equals(version)); } return new DomCDATASection(this, buf, off, len); } /** * <b>DOM L1</b> * Returns a newly created processing instruction. */ public ProcessingInstruction createProcessingInstruction(String target,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -