DomDocumentBuilderFactory.java [plain text]
package gnu.xml.dom;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.DOMConfiguration;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSParser;
public class DomDocumentBuilderFactory
extends DocumentBuilderFactory
{
final DOMImplementation impl;
final DOMImplementationLS ls;
public DomDocumentBuilderFactory()
{
try
{
DOMImplementationRegistry reg =
DOMImplementationRegistry.newInstance();
impl = reg.getDOMImplementation("LS 3.0");
if (impl == null)
{
throw new FactoryConfigurationError("no LS implementations found");
}
ls = (DOMImplementationLS) impl;
}
catch (Exception e)
{
throw new FactoryConfigurationError(e);
}
}
public DocumentBuilder newDocumentBuilder()
throws ParserConfigurationException
{
LSParser parser = ls.createLSParser(DOMImplementationLS.MODE_ASYNCHRONOUS,
"http://www.w3.org/TR/REC-xml");
DOMConfiguration config = parser.getDomConfig();
setParameter(config, "namespaces",
isNamespaceAware() ? Boolean.TRUE : Boolean.FALSE);
setParameter(config, "element-content-whitespace",
isIgnoringElementContentWhitespace() ? Boolean.FALSE :
Boolean.TRUE);
setParameter(config, "comments",
isIgnoringComments() ? Boolean.FALSE : Boolean.TRUE);
setParameter(config, "expand-entity-references",
isExpandEntityReferences() ? Boolean.TRUE : Boolean.FALSE);
setParameter(config, "coalescing",
isCoalescing() ? Boolean.TRUE : Boolean.FALSE);
setParameter(config, "validating",
isValidating() ? Boolean.TRUE : Boolean.FALSE);
setParameter(config, "xinclude-aware",
isXIncludeAware() ? Boolean.TRUE : Boolean.FALSE);
return new DomDocumentBuilder(impl, ls, parser);
}
void setParameter(DOMConfiguration config, String name, Object value)
throws ParserConfigurationException
{
if (!config.canSetParameter(name, value))
{
throw new ParserConfigurationException(name);
}
config.setParameter(name, value);
}
public Object getAttribute(String name)
{
return null;
}
public void setAttribute(String name, Object value)
{
}
}