this.configuration = configuration;
this.geoServer = gs;
}
public Object read(Object request, Reader reader, Map kvp) throws Exception {
Parser parser = new Parser(configuration);
parser.setValidating(true);
//"inject" namespace mappings
Catalog catalog = geoServer.getCatalog();
List<NamespaceInfo> namespaces = catalog.getNamespaces();
for ( NamespaceInfo ns : namespaces ) {
if ( ns.equals( catalog.getDefaultNamespace() ) )
continue;
parser.getNamespaces().declarePrefix(
ns.getPrefix(), ns.getURI());
}
//set the input source with the correct encoding
InputSource source = new InputSource(reader);
source.setEncoding(geoServer.getGlobal().getCharset());
Object parsed = parser.parse(source);
// unfortunately insert elements in transactions cannot be validated...
if(!(parsed instanceof PostDiffType) && !(parsed instanceof GetDiffResponseType)) {
if (!parser.getValidationErrors().isEmpty()) {
WFSException exception = new WFSException("Invalid request", "InvalidParameterValue");
for (Iterator e = parser.getValidationErrors().iterator(); e.hasNext();) {
Exception error = (Exception) e.next();
exception.getExceptionText().add(error.getLocalizedMessage());
}
throw exception;