use of org.w3c.dom.DOMConfiguration in project webservices-axiom by apache.
the class TestGetDomConfigDefaults method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
DOMConfiguration domConfig = document.getDomConfig();
assertEquals(Boolean.FALSE, domConfig.getParameter("canonical-form"));
assertEquals(Boolean.TRUE, domConfig.getParameter("cdata-sections"));
assertEquals(Boolean.FALSE, domConfig.getParameter("check-character-normalization"));
assertEquals(Boolean.TRUE, domConfig.getParameter("comments"));
assertEquals(Boolean.FALSE, domConfig.getParameter("datatype-normalization"));
assertEquals(Boolean.TRUE, domConfig.getParameter("element-content-whitespace"));
assertEquals(Boolean.TRUE, domConfig.getParameter("entities"));
assertEquals(Boolean.TRUE, domConfig.getParameter("namespaces"));
assertEquals(Boolean.TRUE, domConfig.getParameter("namespace-declarations"));
assertEquals(Boolean.FALSE, domConfig.getParameter("normalize-characters"));
assertEquals(Boolean.TRUE, domConfig.getParameter("split-cdata-sections"));
assertEquals(Boolean.FALSE, domConfig.getParameter("validate"));
assertEquals(Boolean.FALSE, domConfig.getParameter("validate-if-schema"));
assertEquals(Boolean.TRUE, domConfig.getParameter("well-formed"));
}
use of org.w3c.dom.DOMConfiguration 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.DOMConfiguration in project webservices-axiom by apache.
the class TestNormalizeDocumentNamespace method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().newDocument();
Element element = document.createElementNS("urn:ns", "root");
document.appendChild(element);
DOMConfiguration domConfig = document.getDomConfig();
domConfig.setParameter("split-cdata-sections", Boolean.FALSE);
domConfig.setParameter("well-formed", Boolean.FALSE);
domConfig.setParameter("namespaces", Boolean.TRUE);
document.normalizeDocument();
NamedNodeMap attributes = element.getAttributes();
assertEquals(1, attributes.getLength());
Attr attr = (Attr) attributes.item(0);
assertNull(attr.getPrefix());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE, attr.getLocalName());
assertEquals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, attr.getNamespaceURI());
assertEquals("urn:ns", attr.getValue());
}
Aggregations