import mir.config.MirPropertiesConfiguration;
import mir.log.LoggerWrapper;
import mir.session.*;
-import mir.storage.StorageObject;
-import mir.util.ExceptionFunctions;
-import mir.util.FileFunctions;
+import mir.storage.Database;
+import mir.util.ExceptionRoutines;
+import mir.util.FileRoutines;
+import mir.util.IORoutines;
import mircoders.global.MirGlobal;
-import mircoders.module.ModuleMediaType;
+import mircoders.media.UnsupportedMediaTypeExc;
import java.io.*;
import java.util.*;
*/
public abstract class MirBasicPostingSessionHandler implements SessionHandler {
protected static LoggerWrapper logger = new LoggerWrapper("Localizer.OpenPosting");
- protected MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();;
+ protected MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
/** Previously uploaded files */
protected List attachments;
subsequentRequest(aRequest, aSession, aResponse);
}
}
- };
+ }
protected void initialRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
initializeSession(aRequest, aSession);
makeInitialResponse(aRequest, aSession, aResponse);
}
- protected void processAttachments(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
+ protected void processAttachments(Request aRequest, Session aSession, Response aResponse) {
Iterator i = attachments.iterator();
while (i.hasNext()) {
- processAttachment(aRequest, aSession, (Attachment) i.next());
+ Attachment attachment = (Attachment) i.next();
+ try{
+ processAttachment(aRequest, aSession, attachment);
+ }
+ catch (Throwable t) {
+ try {
+ processAttachmentError(aRequest, aSession, attachment, t);
+ }
+ catch (Throwable u) {
+ }
+ logger.error("Error while processing attachment", t);
+ }
}
}
preProcessRequest(aRequest, aSession);
processAttachments(aRequest, aSession, aResponse);
-
postProcessRequest(aRequest, aSession);
initializeResponseData(aRequest, aSession, aResponse);
makeFinalResponse(aRequest, aSession, aResponse);
if (configuration.getBoolean("Localizer.OpenSession.AllowFTPUploads", false)) {
aResponse.setResponseValue("ftpfiles",
- FileFunctions.getDirectoryContentsAsList(configuration.getFile("Localizer.OpenSession.FTPDirectory"),
+ FileRoutines.getDirectoryContentsAsList(configuration.getFile("Localizer.OpenSession.FTPDirectory"),
new FilenameFilter() {
public boolean accept(File aDir, String aName) {
return !(new File(aDir, aName).isDirectory());
if (configuration.getBoolean("Localizer.OpenSession.AllowFTPUploads", false)) {
File FTPDirectory = configuration.getFile("Localizer.OpenSession.FTPDirectory");
- List ftpUploads = aRequest.getPrefixedParameterNames("ftpupload");
+ List ftpUploads = new ArrayList(aRequest.getPrefixedParameterNames("ftpupload"));
+ Collections.sort(ftpUploads, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ if (o1 instanceof String && o2 instanceof String) {
+ return ((String) o1).compareTo((String) o2);
+ }
+ else {
+ return 0;
+ }
+ }
+ });
+
i = ftpUploads.iterator();
while (i.hasNext()) {
final String fieldName = (String) i.next();
preprocessNewAttachment(aRequest, aSession, new UploadedFile() {
public void writeToFile(File aFile) throws SessionFailure {
try {
- FileFunctions.move(sourceFile, aFile);
+ FileRoutines.move(sourceFile, aFile);
+ }
+ catch (IOException e) {
+ throw new SessionFailure(e);
+ }
+ }
+
+ public void writeToStream(OutputStream aStream) throws SessionFailure {
+ try {
+ IORoutines.copyStream(getInputStream(), aStream);
}
catch (IOException e) {
throw new SessionFailure(e);
protected void makeInitialResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
aResponse.setResponseGenerator(normalResponseGenerator);
- };
+ }
protected void makeResponse(Request aRequest, Session aSession, Response aResponse, List anErrors) throws SessionExc, SessionFailure {
aResponse.setResponseValue("errors", anErrors);
aResponse.setResponseGenerator(normalResponseGenerator);
- };
+ }
protected void makeFinalResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
aResponse.setResponseGenerator(finalResponseGenerator);
- };
+ }
protected void makeErrorResponse(Request aRequest, Session aSession, Response aResponse, Throwable anError) throws SessionExc, SessionFailure {
- Throwable rootCause = ExceptionFunctions.traceCauseException(anError);
+ Throwable rootCause = ExceptionRoutines.traceCauseException(anError);
if (rootCause instanceof DuplicatePostingExc)
aResponse.setResponseGenerator(dupeResponseGenerator);
- if (rootCause instanceof ModuleMediaType.UnsupportedMimeTypeExc) {
- aResponse.setResponseValue("mimetype", ((ModuleMediaType.UnsupportedMimeTypeExc) rootCause).getMimeType());
+ if (rootCause instanceof UnsupportedMediaTypeExc) {
+ aResponse.setResponseValue("mimetype", ((UnsupportedMediaTypeExc) rootCause).getMimeType());
aResponse.setResponseGenerator(unsupportedMediaTypeResponseGenerator);
}
else {
new Object[] {anError.getMessage()}));
makeResponse(aRequest, aSession, aResponse, errors);
}
- };
+ }
protected void makeOpenPostingDisabledResponse(Request aRequest, Session aSession, Response aResponse) {
aResponse.setResponseGenerator(configuration.getString("ServletModule.OpenIndy.PostingDisabledTemplate"));
*
*/
protected void preProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
- };
+ }
public void processAttachment(Request aRequest, Session aSession, Attachment aFile) throws SessionExc, SessionFailure {
- };
+ }
+ public void processAttachmentError(Request aRequest, Session aSession, Attachment aFile, Throwable anError) {
+ }
protected void postProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
- };
+ }
/**
* Determine whether the request shoudl be processed: that is, the validate,
protected boolean shouldProcessRequest(Request aRequest, Session aSession, List aValidationErrors) throws SessionExc, SessionFailure {
if (aRequest.getParameter("post")==null)
return false;
- else {
- validate(aValidationErrors, aRequest, aSession);
- return (aValidationErrors == null || aValidationErrors.size() == 0);
- }
+ validate(aValidationErrors, aRequest, aSession);
+ return (aValidationErrors == null || aValidationErrors.size() == 0);
}
/**
/**
* Method to filter the attributes and their values of a request
- * based on the fields of a storage object.
+ * based on the fields of a database object.
*/
- protected static final Map getIntersectingValues(Request aRequest, StorageObject aStorage) throws SessionFailure {
+ protected static final Map getIntersectingValues(Request aRequest, Database aStorage) throws SessionFailure {
Map result = new HashMap();
- Iterator i = aStorage.getFields().iterator();
+ Iterator i = aStorage.getFieldNames().iterator();
while (i.hasNext()) {
String fieldName = (String) i.next();
uploadedFile.writeToFile(aFile);
}
+ public void writeToStream(OutputStream aStream) throws SessionExc, SessionFailure {
+ try {
+ IORoutines.copyStream(uploadedFile.getInputStream(), aStream);
+ }
+ catch (IOException e) {
+ throw new SessionFailure(e);
+ }
+ }
+
public InputStream getInputStream() throws SessionExc, SessionFailure {
return uploadedFile.getInputStream();
}