CoreDOMImplementationImplpublic class CoreDOMImplementationImpl extends Object implements DOMImplementationLS, DOMImplementationThe DOMImplementation class is description of a particular
implementation of the Document Object Model. As such its data is
static, shared by all instances of this implementation.
The DOM API requires that it be a real object rather than static
methods. However, there's nothing that says it can't be a singleton,
so that's how I've implemented it.
This particular class, along with CoreDocumentImpl, supports the DOM
Core and Load/Save (Experimental). Optional modules are supported by
the more complete DOMImplementation class along with DocumentImpl. |
Fields Summary |
---|
private static final int | SIZE | private RevalidationHandler[] | validators | private int | freeValidatorIndex | private int | currentSize | private int | docAndDoctypeCounter | static CoreDOMImplementationImpl | singletonDom implementation singleton. |
Methods Summary |
---|
protected synchronized int | assignDocTypeNumber()NON-DOM: increment document/doctype counter
return ++docAndDoctypeCounter;
| protected synchronized int | assignDocumentNumber()NON-DOM: increment document/doctype counter
return ++docAndDoctypeCounter;
| final void | checkQName(java.lang.String qname)
int index = qname.indexOf(':");
int lastIndex = qname.lastIndexOf(':");
int length = qname.length();
// it is an error for NCName to have more than one ':'
// check if it is valid QName [Namespace in XML production 6]
if (index == 0 || index == length - 1 || lastIndex != index) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
int start = 0;
// Namespace in XML production [6]
if (index > 0) {
// check that prefix is NCName
if (!XMLChar.isNCNameStart(qname.charAt(start))) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"INVALID_CHARACTER_ERR",
null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
for (int i = 1; i < index; i++) {
if (!XMLChar.isNCName(qname.charAt(i))) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"INVALID_CHARACTER_ERR",
null);
throw new DOMException(
DOMException.INVALID_CHARACTER_ERR,
msg);
}
}
start = index + 1;
}
// check local part
if (!XMLChar.isNCNameStart(qname.charAt(start))) {
// REVISIT: add qname parameter to the message
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"INVALID_CHARACTER_ERR",
null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
for (int i = start + 1; i < length; i++) {
if (!XMLChar.isNCName(qname.charAt(i))) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"INVALID_CHARACTER_ERR",
null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
}
| public org.w3c.dom.Document | createDocument(java.lang.String namespaceURI, java.lang.String qualifiedName, org.w3c.dom.DocumentType doctype)Introduced in DOM Level 2.
Creates an XML Document object of the specified type with its document
element.
if (doctype != null && doctype.getOwnerDocument() != null) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"WRONG_DOCUMENT_ERR",
null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
}
CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
Element e = doc.createElementNS(namespaceURI, qualifiedName);
doc.appendChild(e);
return doc;
| public org.w3c.dom.DocumentType | createDocumentType(java.lang.String qualifiedName, java.lang.String publicID, java.lang.String systemID)Introduced in DOM Level 2.
Creates an empty DocumentType node.
// REVISIT: this might allow creation of invalid name for DOCTYPE
// xmlns prefix.
// also there is no way for a user to turn off error checking.
checkQName(qualifiedName);
return new DocumentTypeImpl(null, qualifiedName, publicID, systemID);
| public org.w3c.dom.ls.LSInput | createLSInput()DOM Level 3 LS CR - Experimental.
Create a new empty input source.
return new DOMInputImpl();
| public org.w3c.dom.ls.LSOutput | createLSOutput()
return new DOMOutputImpl();
| public org.w3c.dom.ls.LSParser | createLSParser(short mode, java.lang.String schemaType)DOM Level 3 LS CR - Experimental.
Create a new LSParser . The newly constructed parser may
then be configured by means of its DOMConfiguration
object, and used to parse documents by means of its parse
method.
if (mode != DOMImplementationLS.MODE_SYNCHRONOUS || (schemaType !=null &&
!"http://www.w3.org/2001/XMLSchema".equals(schemaType) &&
!"http://www.w3.org/TR/REC-xml".equals(schemaType))) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NOT_SUPPORTED_ERR",
null);
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
if (schemaType != null
&& schemaType.equals("http://www.w3.org/TR/REC-xml")) {
return new DOMParserImpl(
"com.sun.org.apache.xerces.internal.parsers.XML11Configuration",
schemaType);
}
else {
// create default parser configuration validating against XMLSchemas
return new DOMParserImpl(
"com.sun.org.apache.xerces.internal.parsers.XML11Configuration",
schemaType);
}
| public org.w3c.dom.ls.LSSerializer | createLSSerializer()DOM Level 3 LS CR - Experimental.
Create a new LSSerializer object.
return new DOMSerializerImpl();
| public static org.w3c.dom.DOMImplementation | getDOMImplementation()NON-DOM: Obtain and return the single shared object
//
// Public methods
//
return singleton;
| synchronized java.lang.Object | getDTDValidator()
return ObjectFactory.newInstance( "com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator", ObjectFactory.findClassLoader(), true);
| public java.lang.Object | getFeature(java.lang.String feature, java.lang.String version)DOM Level 3 WD - Experimental.
if (singleton.hasFeature(feature, version)){
return singleton;
}
return null;
| synchronized com.sun.org.apache.xerces.internal.impl.RevalidationHandler | getValidator(java.lang.String schemaType)NON-DOM: retrieve validator.
// REVISIT: implement retrieving DTD validator
if (freeValidatorIndex < 0) {
// create new validator - we should not attempt
// to restrict the number of validation handlers being
// requested
return (RevalidationHandler) (ObjectFactory .newInstance( "com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator", ObjectFactory.findClassLoader(), true));
}
// return first available validator
RevalidationHandler val = validators[freeValidatorIndex];
validators[freeValidatorIndex--] = null;
return val;
| public boolean | hasFeature(java.lang.String feature, java.lang.String version)Test if the DOM implementation supports a specific "feature" --
currently meaning language and level thereof.
boolean anyVersion = version == null || version.length() == 0;
if (feature.startsWith("+")) {
feature = feature.substring(1);
}
// check if Xalan implementation is around and if yes report true for supporting
// XPath API
if ((feature.equalsIgnoreCase("XPath")
|| feature.equalsIgnoreCase("+XPath"))
&& (anyVersion || version.equals("3.0"))) {
try {
Class xpathClass =
ObjectFactory.findProviderClass(
"com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl",
ObjectFactory.findClassLoader(),
true);
} catch (Exception e) {
return false;
}
return true;
}
return (
feature.equalsIgnoreCase("Core")
&& (anyVersion
|| version.equals("1.0")
|| version.equals("2.0")
|| version.equals("3.0")))
|| (feature.equalsIgnoreCase("XML")
&& (anyVersion
|| version.equals("1.0")
|| version.equals("2.0")
|| version.equals("3.0")))
|| (feature.equalsIgnoreCase("LS")
&& (anyVersion || version.equals("3.0")));
| synchronized void | releaseValidator(java.lang.String schemaType, com.sun.org.apache.xerces.internal.impl.RevalidationHandler validator)NON-DOM: release validator
// REVISIT: implement support for DTD validators as well
++freeValidatorIndex;
if (validators.length == freeValidatorIndex ){
// resize size of the validators
currentSize+=SIZE;
RevalidationHandler newarray[] = new RevalidationHandler[currentSize];
System.arraycopy(validators, 0, newarray, 0, validators.length);
validators = newarray;
}
validators[freeValidatorIndex]=validator;
|
|