WorkspaceInfo ws = findWorkspace(wsName, catalog());
// Resource resource = dataDir().get(ws).get("icons"); // GEOS-6690
GeoServerResourceLoader rl = geoServer.getCatalog().getResourceLoader();
Resource styles = rl.get(Paths.path("workspaces",ws.getName(),"styles"));
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
@SuppressWarnings("unchecked")
List<FileItem> input = (List<FileItem>) upload.parseRequest(request);
JSONArr created = new JSONArr();
for (FileItem file : input) {
String filename = file.getName();
// trim filename if required
if (filename.lastIndexOf('/') != -1) {
filename = filename.substring(filename.lastIndexOf('/'));
}
if (filename.lastIndexOf('\\') != -1) {
filename = filename.substring(filename.lastIndexOf('\\'));
}
String ext = fileExt(filename);
if( !ICON_FORMATS.containsKey(ext)){
String msg = "Icon "+filename+" format "+ext+" unsupported - try:"+ICON_FORMATS.keySet();
LOG.warning(msg);
throw new FileUploadException(msg);
}
try {
InputStream data = file.getInputStream();
Resources.copy(data, styles, filename);
icon(created.addObject(), ws, styles.get(filename), request);
} catch (Exception e) {
throw new FileUploadException("Unable to write "+filename,e);
}
}