use of org.w3c.dom.DOMError in project robovm by robovm.
the class NormalizeTest method testErrorHandler.
public void testErrorHandler() {
assertEquals(null, domConfiguration.getParameter("error-handler"));
assertSupported("error-handler", null);
assertSupported("error-handler", new DOMErrorHandler() {
public boolean handleError(DOMError error) {
return true;
}
});
}
use of org.w3c.dom.DOMError in project intellij-community by JetBrains.
the class XSDModelLoader method loadSchema.
private XSModel loadSchema(File schemaFile, XMLEntityResolver resolver) throws Exception {
// get DOM Implementation using DOM Registry
System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");
XSLoader schemaLoader = impl.createXSLoader(null);
DOMConfiguration config = schemaLoader.getConfig();
// create Error Handler
DOMErrorHandler errorHandler = new DOMErrorHandler() {
public boolean handleError(DOMError domError) {
Util.log("DOMError: " + domError.getMessage());
Object relatedException = domError.getRelatedException();
if (relatedException != null) {
Util.log("DOMError: " + relatedException);
if (relatedException instanceof Throwable) {
((Throwable) relatedException).printStackTrace(System.out);
}
}
return false;
}
};
// set error handler
config.setParameter("error-handler", errorHandler);
// set validation feature
config.setParameter("validate", Boolean.TRUE);
// parse document
config.setParameter("error-handler", errorHandler);
config.setParameter("http://apache.org/xml/properties/internal/entity-resolver", resolver);
XSModel model = schemaLoader.loadURI(schemaFile.getAbsolutePath());
if (model == null)
return null;
XSNamedMap components = model.getComponents(XSConstants.ELEMENT_DECLARATION);
for (int i = 0; i < components.getLength(); i++) {
XSObject obj = components.item(i);
QName qname = new QName(obj.getNamespace(), obj.getName());
String file = this.model.qname2FileMap.get(qname);
this.model.qname2FileMap.put(qname, (file == null ? "" : file + ";") + schemaFile.getName());
}
components = model.getComponents(XSConstants.TYPE_DEFINITION);
for (int i = 0; i < components.getLength(); i++) {
XSObject obj = components.item(i);
QName qname = new QName(obj.getNamespace(), obj.getName());
String file = this.model.qname2FileMap.get(qname);
this.model.qname2FileMap.put(qname, (file == null ? "" : file) + ":" + schemaFile.getName() + ":");
}
return model;
}
use of org.w3c.dom.DOMError in project ACS by ACS-Community.
the class HibernateWDALImpl method initializeParser.
private void initializeParser() throws RuntimeException {
try {
System.setProperty(DOMImplementationRegistry.PROPERTY, "org.apache.xerces.dom.DOMImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
domImplementationLS = (DOMImplementationLS) registry.getDOMImplementation("LS");
parser = domImplementationLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, "http://www.w3.org/2001/XMLSchema");
//parser.getDomConfig().setParameter("http://apache.org/xml/features/xinclude", Boolean.TRUE);
schemaResourceResolverLoader = new SchemaResourceResolverLoader(null, domImplementationLS, m_logger);
parser.getDomConfig().setParameter("resource-resolver", schemaResourceResolverLoader);
parser.getDomConfig().setParameter("http://apache.org/xml/features/validation/schema", Boolean.TRUE);
parser.getDomConfig().setParameter("error-handler", new DOMErrorHandler() {
public boolean handleError(DOMError error) {
//((Exception) error.getRelatedException()).printStackTrace();
throw new LSException(LSException.PARSE_ERR, error.getMessage());
}
});
input = domImplementationLS.createLSInput();
output = domImplementationLS.createLSOutput();
// SAX parser (non-validating)
SAXParserFactory factory = SAXParserFactory.newInstance();
saxParser = factory.newSAXParser();
} catch (Throwable th) {
throw new RuntimeException("Failed to initialize parser.", th);
}
}
Aggregations