本文整理匯總了Java中javax.xml.validation.SchemaFactory.setFeature方法的典型用法代碼示例。如果您正苦於以下問題:Java SchemaFactory.setFeature方法的具體用法?Java SchemaFactory.setFeature怎麽用?Java SchemaFactory.setFeature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.validation.SchemaFactory
的用法示例。
在下文中一共展示了SchemaFactory.setFeature方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSecureProcessingFeaturePropagationAndReset
import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test
public void testSecureProcessingFeaturePropagationAndReset() throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
boolean value;
value = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
//default is true for JDK
//assertFalse("Default value of feature on SchemaFactory should have been false.", value);
assertTrue("Default value of feature on SchemaFactory should have been false.", value);
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Schema schema = makeSchema(factory, null);
Validator validator = schema.newValidator();
value = validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
assertTrue("Value of feature on Validator should have been true.", value);
validator.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
value = validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
assertFalse("Value of feature on Validator should have been false.", value);
validator.reset();
value = validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
assertTrue("After reset, value of feature on Validator should be true.", value);
}
示例2: 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.");
}
示例3: testValidation_SAX_withSM
import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test
public void testValidation_SAX_withSM() {
System.out.println("Validation using SAX Source with security manager:");
setSystemProperty(SAX_FACTORY_ID, "MySAXFactoryImpl");
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// should not allow
factory.setFeature(ORACLE_FEATURE_SERVICE_MECHANISM, true);
if ((boolean) factory.getFeature(ORACLE_FEATURE_SERVICE_MECHANISM)) {
Assert.fail("should not override in secure mode");
}
} catch (Exception e) {
Assert.fail(e.getMessage());
} finally {
clearSystemProperty(SAX_FACTORY_ID);
}
}
示例4: 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);
}
示例5: testValidation_SAX_withoutServiceMech
import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test
public void testValidation_SAX_withoutServiceMech() {
System.out.println("Validation using SAX Source; Service mechnism is turned off; SAX Impl should be the default:");
InputSource is = new InputSource(Bug6941169Test.class.getResourceAsStream("Bug6941169.xml"));
SAXSource ss = new SAXSource(is);
setSystemProperty(SAX_FACTORY_ID, "MySAXFactoryImpl");
long start = System.currentTimeMillis();
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setFeature(ORACLE_FEATURE_SERVICE_MECHANISM, false);
Schema schema = factory.newSchema(new StreamSource(_xsd));
Validator validator = schema.newValidator();
validator.validate(ss, null);
} catch (Exception e) {
// e.printStackTrace();
String error = e.getMessage();
if (error.indexOf("javax.xml.parsers.FactoryConfigurationError: Provider MySAXFactoryImpl not found") > 0) {
Assert.fail(e.getMessage());
} else {
System.out.println("Default impl is used");
}
// System.out.println(e.getMessage());
}
long end = System.currentTimeMillis();
double elapsedTime = ((end - start));
System.out.println("Time elapsed: " + elapsedTime);
clearSystemProperty(SAX_FACTORY_ID);
}
示例6: testValidation_SAX_withSM
import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test
public void testValidation_SAX_withSM() throws Exception {
if(System.getSecurityManager() == null)
return;
System.out.println("Validation using SAX Source with security manager:");
InputSource is = new InputSource(Bug6941169Test.class.getResourceAsStream("Bug6941169.xml"));
SAXSource ss = new SAXSource(is);
setSystemProperty(SAX_FACTORY_ID, "MySAXFactoryImpl");
long start = System.currentTimeMillis();
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setFeature(ORACLE_FEATURE_SERVICE_MECHANISM, false);
Schema schema = factory.newSchema(new StreamSource(_xsd));
Validator validator = schema.newValidator();
validator.validate(ss, null);
} catch (Exception e) {
String error = e.getMessage();
if (error.indexOf("javax.xml.parsers.FactoryConfigurationError: Provider MySAXFactoryImpl not found") > 0) {
Assert.fail(e.getMessage());
} else {
System.out.println("Default impl is used");
}
// System.out.println(e.getMessage());
} finally {
clearSystemProperty(SAX_FACTORY_ID);
}
long end = System.currentTimeMillis();
double elapsedTime = ((end - start));
System.out.println("Time elapsed: " + elapsedTime);
}
示例7: testValidation
import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test
public void testValidation() throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setFeature("http://apache.org/xml/features/validate-annotations", true);
factory.newSchema(new File(getClass().getResource("Bug8149915.xsd").getFile()));
}
示例8: testSetUnrecognizedFeature
import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test(expectedExceptions = SAXNotRecognizedException.class)
public void testSetUnrecognizedFeature() throws SAXNotRecognizedException, SAXNotSupportedException {
SchemaFactory sf = newSchemaFactory();
sf.setFeature(UNRECOGNIZED_NAME, true);
}
示例9: testSetNullFeature
import javax.xml.validation.SchemaFactory; //導入方法依賴的package包/類
@Test(expectedExceptions = NullPointerException.class)
public void testSetNullFeature() throws SAXNotRecognizedException, SAXNotSupportedException {
SchemaFactory sf = newSchemaFactory();
assertNotNull(sf);
sf.setFeature(null, true);
}