use of org.w3c.dom.ls.LSResourceResolver in project camel by apache.
the class ValidatorWithResourceResolverRouteTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
// we have to do it here, because we need the context created first
CatalogManager.getStaticManager().setIgnoreMissingProperties(true);
CatalogResolver catalogResolver = new CatalogResolver(true);
URL catalogUrl = ResourceHelper.resolveMandatoryResourceAsUrl(context.getClassResolver(), "org/apache/camel/component/validator/catalog.cat");
catalogResolver.getCatalog().parseCatalog(catalogUrl);
LSResourceResolver resourceResolver = new CatalogLSResourceResolver(catalogResolver);
JndiRegistry registry = (JndiRegistry) ((PropertyPlaceholderDelegateRegistry) context.getRegistry()).getRegistry();
registry.bind("resourceResolver", resourceResolver);
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").doTry().to("validator:org/apache/camel/component/validator/report.xsd?resourceResolver=#resourceResolver").to("mock:valid").doCatch(ValidationException.class).to("mock:invalid").doFinally().to("mock:finally").end();
}
};
}
use of org.w3c.dom.ls.LSResourceResolver in project santuario-java by apache.
the class XMLSecurityUtils method loadXMLSecuritySchemas.
public static Schema loadXMLSecuritySchemas() throws SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolver() {
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
if ("http://www.w3.org/2001/XMLSchema.dtd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class));
return concreteLSInput;
} else if ("XMLSchema.dtd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class));
return concreteLSInput;
} else if ("datatypes.dtd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("bindings/schemas/datatypes.dtd", XMLSecurityConstants.class));
return concreteLSInput;
} else if ("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd", XMLSecurityConstants.class));
return concreteLSInput;
} else if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
ConcreteLSInput concreteLSInput = new ConcreteLSInput();
concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xml.xsd", XMLSecurityConstants.class));
return concreteLSInput;
}
return null;
}
});
Schema schema = schemaFactory.newSchema(new Source[] { new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/exc-c14n.xsd", XMLSecurityConstants.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd", XMLSecurityConstants.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xenc-schema.xsd", XMLSecurityConstants.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xenc-schema-11.xsd", XMLSecurityConstants.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig11-schema.xsd", XMLSecurityConstants.class)) });
return schema;
}
use of org.w3c.dom.ls.LSResourceResolver in project cxf by apache.
the class XercesSchemaValidationUtils method tryToParseSchemas.
void tryToParseSchemas(XmlSchemaCollection collection, DOMErrorHandler handler) throws Exception {
final List<DOMLSInput> inputs = new ArrayList<>();
final Map<String, LSInput> resolverMap = new HashMap<>();
for (XmlSchema schema : collection.getXmlSchemas()) {
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
continue;
}
Document document = new XmlSchemaSerializer().serializeSchema(schema, false)[0];
DOMLSInput input = new DOMLSInput(document, schema.getTargetNamespace());
resolverMap.put(schema.getTargetNamespace(), input);
inputs.add(input);
}
try {
Object schemaLoader = findMethod(impl, "createXSLoader").invoke(impl, new Object[1]);
DOMConfiguration config = (DOMConfiguration) findMethod(schemaLoader, "getConfig").invoke(schemaLoader);
config.setParameter("validate", Boolean.TRUE);
config.setParameter("error-handler", handler);
config.setParameter("resource-resolver", new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
return resolverMap.get(namespaceURI);
}
});
Method m = findMethod(schemaLoader, "loadInputList");
String name = m.getParameterTypes()[0].getName() + "Impl";
name = name.replace("xs.LS", "impl.xs.util.LS");
Class<?> c = Class.forName(name);
Object inputList = c.getConstructor(LSInput[].class, Integer.TYPE).newInstance(inputs.toArray(new LSInput[0]), inputs.size());
m.invoke(schemaLoader, inputList);
} catch (InvocationTargetException e) {
throw (Exception) e.getTargetException();
}
}
Aggregations