當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。