StringWriter writer = new StringWriter();
new HierarchicalStreamCopier().copy(hsr, new PrettyPrintWriter(writer));
writer.close();
newLayer = (TileLayer) xs.fromXML(writer.toString());
} else {
throw new RestletException("Unknown or missing format extension: "
+ formatExtension, Status.CLIENT_ERROR_BAD_REQUEST);
}
} catch (ConversionException xstreamExceptionWrapper) {
Throwable cause = xstreamExceptionWrapper.getCause();
if (cause instanceof Error) {
throw (Error) cause;
}
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
if (cause!=null){
throw new RestletException(cause.getMessage(), Status.SERVER_ERROR_INTERNAL,
(Exception) cause);
} else {
throw new RestletException(xstreamExceptionWrapper.getMessage(),
Status.SERVER_ERROR_INTERNAL, xstreamExceptionWrapper);
}
}
if (!newLayer.getName().equals(layerName)) {
throw new RestletException("There is a mismatch between the name of the "
+ " layer in the submission and the URL you specified.",
Status.CLIENT_ERROR_BAD_REQUEST);
}
// Check that the parameter filters deserialized correctly
if(newLayer.getParameterFilters()!=null) {
try {
for(@SuppressWarnings("unused")
ParameterFilter filter: newLayer.getParameterFilters()){
// Don't actually need to do anything here. Just iterate over the elements
// casting them into ParameterFilter
}
} catch (ClassCastException ex) {
// By this point it has already been turned into a POJO, so the XML is no longer
// available. Otherwise it would be helpful to include in the error message.
throw new RestletException("parameterFilters contains an element that is not "+
"a known ParameterFilter", Status.CLIENT_ERROR_BAD_REQUEST);
}
}
return newLayer;