return;
}
session = HibernateSessions.startTransaction(this.getClass());
try {
if (debug) System.out.println("--- BEGIN DOPOST ---");
FCKEditorManager fckMgr = new FCKEditorManager(Locale.GERMAN, session);
response.setContentType("text/html; charset=UTF-8");
response.setHeader("Cache-Control","no-cache");
PrintWriter out = response.getWriter();
String commandStr=request.getParameter("Command");
String typeStr=request.getParameter("Type");
String currentFolderStr=request.getParameter("CurrentFolder");
String currentPath=baseDir+typeStr+currentFolderStr;
File currentDir = fckMgr.getFolder(blogCode, currentPath);
if (currentDir == null) {
currentDir = fckMgr.createFolder(blogCode, currentPath, user);
}
String retVal="0";
String fileName="";
if(!commandStr.equals("FileUpload"))
retVal="203";
else {
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
try {
List items = upload.parseRequest(request);
Map fields=new HashMap();
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
fields.put(item.getFieldName(),item.getString());
} else {
fields.put(item.getFieldName(),item);
}
}
FileItem uplFile=(FileItem)fields.get("NewFile");
String fileNameLong=uplFile.getName();
fileNameLong=fileNameLong.replace('\\','/');
fileNameLong=fileNameLong.replaceAll("[^a-zA-Z_0-9/:.]", "_");
String[] pathParts=fileNameLong.split("/");
fileName=pathParts[pathParts.length-1];
String nameWithoutExt=getNameWithoutExtension(fileName);
String ext=getExtension(fileName);
int counter=1;
while(fckMgr.getFile(blogCode, currentDir, fileName, false) != null) {
fileName = nameWithoutExt+"("+counter+")"+"."+ext;
retVal="201";
counter++;
}
byte[] fileData = uplFile.get();
if (fileData != null && fileData.length > 0) { // this also happens if the file does not exist => no precise error message possible
fckMgr.saveFile(blogCode, currentDir, fileName, fileData, uplFile.getContentType(), user);
}
} catch (Exception ex) {
retVal="203";
}