Author: norman
Date: Fri Jul 24 15:06:18 2009
New Revision: 797516
URL: http://svn.apache.org/viewvc?rev=797516&view=rev
Log:
Start to work on sending messages with attachments
Added:
labs/hupa/src/main/java/org/apache/hupa/server/AttachmentStore.java
labs/hupa/src/main/java/org/apache/hupa/server/FileAttachmentStore.java
Modified:
labs/hupa/src/main/java/org/apache/hupa/server/SendMessageHandler.java
labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java
labs/hupa/src/main/java/org/apache/hupa/server/servlet/UploadAttachmentServlet.java
Added: labs/hupa/src/main/java/org/apache/hupa/server/AttachmentStore.java
URL:
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/AttachmentStore.java?rev=797516&view=auto
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/AttachmentStore.java (added)
+++ labs/hupa/src/main/java/org/apache/hupa/server/AttachmentStore.java Fri Jul
24 15:06:18 2009
@@ -0,0 +1,30 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.hupa.server;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public interface AttachmentStore {
+
+ public InputStream get(String file) throws IOException;
+ public void add(String name, InputStream in) throws IOException;
+ public void delete(String file);
+}
Added: labs/hupa/src/main/java/org/apache/hupa/server/FileAttachmentStore.java
URL:
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/FileAttachmentStore.java?rev=797516&view=auto
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/FileAttachmentStore.java
(added)
+++ labs/hupa/src/main/java/org/apache/hupa/server/FileAttachmentStore.java Fri
Jul 24 15:06:18 2009
@@ -0,0 +1,57 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.hupa.server;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+
+
+public class FileAttachmentStore implements AttachmentStore {
+ private String dir = System.getProperty("java.io.tmpdir");
+
+ public void delete(String file) {
+ new File(dir + "/" + file).delete();
+ }
+
+ public InputStream get(String file) throws IOException{
+ File f = new File(dir+ "/"+file);
+ if (f.exists() == false) {
+ throw new IOException("No such attachment");
+ }
+ return new FileInputStream(f);
+ }
+
+ public void add(String name,InputStream in) throws IOException {
+ File f = new File(dir + "/" + name);
+ if (f.exists()) {
+ f.delete();
+ }
+ f.createNewFile();
+
+ IOUtils.copy(in, new FileOutputStream(f));
+
+ }
+
+}
Modified: labs/hupa/src/main/java/org/apache/hupa/server/SendMessageHandler.java
URL:
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/SendMessageHandler.java?rev=797516&r1=797515&r2=797516&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/SendMessageHandler.java
(original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/SendMessageHandler.java Fri
Jul 24 15:06:18 2009
@@ -45,10 +45,12 @@
ActionHandler<SendMessage, EmptyResult> {
private Log logger;
+ private AttachmentStore store;
@Inject
- public SendMessageHandler(Log logger) {
+ public SendMessageHandler(Log logger,AttachmentStore store) {
this.logger = logger;
+ this.store = store;
}
public EmptyResult execute(SendMessage action, ExecutionContext arg1)
Modified: labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java
URL:
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java?rev=797516&r1=797515&r2=797516&view=diff
==============================================================================
--- labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java
(original)
+++ labs/hupa/src/main/java/org/apache/hupa/server/guice/ServerModul.java Fri
Jul 24 15:06:18 2009
@@ -22,10 +22,12 @@
import net.customware.gwt.dispatch.server.guice.ActionHandlerModule;
import org.apache.commons.logging.Log;
+import org.apache.hupa.server.AttachmentStore;
import org.apache.hupa.server.DeleteMessageHandler;
import org.apache.hupa.server.ExposeMessageHandler;
import org.apache.hupa.server.FetchFoldersHandler;
import org.apache.hupa.server.FetchMessagesHandler;
+import org.apache.hupa.server.FileAttachmentStore;
import org.apache.hupa.server.IMAPStoreCache;
import org.apache.hupa.server.LoginUserHandler;
import org.apache.hupa.server.LogoutUserHandler;
@@ -56,6 +58,7 @@
bindHandler(SendMessageHandler.class);
bindHandler(NoopHandler.class);
+
bind(AttachmentStore.class).to(FileAttachmentStore.class).in(Singleton.class);
bind(IMAPStoreCache.class).in(Singleton.class);
bind(Log.class).toProvider(LogProvider.class).in(Singleton.class);
bind(DownloadAttachmentServlet.class).in(Singleton.class);
Modified:
labs/hupa/src/main/java/org/apache/hupa/server/servlet/UploadAttachmentServlet.java
URL:
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/server/servlet/UploadAttachmentServlet.java?rev=797516&r1=797515&r2=797516&view=diff
==============================================================================
---
labs/hupa/src/main/java/org/apache/hupa/server/servlet/UploadAttachmentServlet.java
(original)
+++
labs/hupa/src/main/java/org/apache/hupa/server/servlet/UploadAttachmentServlet.java
Fri Jul 24 15:06:18 2009
@@ -19,17 +19,32 @@
package org.apache.hupa.server.servlet;
+import gwtupload.server.UploadAction;
+
import java.io.IOException;
import java.util.Vector;
import org.apache.commons.fileupload.FileItem;
+import org.apache.hupa.server.AttachmentStore;
-import gwtupload.server.UploadAction;
+import com.google.inject.Inject;
public class UploadAttachmentServlet extends UploadAction{
+ private AttachmentStore store;
+
+ @Inject
+ public UploadAttachmentServlet(AttachmentStore store) {
+ this.store = store;
+ }
+
+
@Override
public String doAction(Vector<FileItem> sessionFiles) throws
IOException {
+ for (int i = 0; i < sessionFiles.size(); i++) {
+ FileItem item = sessionFiles.get(i);
+ store.add(item.getName(), item.getInputStream());
+ }
return null;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]