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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 Validator Questions & Answers:

See Code Examples for Java 8 Validator Methods: