StylesEditorForm stylesForm = (StylesEditorForm) form;
FormFile file = stylesForm.getSldFile();
final String filename = file.getFileName();
final String styleID = stylesForm.getStyleID();
StyleConfig style = user.getStyle();
boolean doFullValidation = stylesForm.getFullyValidate();
if (stylesForm.getFullyValidateChecked() == false) {
doFullValidation = false;
}
if (doFullValidation)
{
List l = getSchemaExceptions(file,request);
if (l.size() !=0)
{
handleValidationErrors(l,file,stylesForm);
return mapping.findForward("schemaErrors");
}
}
if (style == null) {
// Must of bookmarked? Redirect so they can select
return mapping.findForward("config.data.style");
}
ServletContext sc = getServlet().getServletContext();
//DJB: changed for geoserver_data_dir
//File rootDir = new File(getServlet().getServletContext().getRealPath("/"));
File rootDir = GeoserverDataDirectory.getGeoserverDataDirectory(sc);
File styleDir;
try {
styleDir = GeoserverDataDirectory.findConfigDir(rootDir, "styles");
} catch (ConfigurationException cfe) {
LOGGER.warning("no style dir found, creating new one");
//if for some bizarre reason we don't fine the dir, make a new one.
styleDir = new File(rootDir, "styles");
}
// send content of FormFile to /styles :
// there nothing to keep the styles in memory for XMLConfigWriter.store()
InputStreamReader isr = new InputStreamReader(file.getInputStream());
File newSldFile = new File(styleDir, filename);
//here we do a check to see if the file we are trying to upload is
//overwriting another style file.
LOGGER.fine("new sld file is: " + newSldFile + ", exists: "
+ newSldFile.exists());
if (newSldFile.exists()) {
StyleConfig styleForID = config.getStyle(styleID);
if (styleForID == null) {
//if there is already a file at the location (file.exists()), and
//the system does not have a record of this styleId then it means
//we are trying to add a new sld at a location that would overwrite
//another's sld file.
doFileExistsError(newSldFile, request);
return mapping.findForward("config.data.style.editor");
} else {
//if the system has a record of the file, then we need to check if this
//update is being performed on the correct style id, so we see if the
//file in the system is the same as this one.
File oldFile = styleForID.getFilename();
LOGGER.fine("old file: " + oldFile + ", newFile: " + newSldFile);
if (!oldFile.equals(newSldFile)) {
doFileExistsError(newSldFile, request);