LSDocumentBuilderFactorypublic class LSDocumentBuilderFactory extends DOMTestDocumentBuilderFactory This class implements the generic parser and configuation
abstract class for the DOM L3 implementations |
Fields Summary |
---|
private final Object | parser | private final Method | parseURIMethod | private final DOMImplementation | impl | private static final Map | strategiesStrategies for mapping DocumentBuilderSettings to
actions on LSParser |
Constructors Summary |
---|
public LSDocumentBuilderFactory(DocumentBuilderSetting[] settings)Creates a LS implementation of DOMTestDocumentBuilderFactory.
strategies = new HashMap();
strategies.put("coalescing", new LSParameterStrategy("cdata-sections", true));
strategies.put("expandEntityReferences", new LSParameterStrategy("entities", true));
strategies.put("ignoringElementContentWhitespace",
new LSParameterStrategy("element-content-whitespace", true));
strategies.put("namespaceAware", new LSParameterStrategy("namespaces", false));
strategies.put("validating",
new LSValidateStrategy("http://www.w3.org/TR/REC-xml"));
strategies.put("schemaValidating",
new LSValidateStrategy("http://www.w3.org/2001/XMLSchema"));
strategies.put("ignoringComments", new LSParameterStrategy("comments", true));
strategies.put("signed", new LSFixedStrategy(true));
strategies.put("hasNullString", new LSFixedStrategy(true));
super(settings);
try {
Class domImplRegistryClass = Class.forName(
"org.w3c.dom.bootstrap.DOMImplementationRegistry");
Method newInstanceMethod = domImplRegistryClass.getMethod("newInstance", null);
Object domRegistry = newInstanceMethod.invoke(null, null);
Method getDOMImplementationMethod = domImplRegistryClass.getMethod(
"getDOMImplementation", new Class[] {String.class});
impl = (DOMImplementation) getDOMImplementationMethod.invoke(domRegistry,
new Object[] {"LS"});
Method createLSParserMethod = impl.getClass().getMethod("createLSParser",
new Class[] {short.class, String.class});
parser = createLSParserMethod.invoke(impl,
new Object[] {new Short( (short) 1), null});
parseURIMethod = parser.getClass().getMethod("parseURI",
new Class[] {String.class});
}
catch (InvocationTargetException ex) {
throw new DOMTestIncompatibleException(ex.getTargetException(), null);
}
catch (Exception ex) {
throw new DOMTestIncompatibleException(ex, null);
}
if (settings != null) {
for (int i = 0; i < settings.length; i++) {
Object strategy = strategies.get(settings[i].getProperty());
if (strategy == null) {
throw new DOMTestIncompatibleException(null, settings[i]);
}
else {
( (LSStrategy) strategy).applySetting(settings[i], parser);
}
}
}
|
Methods Summary |
---|
public org.w3c.dom.DOMImplementation | getDOMImplementation()Gets DOMImplementation
return impl;
| public boolean | hasFeature(java.lang.String feature, java.lang.String version)Determines if the implementation supports the specified feature
return getDOMImplementation().hasFeature(feature, version);
| private boolean | hasProperty(java.lang.String parameter)
try {
return ( (Boolean) LSParameterStrategy.getParameter(parser, parameter)).
booleanValue();
}
catch (Exception ex) {
return true;
}
| public boolean | isCoalescing()Indicates whether the implementation combines text and cdata nodes.
return!hasProperty("cdata-sections");
| public boolean | isExpandEntityReferences()Indicates whether the implementation expands entity references.
return!hasProperty("entities");
| public boolean | isIgnoringElementContentWhitespace()Indicates whether the implementation ignores
element content whitespace.
return!hasProperty("element-content-whitespace");
| public boolean | isNamespaceAware()Indicates whether the implementation is namespace aware.
return hasProperty("namespaces");
| public boolean | isValidating()Indicates whether the implementation is validating.
return hasProperty("validate");
| public org.w3c.dom.Document | load(java.net.URL url)Loads specified URL
try {
return (Document) parseURIMethod.invoke(parser,
new Object[] {url.toString()});
}
catch (InvocationTargetException ex) {
throw new DOMTestLoadException(ex.getTargetException());
}
catch (Exception ex) {
throw new DOMTestLoadException(ex);
}
| public DOMTestDocumentBuilderFactory | newInstance(DocumentBuilderSetting[] newSettings)Create new instance of document builder factory
reflecting specified settings
if (newSettings == null) {
return this;
}
DocumentBuilderSetting[] mergedSettings = mergeSettings(newSettings);
return new LSDocumentBuilderFactory(mergedSettings);
|
|