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


Java Validator.setErrorHandler方法代码示例

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


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

示例1: validateXml

import javax.xml.validation.Validator; //导入方法依赖的package包/类
@SneakyThrows
public void validateXml(String xsdPath, boolean namespaceAware, String schemaLanguage, String pageBody) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setNamespaceAware(namespaceAware);

    DocumentBuilder builder = factory.newDocumentBuilder();
    org.w3c.dom.Document document = builder.parse(new InputSource(new StringReader(pageBody)));

    SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
    Source schemaSource = new StreamSource(getClass().getResourceAsStream(xsdPath));

    Schema schema = schemaFactory.newSchema(schemaSource);
    Validator validator = schema.newValidator();
    Source source = new DOMSource(document);
    validator.setErrorHandler(new XmlErrorHandler());
    validator.validate(source);
}
 
开发者ID:christian-draeger,项目名称:page-content-tester,代码行数:19,代码来源:XmlErrorHandler.java

示例2: validate

import javax.xml.validation.Validator; //导入方法依赖的package包/类
private void validate(final String xsdFile, final Source src, final Result result) throws Exception {
    try {
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(new File(ValidatorTest.class.getResource(xsdFile).toURI()));

        // Get a Validator which can be used to validate instance document
        // against this grammar.
        Validator validator = schema.newValidator();
        ErrorHandler eh = new ErrorHandlerImpl();
        validator.setErrorHandler(eh);

        // Validate this instance document against the
        // Instance document supplied
        validator.validate(src, result);
    } catch (Exception ex) {
        throw ex;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ValidatorTest.java

示例3: testGetOwnerItemList

import javax.xml.validation.Validator; //导入方法依赖的package包/类
/**
 * Check grammar caching with imported schemas.
 *
 * @throws Exception If any errors occur.
 * @see <a href="content/coins.xsd">coins.xsd</a>
 * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a>
 */
@Test
public void testGetOwnerItemList() throws Exception {
    String xsdFile = XML_DIR + "coins.xsd";
    String xmlFile = XML_DIR + "coins.xml";

    try(FileInputStream fis = new FileInputStream(xmlFile)) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
        dbf.setValidating(false);

        SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(((xsdFile))));

        MyErrorHandler eh = new MyErrorHandler();
        Validator validator = schema.newValidator();
        validator.setErrorHandler(eh);

        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Document document = docBuilder.parse(fis);
        validator.validate(new DOMSource(document), new DOMResult());
        assertFalse(eh.isAnyError());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:AuctionController.java

示例4: testGetOwnerItemList

import javax.xml.validation.Validator; //导入方法依赖的package包/类
/**
 * Check grammar caching with imported schemas.
 *
 * @throws Exception If any errors occur.
 * @see <a href="content/coins.xsd">coins.xsd</a>
 * @see <a href="content/coinsImportMe.xsd">coinsImportMe.xsd</a>
 */
@Test(groups = {"readLocalFiles"})
public void testGetOwnerItemList() throws Exception {
    String xsdFile = XML_DIR + "coins.xsd";
    String xmlFile = XML_DIR + "coins.xml";

    try(FileInputStream fis = new FileInputStream(xmlFile)) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);
        dbf.setValidating(false);

        SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(((xsdFile))));

        MyErrorHandler eh = new MyErrorHandler();
        Validator validator = schema.newValidator();
        validator.setErrorHandler(eh);

        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Document document = docBuilder.parse(fis);
        validator.validate(new DOMSource(document), new DOMResult());
        assertFalse(eh.isAnyError());
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:32,代码来源:AuctionController.java

示例5: getRepoValidator

import javax.xml.validation.Validator; //导入方法依赖的package包/类
/**
 * Helper method that returns a validator for our Repository XSD
 *
 * @param version The version number, in range {@code 1..NS_LATEST_VERSION}
 * @param handler A {@link CaptureErrorHandler}. If null the default will be used,
 *   which will most likely print errors to stderr.
 */
private Validator getRepoValidator(int version, @Nullable CaptureErrorHandler handler)
        throws SAXException {
    Validator validator = null;
    InputStream xsdStream = SdkRepoConstants.getXsdStream(version);
    if (xsdStream != null) {
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(xsdStream));
        validator = schema.newValidator();

        if (handler != null) {
            validator.setErrorHandler(handler);
        }
    }

    return validator;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ValidateRepositoryXmlTest.java

示例6: getValidator

import javax.xml.validation.Validator; //导入方法依赖的package包/类
/**
 * Helper method that returns a validator for our Repository XSD
 *
 * @param version The version number, in range {@code 1..NS_LATEST_VERSION}
 * @param handler A {@link CaptureErrorHandler}. If null the default will be used,
 *   which will most likely print errors to stderr.
 */
private Validator getValidator(int version, @Nullable CaptureErrorHandler handler)
        throws SAXException {
    Validator validator = null;
    InputStream xsdStream = SdkSysImgConstants.getXsdStream(version);
    if (xsdStream != null) {
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(xsdStream));
        validator = schema.newValidator();

        if (handler != null) {
            validator.setErrorHandler(handler);
        }
    }

    return validator;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ValidateSysImgXmlTest.java

示例7: getAddonValidator

import javax.xml.validation.Validator; //导入方法依赖的package包/类
/**
 * Helper method that returns a validator for our Addon XSD
 *
 * @param version The version number, in range {@code 1..NS_LATEST_VERSION}
 * @param handler A {@link CaptureErrorHandler}. If null the default will be used,
 *   which will most likely print errors to stderr.
 */
private Validator getAddonValidator(int version, @Nullable CaptureErrorHandler handler)
        throws SAXException {
    Validator validator = null;
    InputStream xsdStream = SdkAddonConstants.getXsdStream(version);
    if (xsdStream != null) {
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(xsdStream));
        validator = schema.newValidator();
        if (handler != null) {
            validator.setErrorHandler(handler);
        }
    }

    return validator;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ValidateAddonXmlTest.java

示例8: getValidator

import javax.xml.validation.Validator; //导入方法依赖的package包/类
/**
 * Helper method that returns a validator for our Addons-List XSD
 *
 * @param version The version number, in range {@code 1..NS_LATEST_VERSION}
 * @param handler A {@link CaptureErrorHandler}. If null the default will be used,
 *   which will most likely print errors to stderr.
 */
private Validator getValidator(int version, @Nullable CaptureErrorHandler handler)
        throws SAXException {
    Validator validator = null;
    InputStream xsdStream = SdkAddonsListConstants.getXsdStream(version);
    if (xsdStream != null) {
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(xsdStream));
        validator = schema.newValidator();
        if (handler != null) {
            validator.setErrorHandler(handler);
        }
    }

    return validator;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ValidateAddonsListXmlTest.java

示例9: getValidator

import javax.xml.validation.Validator; //导入方法依赖的package包/类
private Validator getValidator() throws SAXException {
    Schema s = getSchema();
    Validator v = s.newValidator();
    Assert.assertNotNull(v);
    v.setErrorHandler(new DraconianErrorHandler());
    return v;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:Bug4966254.java

示例10: testErrorHandler

import javax.xml.validation.Validator; //导入方法依赖的package包/类
@Test
public void testErrorHandler() {
    Validator validator = getValidator();
    assertNull(validator.getErrorHandler(), "When Validator is created, initially ErrorHandler should not be set.");

    ErrorHandler mh = new MyErrorHandler();
    validator.setErrorHandler(mh);
    assertSame(validator.getErrorHandler(), mh);

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

示例11: testGetOwnerInfo

import javax.xml.validation.Validator; //导入方法依赖的package包/类
/**
 * Check validation API features. A schema which is including in Bug 4909119
 * used to be testing for the functionalities.
 *
 * @throws Exception If any errors occur.
 * @see <a href="content/userDetails.xsd">userDetails.xsd</a>
 */
@Test
public void testGetOwnerInfo() throws Exception {
    String schemaFile = XML_DIR + "userDetails.xsd";
    String xmlFile = XML_DIR + "userDetails.xml";

    try(FileInputStream fis = new FileInputStream(xmlFile)) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);

        SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(Paths.get(schemaFile).toFile());

        Validator validator = schema.newValidator();
        MyErrorHandler eh = new MyErrorHandler();
        validator.setErrorHandler(eh);

        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        docBuilder.setErrorHandler(eh);

        Document document = docBuilder.parse(fis);
        DOMResult dResult = new DOMResult();
        DOMSource domSource = new DOMSource(document);
        validator.validate(domSource, dResult);
        assertFalse(eh.isAnyError());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:AuctionController.java

示例12: testGetOwnerInfo

import javax.xml.validation.Validator; //导入方法依赖的package包/类
/**
 * Check validation API features. A schema which is including in Bug 4909119
 * used to be testing for the functionalities.
 *
 * @throws Exception If any errors occur.
 * @see <a href="content/userDetails.xsd">userDetails.xsd</a>
 */
@Test(groups = {"readLocalFiles"})
public void testGetOwnerInfo() throws Exception {
    String schemaFile = XML_DIR + "userDetails.xsd";
    String xmlFile = XML_DIR + "userDetails.xml";

    try(FileInputStream fis = new FileInputStream(xmlFile)) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI);

        SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(Paths.get(schemaFile).toFile());

        Validator validator = schema.newValidator();
        MyErrorHandler eh = new MyErrorHandler();
        validator.setErrorHandler(eh);

        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        docBuilder.setErrorHandler(eh);

        Document document = docBuilder.parse(fis);
        DOMResult dResult = new DOMResult();
        DOMSource domSource = new DOMSource(document);
        validator.validate(domSource, dResult);
        assertFalse(eh.isAnyError());
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:35,代码来源:AuctionController.java

示例13: validate

import javax.xml.validation.Validator; //导入方法依赖的package包/类
public void validate() throws IOException, SAXException {
    Validator validator = this.getSchema(MCR_TRANSCRIPTION_SCHEMA).newValidator();
    validator.setErrorHandler(this);

    try {
        validator.validate(this.teiSource);
    } catch (SAXException e) {
        throw e;
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:11,代码来源:MCRTEIValidator.java

示例14: testValidateStreamSource

import javax.xml.validation.Validator; //导入方法依赖的package包/类
@Test
public void testValidateStreamSource() throws SAXException, IOException {
    Validator validator = getValidator();
    validator.setErrorHandler(new MyErrorHandler());
    validator.validate(getStreamSource());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:ValidatorTest.java

示例15: validate

import javax.xml.validation.Validator; //导入方法依赖的package包/类
public void validate(Document doc) throws IOException, SAXException {
    Validator validator = camelSchemas().newValidator();
    validator.setErrorHandler(this);

    validate(validator, doc.getRootElement());
}
 
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:7,代码来源:ValidationHandler.java


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