本文整理汇总了Java中javax.xml.validation.SchemaFactory.setResourceResolver方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaFactory.setResourceResolver方法的具体用法?Java SchemaFactory.setResourceResolver怎么用?Java SchemaFactory.setResourceResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.validation.SchemaFactory
的用法示例。
在下文中一共展示了SchemaFactory.setResourceResolver方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import javax.xml.validation.SchemaFactory; //导入方法依赖的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: getCompiledSchema
import javax.xml.validation.SchemaFactory; //导入方法依赖的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;
}
示例3: validate
import javax.xml.validation.SchemaFactory; //导入方法依赖的package包/类
@Override
protected void validate(Model model, Schema schema, XsdBasedValidator.Handler handler) {
try {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
CatalogModel cm = (CatalogModel) model.getModelSource().getLookup()
.lookup(CatalogModel.class);
if (cm != null) {
sf.setResourceResolver(cm);
}
sf.setErrorHandler(handler);
Source saxSource = getSource(model, 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());
}
}
示例4: testValidation
import javax.xml.validation.SchemaFactory; //导入方法依赖的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: newValidator
import javax.xml.validation.SchemaFactory; //导入方法依赖的package包/类
public ValidatorHandler newValidator() {
if (schema==null) {
synchronized (this) {
if (schema == null) {
ResourceResolver resourceResolver = null;
try (InputStream is = clazz.getResourceAsStream(resourceName)) {
StreamSource source = new StreamSource(is);
source.setSystemId(resourceName);
// do not disable secure processing - these are well-known schemas
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
SchemaFactory schemaFactory = allowExternalAccess(sf, "file", false);
if (createResolver) {
resourceResolver = new ResourceResolver(clazz);
schemaFactory.setResourceResolver(resourceResolver);
}
schema = schemaFactory.newSchema(source);
} catch (IOException | SAXException e) {
InternalError ie = new InternalError(e.getMessage());
ie.initCause(e);
throw ie;
} finally {
if (resourceResolver != null) resourceResolver.closeStreams();
}
}
}
}
return schema.newValidatorHandler();
}
示例6: test1
import javax.xml.validation.SchemaFactory; //导入方法依赖的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;
}
}
示例7: testValidator
import javax.xml.validation.SchemaFactory; //导入方法依赖的package包/类
/**
* Verifies Catalog Support for the Validator.
* @param setUseCatalog1 a flag to indicate whether USE_CATALOG shall be set
* on the factory.
* @param setUseCatalog2 a flag to indicate whether USE_CATALOG shall be set
* on the Validator.
* @param source the XML source
* @param resolver1 a resolver to be set on the factory if specified
* @param resolver2 a resolver to be set on the Validator if specified
* @param catalog1 a catalog to be set on the factory if specified
* @param catalog2 a catalog to be set on the Validator if specified
*/
public void testValidator(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
String catalog1, String catalog2)
throws Exception {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
if (setUseCatalog1) {
schemaFactory.setFeature(XMLConstants.USE_CATALOG, useCatalog);
}
if (catalog1 != null) {
schemaFactory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog1);
}
if (resolver1 != null) {
schemaFactory.setResourceResolver(resolver1);
}
Schema schema = schemaFactory.newSchema();
Validator validator = schema.newValidator();
if (setUseCatalog2) {
validator.setFeature(XMLConstants.USE_CATALOG, useCatalog);
}
if (catalog2 != null) {
validator.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog2);
}
if (resolver2 != null) {
validator.setResourceResolver(resolver2);
}
validator.validate(source);
}
示例8: supportLSResourceResolver
import javax.xml.validation.SchemaFactory; //导入方法依赖的package包/类
@Test(dataProvider = "supportLSResourceResolver")
public void supportLSResourceResolver(URI catalogFile, Source schemaSource) throws SAXException {
CatalogResolver cr = CatalogManager.catalogResolver(CatalogFeatures.defaults(), catalogFile);
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setResourceResolver(cr);
Schema schema = factory.newSchema(schemaSource);
}