Java Code Examples for javax.xml.validation.Validator#setProperty()

The following examples show how to use javax.xml.validation.Validator#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeaturePropagationTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testPropertyReset() throws Exception {
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = makeSchema(factory, null);
    Validator validator = schema.newValidator();
    Object beforeReset = validator.getProperty(SECURITY_MANAGER);
    validator.setProperty(SECURITY_MANAGER, null);
    Object changed = validator.getProperty(SECURITY_MANAGER);
    //for JDK, this is changed since by default the security manager is set
    assertTrue("Property value should have changed after calling setProperty().", beforeReset != changed);
    validator.reset();
    Object afterReset = validator.getProperty(SECURITY_MANAGER);
    assertTrue("Property value should be the same after calling reset()", beforeReset == afterReset);
}
 
Example 2
Source File: Bug4969693.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test02() throws SAXException {
    Validator validator = schemaFactory.newSchema().newValidator();
    try {
        validator.setProperty(null, "abc");
        Assert.fail("exception expected");
    } catch (NullPointerException e) {
        ;
    }
}
 
Example 3
Source File: CatalogSupportBase.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verifies Catalog Support for the Validator.
 * @param setUseCatalog1 a flag to indicate whether USE_CATALOG shall be set
 * on the factory.
 * @param setUseCatalog2 a flag to indicate whether USE_CATALOG shall be set
 * on the Validator.
 * @param source  the XML source
 * @param resolver1 a resolver to be set on the factory if specified
 * @param resolver2 a resolver to be set on the Validator if specified
 * @param catalog1 a catalog to be set on the factory if specified
 * @param catalog2 a catalog to be set on the Validator if specified
 */
public void testValidator(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog,
        Source source, LSResourceResolver resolver1, LSResourceResolver resolver2,
        String catalog1, String catalog2)
        throws Exception {

        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        if (setUseCatalog1) {
            schemaFactory.setFeature(XMLConstants.USE_CATALOG, useCatalog);
        }
        if (catalog1 != null) {
            schemaFactory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog1);
        }
        if (resolver1 != null) {
            schemaFactory.setResourceResolver(resolver1);
        }

        Schema schema = schemaFactory.newSchema();
        Validator validator = schema.newValidator();
        if (setUseCatalog2) {
            validator.setFeature(XMLConstants.USE_CATALOG, useCatalog);
        }
        if (catalog2 != null) {
            validator.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog2);
        }
        if (resolver2 != null) {
            validator.setResourceResolver(resolver2);
        }
        validator.validate(source);
}
 
Example 4
Source File: ValidatorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = SAXNotRecognizedException.class)
public void testSetUnrecognizedProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
    Validator validator = getValidator();
    validator.setProperty(UNRECOGNIZED_NAME, "test");
}
 
Example 5
Source File: ValidatorTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = NullPointerException.class)
public void testSetNullProperty() throws SAXNotRecognizedException, SAXNotSupportedException {
    Validator validator = getValidator();
    assertNotNull(validator);
    validator.setProperty(null, "test");
}
 
Example 6
Source File: ValidatorConfigurator.java    From dss with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
protected void setSecurityAttribute(Validator validator, String attribute, Object value) throws Exception {
	validator.setProperty(attribute, value);
}
 
Example 7
Source File: XmlUtils.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Validate a source, throws an exception if invalid.
 *
 * @param schema
 *            the schema to verify against. Use
 *            {@link #newSafeSchemaFactory()} for a safe schema
 * @param source
 *            the source to verify
 * @throws SAXException
 *             when the underlying XMLReader cannot set the security
 *             properties -or- when the source fails validation
 * @throws IOException
 *             the source failed validation due to file reasons, e.g.
 *             permissions
 * @since 4.2
 */
public static void safeValidate(Schema schema, Source source) throws SAXException, IOException {
    Validator validator = schema.newValidator();
    validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, EMPTY);
    validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, EMPTY);
    validator.validate(source);
}