Java 8 Validator - 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 Validator class.

This code example shows how to use the following methods: setErrorHandler, setResourceResolver, validate
 
        // Create the merged Schema instance and from that, create the Validator instance... 
        Validator validator = schema.newValidator();
 
        if(schemaSourceResolver != null) {
            validator.setResourceResolver(schemaSourceResolver);
        } 
        if(errorHandler != null) {
            validator.setErrorHandler(errorHandler);
        } 
 
        // Validate the source... 
        validator.validate(source);
    } 
 
    private void assertSchemaNotInitialized() { 
        if (this.schema != null) {
            throw new IllegalStateException("Schema already initialised.");
        } 
    } 
Full Snippet Info
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: getFeature, reset, setFeature
     
    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);        
    } 
     
    public void testSecureProcessingFeaturePropagationAndReset() throws Exception { 
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        boolean value;
        value = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
        assertFalse("Default value of feature on SchemaFactory should have been false.", value);
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Full Snippet Info
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: setErrorHandler, validate
                System.out.println(e.getMessage());
                errors.add(e);
            } 
        }; 
 
        v.setErrorHandler(handler);
        v.validate(new StreamSource(new ByteArrayInputStream(data)));
 
        assertTrue(errors.isEmpty());
    } 
 
    public void testEncodeFeatureWithBounds() throws Exception {
        SimpleFeature feature = GML3MockData.feature();
        TestConfiguration configuration  = new TestConfiguration();
        //configuration.getProperties().add( org.geotools.gml2.GMLConfiguration.NO_FEATURE_BOUNDS ); 
     
        Encoder encoder = new Encoder( configuration );
        Document dom = encoder.encodeAsDOM(feature, TEST.TestFeature );
         
        assertEquals( 1, dom.getElementsByTagName("gml:boundedBy").getLength());
Full Snippet Info
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: validate
    } 
 
    public void testValidatorBadXML() { 
        System.out.println("-- testValidatorBadXML");
        try { 
            validator.validate(getAsSource(BAD_XML));
            fail("MUST NOT be able to validate bad restlet.xml"); 
        } catch (SAXException x) {
            // the error must be a "cvc-complex-type.2.4.a" 
            assertTrue("MUST detect schema violation", x.getLocalizedMessage()
                    .startsWith("cvc-complex-type.2.4.a"));
            // ...and it has to refer to 'bad-element' 
            assertTrue("MUST detect schema violation related to 'bad-element'", 
                    x.getLocalizedMessage().indexOf("bad-element") > 0);
 
        } catch (IOException x) {
            fail("MUST throw a SAXException only"); 
        } 
    } 
 
Full Snippet Info
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: setErrorHandler
        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;
    } 
 
    /** An helper that validates a string against an expected regexp. */ 
    private void assertRegex(String expectedRegexp, String actualString) {
        assertNotNull(actualString);
        assertTrue(
                String.format("Regexp Assertion Failed:\nExpected: %s\nActual: %s\n",
                        expectedRegexp, actualString),
                actualString.matches(expectedRegexp));
    } 
Full Snippet Info
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: validate
This code example shows how to use the following methods: setErrorHandler, validate
        InputStream xsdStream = SdkRepository.getXsdStream(version);
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new StreamSource(xsdStream));
        Validator validator = schema.newValidator();
        if (handler != null) {
            validator.setErrorHandler(handler);
        } 
 
        return validator;
    } 
 
    /** An helper that validates a string against an expected regexp. */ 
    private void assertRegex(String expectedRegexp, String actualString) {
        assertNotNull(actualString);
        assertTrue(
                String.format("Regexp Assertion Failed:\nExpected: %s\nActual: %s\n",
                        expectedRegexp, actualString),
                actualString.matches(expectedRegexp));
    } 
 

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: setErrorHandler, validate
 
            Validator validator = schema.newValidator();
 
            XmlValidationHandler baseHandler = new XmlValidationHandler( failOnValidationError );
 
            validator.setErrorHandler( baseHandler );
 
            reader = new XmlStreamReader( file );
 
            validator.validate( new StreamSource( reader ) );
 
            return baseHandler;
        } 
        catch ( IOException e )
        { 
            throw new SchemaValidatorException( "IOException : " + e.getMessage(), e );
        } 
        catch ( SAXException e )
        { 
            throw new SchemaValidatorException( "SAXException : " + e.getMessage(), e );
Full Snippet Info
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: validate
    	SchemaFactory sf=SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    	Schema schema=sf.newSchema(new StreamSource(schemaIn));
    	Validator validator=schema.newValidator();
    	StringBuilder errorBuilder=new StringBuilder();
    	try{ 
    		validator.validate(new StreamSource(new StringReader(xml)));
    	}catch (Exception e) {
    		e.printStackTrace();
    		fail("Error during validation of XML:\n" + e.getLocalizedMessage());
		} 
    } 
 
 
    /** 
     * Explicit RELS-EXT relation to collection object 
     * @throws Exception 
     */ 
    public void testRISearchRelsExtCollection() throws Exception { 
        FedoraClient client = getFedoraClient();
        String collectionPid = "demo:SmileyStuff";
Full Snippet Info
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: validate
            Validator validator = schema.newValidator();
 
            // TODO: stuff the input stream into the context for execute() 
            InputStream galleryItemInputStream = xmlFetcher.getInputStream(galleryItemUrl);
 
            validator.validate(new StreamSource(galleryItemInputStream));
 
            log.debug("Success validating xml at: " + galleryItemUrl);
        } 
        catch (Exception e)
        { 
            log.error("Validation for gadget definition failed.", e);
            ValidationException ve = new ValidationException();
            ve.addError(URL_KEY, "Valid url is required");
            throw ve;
        } 
        finally 
        { 
            try 
            { 
Full Snippet Info
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Validator Questions & Answers:

See Code Examples for Java 8 Validator Methods: