* ".../schemas/sld/StyleLayerDescriptor.xsd"
*
* @return list of SAXExceptions (0 if the file's okay)
*/
public List validateSLD(InputSource xml, ServletContext servContext) {
SAXParser parser = new SAXParser();
try {
// this takes care of spaces in the path to the file
URL schemaFile = servContext.getResource("/schemas/sld/StyledLayerDescriptor.xsd");
if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info(new StringBuffer("Validating SLD with ").append(schemaFile.toString())
.toString());
}
String schemaUrl = schemaFile.toString();
// 1. tell the parser to validate the XML document vs the schema
// 2. does not validate the schema (the GML schema is *not* valid. This is
// an OGC blunder)
// 3. tells the validator that the tags without a namespace are actually
// SLD tags.
// 4. tells the validator to 'override' the SLD schema that a user may
// include with the one inside geoserver.
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
false);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
schemaUrl);
parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
"http://www.opengis.net/sld " + schemaUrl);
//parser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation","http://www.opengis.net/ows "+SchemaUrl);
Validator handler = new Validator();
parser.setErrorHandler(handler);
parser.parse(xml);
return handler.errors;
} catch (java.io.IOException ioe) {
ArrayList al = new ArrayList();
al.add(new SAXParseException(ioe.getLocalizedMessage(), null));