Search in sources :

Example 1 with JmriLocalEntityResolver

use of jmri.util.JmriLocalEntityResolver in project JMRI by JMRI.

the class XmlFile method getBuilder.

public static SAXBuilder getBuilder(Validate validate) {
    // should really be a Verify enum
    SAXBuilder builder;
    boolean verifyDTD = (validate == Validate.CheckDtd) || (validate == Validate.CheckDtdThenSchema);
    boolean verifySchema = (validate == Validate.RequireSchema) || (validate == Validate.CheckDtdThenSchema);
    // old style 
    // argument controls DTD validation
    builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", verifyDTD);
    // insert local resolver for includes, schema, DTDs
    builder.setEntityResolver(new JmriLocalEntityResolver());
    // configure XInclude handling
    builder.setFeature("http://apache.org/xml/features/xinclude", true);
    builder.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
    // only validate if grammar is available, making ABSENT OK
    builder.setFeature("http://apache.org/xml/features/validation/dynamic", verifyDTD && !verifySchema);
    // control Schema validation
    builder.setFeature("http://apache.org/xml/features/validation/schema", verifySchema);
    builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", verifySchema);
    // if not validating DTD, just validate Schema
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", verifyDTD);
    if (!verifyDTD) {
        builder.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
    }
    // allow Java character encodings
    builder.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
    return builder;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) JmriLocalEntityResolver(jmri.util.JmriLocalEntityResolver)

Aggregations

JmriLocalEntityResolver (jmri.util.JmriLocalEntityResolver)1 SAXBuilder (org.jdom2.input.SAXBuilder)1