本文整理汇总了Java中org.w3c.dom.ls.LSResourceResolver类的典型用法代码示例。如果您正苦于以下问题:Java LSResourceResolver类的具体用法?Java LSResourceResolver怎么用?Java LSResourceResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LSResourceResolver类属于org.w3c.dom.ls包,在下文中一共展示了LSResourceResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
private void validate(WSDLModel model,
Source saxSource,
XsdBasedValidator.Handler handler,
LSResourceResolver resolver) {
try {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
if (resolver != null) {
sf.setResourceResolver(resolver);
}
sf.setErrorHandler(handler);
if (saxSource == null) {
return;
}
sf.newSchema(saxSource);
} catch(SAXException sax) {
//already processed by handler
} catch(Exception ex) {
handler.logValidationErrors(Validator.ResultType.ERROR, ex.getMessage());
}
}
示例2: resolveResource
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
LSInput input = null;
Iterator<ValidatorSchemaFactory> it = mExtSchemaFactories.iterator();
while(it.hasNext()) {
ValidatorSchemaFactory fac = it.next();
LSResourceResolver resolver = fac.getLSResourceResolver();
if(resolver != null) {
input = resolver.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
if(input != null) {
break;
}
}
}
return input;
}
示例3: getCompiledSchema
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
/**
* Subclasses can use this to get a compiled schema object.
* @param schemas Input stream of schemas.
* @param lsResourceResolver resolver can be supplied optionally. Otherwise pass null.
* @return Compiled Schema object.
*/
protected Schema getCompiledSchema(InputStream[] schemas,
LSResourceResolver lsResourceResolver) {
Schema schema = null;
// Convert InputStream[] to StreamSource[]
StreamSource[] schemaStreamSources = new StreamSource[schemas.length];
for(int index1=0 ; index1<schemas.length ; index1++)
schemaStreamSources[index1] = new StreamSource(schemas[index1]);
// Create a compiled Schema object.
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(lsResourceResolver);
try {
schema = schemaFactory.newSchema(schemaStreamSources);
} catch(SAXException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "getCompiledSchema", ex);
}
return schema;
}
示例4: testValidation
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
public void testValidation(boolean setUseCatalog, boolean useCatalog, String catalog,
String xsd, LSResourceResolver resolver)
throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// use resolver or catalog if resolver = null
if (resolver != null) {
factory.setResourceResolver(resolver);
}
if (setUseCatalog) {
factory.setFeature(XMLConstants.USE_CATALOG, useCatalog);
}
factory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog);
Schema schema = factory.newSchema(new StreamSource(new StringReader(xsd)));
success("XMLSchema.dtd and datatypes.dtd are resolved.");
}
示例5: createSchema
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
/**
* Creates the schema.
*
* @param xsdInputStream the xsd input stream
* @param resourceResolver the resource resolver
* @return the schema
* @throws XmlSchemaFailureException the xml schema failure exception
*/
private Schema createSchema(InputStream xsdInputStream,
LSResourceResolver resourceResolver)
throws XmlSchemaFailureException {
final SchemaFactory factory = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final Source schemaSource = new StreamSource(xsdInputStream);
if (resourceResolver != null) {
factory.setResourceResolver(resourceResolver);
}
Schema schema;
try {
schema = factory.newSchema(schemaSource);
} catch (final SAXException e) {
logger.error(e.getMessage());
throw new XmlSchemaFailureException(e);
}
return schema;
}
示例6: createRouteBuilder
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
@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();
}
};
}
示例7: testInstanceResourceResolver
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
@Test
public void testInstanceResourceResolver() throws SAXException, IOException {
SchemaFactory f = factory();
Validator v = f.newSchema(charStreamSource(element("doc", element("inner")))).newValidator();
Assert.assertNull(v.getResourceResolver());
LSResourceResolver rr = new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
// In Java 5 Xerces absolutized the systemId relative to the current directory
int slashIndex = systemId.lastIndexOf('/');
if (slashIndex >= 0)
systemId = systemId.substring(slashIndex + 1);
Assert.assertEquals(systemId, "e.xml");
Assert.assertEquals(type, "http://www.w3.org/TR/REC-xml");
LSInput in = new LSInputImpl();
in.setStringData("<inner/>");
return in;
}
};
v.setResourceResolver(rr);
Assert.assertSame(v.getResourceResolver(), rr);
v.validate(charStreamSource("<!DOCTYPE doc [ <!ENTITY e SYSTEM 'e.xml'> ]><doc>&e;</doc>"));
}
示例8: testSchemaResourceResolver
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
@Test
public void testSchemaResourceResolver() throws SAXException, IOException {
SchemaFactory f = factory();
Assert.assertNull(f.getResourceResolver());
LSResourceResolver rr = new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
Assert.assertEquals(systemId, "myschema");
Assert.assertEquals(type, getLSType());
Assert.assertNull(baseURI);
Assert.assertNull(namespaceURI);
Assert.assertNull(publicId);
LSInput in = new LSInputImpl();
in.setStringData(createSchema("doc"));
return in;
}
};
f.setResourceResolver(rr);
Assert.assertSame(f.getResourceResolver(), rr);
Validator v = f.newSchema(charStreamSource(externalRef("myschema"))).newValidator();
v.validate(charStreamSource("<doc/>"));
}
示例9: XSParser
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
public XSParser(LSResourceResolver entityResolver, DOMErrorHandler errorHandler){
System.setProperty(DOMImplementationRegistry.PROPERTY, DOMXSImplementationSourceImpl.class.getName());
DOMImplementationRegistry registry;
try{
registry = DOMImplementationRegistry.newInstance();
}catch(Exception ex){
throw new ImpossibleException(ex);
}
XSImplementationImpl xsImpl = (XSImplementationImpl)registry.getDOMImplementation("XS-Loader");
xsLoader = xsImpl.createXSLoader(null);
DOMConfiguration config = xsLoader.getConfig();
config.setParameter(Constants.DOM_VALIDATE, Boolean.TRUE);
if(entityResolver!=null)
config.setParameter(Constants.DOM_RESOURCE_RESOLVER, entityResolver);
if(errorHandler!=null)
config.setParameter(Constants.DOM_ERROR_HANDLER, errorHandler);
}
示例10: isValidFacesConfig
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
/**
* Validates *.faces-config.xml file
*
* @param xml
* @return
*/
private boolean isValidFacesConfig(InputStream xml) {
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver((LSResourceResolver) DbfFactory.FACES_ENTITY_RESOLVER);
InputStream xsd = this.getClass().getResourceAsStream(FACES_2_2_XSD);
Schema schema = factory.newSchema(new StreamSource(xsd));
Validator validator = schema.newValidator();
validator.validate(new StreamSource(xml));
return true;
} catch (Exception ex) {
return false;
}
}
示例11: getLSResourceResolver
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
public static LSResourceResolver getLSResourceResolver() throws Exception {
logger.info("");
LSResourceResolver resourceResolver = new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceUri,
String publicId, String systemId, String baseUri) {
try {
final InputStream in = GXmlEntity.class.getResource(
"/" + systemId).openStream();
LSInputAdapter adapter = new LSInputAdapter(in);
return adapter;
}
catch (Exception exception) {
exception.printStackTrace();
return null;
}
}
};
return resourceResolver;
}
示例12: getLSResourceResolver
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
private static LSResourceResolver getLSResourceResolver() throws Exception {
logger.info("");
LSResourceResolver resourceResolver = new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceUri,
String publicId, String systemId, String baseUri) {
try {
final InputStream in = GXmlEntity.class.getResource(
"/" + systemId).openStream();
LSInputAdapter adapter = new LSInputAdapter(in);
return adapter;
}
catch (Exception exception) {
logger.error(GStringUtils.stackTraceToString(exception));
return null;
}
}
};
return resourceResolver;
}
示例13: test1
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
@Test
public void test1() throws Exception {
String xsd1 = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n" + " xmlns:test='jaxp13_test1'\n"
+ " targetNamespace='jaxp13_test1'\n" + " elementFormDefault='qualified'>\n" + " <import namespace='jaxp13_test2'/>\n"
+ " <element name='test'/>\n" + " <element name='child1'/>\n" + "</schema>\n";
final NullPointerException EUREKA = new NullPointerException("NewSchema015");
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
StringReader reader = new StringReader(xsd1);
StreamSource source = new StreamSource(reader);
LSResourceResolver resolver = new LSResourceResolver() {
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
LSInput input;
if (namespaceURI != null && namespaceURI.endsWith("jaxp13_test2")) {
throw EUREKA;
} else {
input = null;
}
return input;
}
};
schemaFactory.setResourceResolver(resolver);
try {
schemaFactory.newSchema(new Source[] { source });
Assert.fail("NullPointerException was not thrown.");
} catch (RuntimeException e) {
if (e != EUREKA)
throw e;
}
}
示例14: testValidationA
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
@Test(dataProvider = "data_SchemaA")
public void testValidationA(boolean setUseCatalog, boolean useCatalog,
String catalog, String xsd, LSResourceResolver resolver)
throws Exception {
testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ;
}
示例15: testValidatorA
import org.w3c.dom.ls.LSResourceResolver; //导入依赖的package包/类
@Test(dataProvider = "data_ValidatorA")
public void testValidatorA(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
String catalog1, String catalog2)
throws Exception {
testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source,
resolver1, resolver2, catalog1, catalog2);
}