Fields Summary |
---|
protected static org.apache.juli.logging.Log | logThe Log to which all SAX event related logging calls will be made. |
private static final String | JAXP_SCHEMA_SOURCEThe JAXP 1.2 property required to set up the schema location. |
protected static String | JAXP_SCHEMA_LANGUAGEThe JAXP 1.2 property to set up the schemaLanguage used. |
protected static String | XERCES_DYNAMICXerces dynamic validation property |
protected static String | XERCES_SCHEMAXerces schema validation property |
protected static float | versionA float representing the underlying Xerces version |
protected static String | versionNumberThe current Xerces version. |
Methods Summary |
---|
private static void | configureOldXerces(javax.xml.parsers.SAXParser parser, java.util.Properties properties)Configure schema validation as recommended by the JAXP 1.2 spec.
The properties object may contains information about
the schema local and language.
String schemaLocation = (String)properties.get("schemaLocation");
String schemaLanguage = (String)properties.get("schemaLanguage");
try{
if (schemaLocation != null) {
parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage);
parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation);
}
} catch (SAXNotRecognizedException e){
log.info(parser.getClass().getName() + ": "
+ e.getMessage() + " not supported.");
}
|
private static void | configureXerces(javax.xml.parsers.SAXParserFactory factory)Configure schema validation as recommended by the Xerces spec.
Both DTD and Schema validation will be enabled simultaneously.
factory.setFeature(XERCES_DYNAMIC, true);
factory.setFeature(XERCES_SCHEMA, true);
|
private static java.lang.String | getXercesVersion()Return the current Xerces version.
// If for some reason we can't get the version, set it to 1.0.
String versionNumber = "1.0";
try{
// Use reflection to avoid a build dependency with Xerces.
Class versionClass =
Class.forName("org.apache.xerces.impl.Version");
// Will return Xerces-J 2.x.0
Method method =
versionClass.getMethod("getVersion", (Class[]) null);
String version = (String)method.invoke(null, (Object[]) null);
versionNumber = version.substring( "Xerces-J".length() ,
version.lastIndexOf(".") );
} catch (Exception ex){
// Do nothing.
}
return versionNumber;
|
public static javax.xml.parsers.SAXParser | newSAXParser(java.util.Properties properties)Create a SAXParser based on the underlying
Xerces version.
SAXParserFactory factory =
(SAXParserFactory)properties.get("SAXParserFactory");
if (versionNumber == null){
versionNumber = getXercesVersion();
version = new Float( versionNumber ).floatValue();
}
// Note: 2.2 is completely broken (with XML Schema).
if (version > 2.1) {
configureXerces(factory);
return factory.newSAXParser();
} else {
SAXParser parser = factory.newSAXParser();
configureOldXerces(parser,properties);
return parser;
}
|