You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2007/11/09 17:27:07 UTC
svn commit: r593583 - in
/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event:
FileUploadProgressListener.java ServiceEventHandler.java
Author: jaz
Date: Fri Nov 9 08:27:06 2007
New Revision: 593583
URL: http://svn.apache.org/viewvc?rev=593583&view=rev
Log:
added a FileProgress listener to the session when uploading files through the service event handler
Added:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/FileUploadProgressListener.java
Modified:
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java
Added: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/FileUploadProgressListener.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/FileUploadProgressListener.java?rev=593583&view=auto
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/FileUploadProgressListener.java (added)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/FileUploadProgressListener.java Fri Nov 9 08:27:06 2007
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.ofbiz.webapp.event;
+
+import org.apache.commons.fileupload.ProgressListener;
+
+import java.io.Serializable;
+
+/**
+ * FileUploadProgressListener - Commons FileUpload progress listener
+ */
+public class FileUploadProgressListener implements ProgressListener, Serializable {
+
+ public static final String module = FileUploadProgressListener.class.getName();
+
+ protected long contentLength = -1;
+ protected long bytesRead = -1;
+ protected int items = -1;
+ protected boolean hasStarted = false;
+
+ public void update(long bytesRead, long contentLength, int items) {
+ this.contentLength = contentLength;
+ this.bytesRead = bytesRead;
+ this.items = items;
+ if (!hasStarted) {
+ hasStarted = true;
+ }
+ }
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ public long getBytesRead() {
+ return bytesRead;
+ }
+
+ public int getItems() {
+ return items;
+ }
+
+ public boolean hasStarted() {
+ return hasStarted;
+ }
+}
Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java?rev=593583&r1=593582&r2=593583&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceEventHandler.java Fri Nov 9 08:27:06 2007
@@ -150,6 +150,12 @@
Map multiPartMap = FastMap.newInstance();
if (isMultiPart) {
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory(sizeThreshold, new File(tmpUploadRepository)));
+
+ // create the progress listener and add it to the session
+ FileUploadProgressListener listener = new FileUploadProgressListener();
+ upload.setProgressListener(listener);
+ session.setAttribute("uploadProgressListener", listener);
+
if (encoding != null) {
upload.setHeaderEncoding(encoding);
}