Java 8 ValidatorHandler - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ValidatorHandler class.

This code example shows how to use the following methods:setContentHandler, setErrorHandler
    public Iterable<Object> startWithValidation(final Reader in, String namespace, String schemaSource) throws SAXException {
        try { 
            SchemaFactory factory =  SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
            Schema schema = factory.newSchema(new StreamSource(new MirroredInputStream(schemaSource)));
            ValidatorHandler validator = schema.newValidatorHandler();
            validator.setContentHandler(parser);
            validator.setErrorHandler(parser);
 
            AddNamespaceFilter filter = new AddNamespaceFilter(namespace);
            filter.setContentHandler(validator);
            return start(in, filter);
        } catch(IOException e) {
            throw new SAXException(tr("Failed to load XML schema."), e);
        } 
    } 
 
    public void map(String tagName, Class<?> klass) {
        mapping.put(tagName, new Entry(klass,false,false));
    } 
 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setContentHandler, setErrorHandler
		StringWriter stringWriter = new StringWriter();
		XMLWriter dom4jOutWriter = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint());
 
		ValidatorHandler validatorHandler = pingSchema.newValidatorHandler();
		errorHandler.reset();
		validatorHandler.setErrorHandler(errorHandler);
		//SAX ContentHandler -> DOM4J XMLWriter 
		validatorHandler.setContentHandler(dom4jOutWriter); //chaining breaks prettyprint :(
		//DOM4J SAXWriter -> SAX ContentHandler 
		SAXWriter saxWriter = new SAXWriter(validatorHandler);
		saxWriter.write(dom4jDocument);
 
		System.out.println(stringWriter);
		assertThat(errorHandler.getErrors()).hasSize(6);
		assertThat(errorHandler.getErrors().get(0).getXpath()).isNotEmpty();
 
		//org.dom4j.io.DocumentSource/DocumentResult are SAX based therefore compatible and works 
 
		Transformer transformer = traxFactory.newTransformer();
		JAXBResult jaxbResult = new JAXBResult(pingContext.getJaxbContext());

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setContentHandler, setErrorHandler
		StringWriter stringWriter = new StringWriter();
		XMLWriter dom4jOutWriter = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint());
 
		ValidatorHandler validatorHandler = pingSchema.newValidatorHandler();
		errorHandler.reset();
		validatorHandler.setErrorHandler(errorHandler);
		//SAX ContentHandler -> DOM4J XMLWriter 
		validatorHandler.setContentHandler(dom4jOutWriter); //chaining breaks prettyprint :(
		//DOM4J SAXWriter -> SAX ContentHandler 
		SAXWriter saxWriter = new SAXWriter(validatorHandler);
		saxWriter.write(dom4jDocument);
 
		System.out.println(stringWriter);
		assertThat(errorHandler.getErrors()).hasSize(6);
		assertThat(errorHandler.getErrors().get(0).getXpath()).isNotEmpty();
 
		//org.dom4j.io.DocumentSource/DocumentResult are SAX based therefore compatible and works 
 
		Transformer transformer = traxFactory.newTransformer();
		JAXBResult jaxbResult = new JAXBResult(pingContext.getJaxbContext());

5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setContentHandler, setErrorHandler
	@SuppressWarnings("unused") 
	private void writeDomTraxSax(Node node, Writer writer, Schema schema, XmlErrorHandler errorHandler)
			throws XmlValidationException { 
 
		ValidatorHandler validatorHandler = schema.newValidatorHandler();
		validatorHandler.setErrorHandler(errorHandler);
		XPathSaxTracker xpathTracker = new XPathSaxTracker(validatorHandler);
		errorHandler.setXPathTracker(xpathTracker);
 
		ContentHandler xmlWriter;
		if (indenting) {
			xmlWriter = new Sax2IndentingWriter(writer, "utf-8");
		} else { 
			xmlWriter = new Sax2Writer(writer, "utf-8");
		} 
		validatorHandler.setContentHandler(xmlWriter);
		Transformer transformer = getTraxFactory().newTransformer();
		transformer.setErrorListener(errorHandler);
 
		try { 
			transformer.transform(new DOMSource(node), new SAXResult(xpathTracker));
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 ValidatorHandler Methods: