当前位置: 首页>>代码示例>>Java>>正文


Java ValidatorHandler.setFeature方法代码示例

本文整理汇总了Java中javax.xml.validation.ValidatorHandler.setFeature方法的典型用法代码示例。如果您正苦于以下问题:Java ValidatorHandler.setFeature方法的具体用法?Java ValidatorHandler.setFeature怎么用?Java ValidatorHandler.setFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.validation.ValidatorHandler的用法示例。


在下文中一共展示了ValidatorHandler.setFeature方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseAndValidate

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
/**
 * Parse and Validate an XML represented by the input stream against provided XSD and reports validation issues.
 *
 * @param input XML to parse and validate
 * @param vHandler Validator handler
 * @throws IOException If a IO error occurs during XML parsing.
 * @throws XmlParseException If a SAX error occurs during XML parsing.
 */
protected void parseAndValidate(InputStream input, ValidatorHandler vHandler) throws XmlParseException, IOException {
    vHandler.setErrorHandler(this);

    InputSource is = new InputSource(new InputStreamReader(input, "UTF-8"));
    is.setEncoding("UTF-8");

    try {
        XMLReader parser = XMLReaderFactory.createXMLReader();
        parser.setContentHandler(vHandler);
        parser.setErrorHandler(this);

        vHandler.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);

        // Commented out the following line, as Java 1.6.0_45 throws an exception on this.
        //parser.setFeature("http://apache.org/xml/features/validation/id-idref-checking", false);
        parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
        parser.setFeature("http://xml.org/sax/features/external-general-entities", false);
        parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

        parser.parse(is);
    } catch (SAXException e) {
        throw new XmlParseException(e.getMessage(), e);
    }
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:33,代码来源:EdfiRecordParser.java

示例2: parseAndValidate

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
private void parseAndValidate(InputStream input, Schema schema) throws XmlParseException, IOException {
    ValidatorHandler vHandler = schema.newValidatorHandler();
    vHandler.setContentHandler(this);
    vHandler.setErrorHandler(this);

    InputSource is = new InputSource(new InputStreamReader(input, "UTF-8"));
    is.setEncoding("UTF-8");

    try {
        XMLReader parser = XMLReaderFactory.createXMLReader();
        parser.setContentHandler(vHandler);
        parser.setErrorHandler(this);

        vHandler.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);

        parser.setFeature("http://apache.org/xml/features/validation/id-idref-checking", false);
        parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", false);
        parser.setFeature("http://xml.org/sax/features/external-general-entities", false);
        parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

        parser.parse(is);
    } catch (SAXException e) {
        throw new XmlParseException(e.getMessage(), e);
    }
}
 
开发者ID:inbloom,项目名称:secure-data-service,代码行数:26,代码来源:EdfiRecordParserImpl2.java

示例3: test1

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test
public void test1() throws Exception {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    ValidatorHandler validatorHandler = schemaFactory.newSchema().newValidatorHandler();
    validatorHandler.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
    validatorHandler.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:Bug4970400.java

示例4: test

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    ValidatorHandler validatorHandler = schemaFactory.newSchema().newValidatorHandler();
    try {
        validatorHandler.setFeature(null, false);
        Assert.fail("should report an error");
    } catch (NullPointerException e) {
        ; // expected
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:Bug4970383.java

示例5: testFeature

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
public void testFeature() throws SAXNotRecognizedException, SAXNotSupportedException {
    ValidatorHandler validatorHandler = getValidatorHandler();
    assertFalse(validatorHandler.getFeature(FEATURE_NAME), "The feature should be false by default.");

    validatorHandler.setFeature(FEATURE_NAME, true);
    assertTrue(validatorHandler.getFeature(FEATURE_NAME), "The feature should be false by default.");

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ValidatorHandlerTest.java

示例6: testSetNullFeature

import javax.xml.validation.ValidatorHandler; //导入方法依赖的package包/类
@Test(expectedExceptions = NullPointerException.class)
public void testSetNullFeature() throws SAXNotRecognizedException, SAXNotSupportedException {
    ValidatorHandler validatorHandler = getValidatorHandler();
    assertNotNull(validatorHandler);
    validatorHandler.setFeature(null, true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:ValidatorHandlerTest.java


注:本文中的javax.xml.validation.ValidatorHandler.setFeature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。