本文整理汇总了Java中javax.xml.validation.Validator.setFeature方法的典型用法代码示例。如果您正苦于以下问题:Java Validator.setFeature方法的具体用法?Java Validator.setFeature怎么用?Java Validator.setFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.validation.Validator
的用法示例。
在下文中一共展示了Validator.setFeature方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSecureProcessingFeaturePropagationAndReset
import javax.xml.validation.Validator; //导入方法依赖的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: testFeatureReset
import javax.xml.validation.Validator; //导入方法依赖的package包/类
@Test
public void testFeatureReset() throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = makeSchema(factory, null);
Validator validator = schema.newValidator();
validator.setFeature(FEATURE_STRING_DEFAULT_TRUE, false);
validator.setFeature(FEATURE_STRING_DEFAULT_FALSE, true);
validator.reset();
boolean value = validator.getFeature(FEATURE_STRING_DEFAULT_TRUE);
assertTrue("After reset, value of feature on Validator should be true.", value);
value = validator.getFeature(FEATURE_STRING_DEFAULT_FALSE);
assertFalse("After reset, value of feature on Validator should be false.", value);
}
示例3: test02
import javax.xml.validation.Validator; //导入方法依赖的package包/类
@Test
public void test02() throws SAXException {
Validator validator = schemaFactory.newSchema().newValidator();
try {
validator.setFeature(null, false);
Assert.fail("exception expected");
} catch (NullPointerException e) {
;
}
}
示例4: testValidator
import javax.xml.validation.Validator; //导入方法依赖的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: testSetUnrecognizedFeature
import javax.xml.validation.Validator; //导入方法依赖的package包/类
@Test(expectedExceptions = SAXNotRecognizedException.class)
public void testSetUnrecognizedFeature() throws SAXNotRecognizedException, SAXNotSupportedException {
Validator validator = getValidator();
validator.setFeature(UNRECOGNIZED_NAME, true);
}
示例6: testSetNullFeature
import javax.xml.validation.Validator; //导入方法依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void testSetNullFeature() throws SAXNotRecognizedException, SAXNotSupportedException {
Validator validator = getValidator();
assertNotNull(validator);
validator.setFeature(null, true);
}