You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2007/03/01 07:14:14 UTC
svn commit: r513162 - in
/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload:
MultiUploadPage.html MultiUploadPage.java MultiUploadPage.properties
Author: ivaynberg
Date: Wed Feb 28 22:14:13 2007
New Revision: 513162
URL: http://svn.apache.org/viewvc?view=rev&rev=513162
Log:
bah, checking in missing files
Added:
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.html
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.java
incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.properties
Added: incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.html
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.html?view=auto&rev=513162
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.html (added)
+++ incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.html Wed Feb 28 22:14:13 2007
@@ -0,0 +1,48 @@
+<html xmlns:wicket="http://wicket.sourceforge.net/">
+<head>
+ <title>Wicket Examples - upload</title>
+ <link rel="stylesheet" type="text/css" href="style.css"/>
+ <style>
+ legend { border: 1px solid #e9601a; background-color: #bbb; color: #fff; padding: 4px;}
+ fieldset { border: 1px solid #e9601a; padding: 10px; margin-top: 10px;}
+ .mfuex { padding:5px;margin:5px;background:#eee; }
+ .mfuex .wicket-mfu-container { padding: 5px; margin-top: 3px; background-color: white; border:1px solid black; font-size: xx-small; }
+ .mfuex .wicket-mfu-caption { font-weight: bold; }
+ .mfuex .wicket-mfu-container input { margin-left: 5px; font-size: xx-small; }
+ </style>
+</head>
+<body>
+ <span wicket:id="mainNavigation"/>
+
+ The multi upload field is based on javascript found <a target="_blank" href="http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/">here</a>.<br/>
+
+ <form wicket:id="simpleUpload">
+ <fieldset>
+ <legend>Upload form</legend>
+ <p>
+ <div wicket:id="fileInput" class="mfuex"/>
+ </p>
+ <input type="submit" value="Upload!"/>
+ </fieldset>
+ </form>
+
+
+ <div>
+ <span wicket:id="uploadFeedback"/>
+ </div>
+
+ <div>
+ <h4>Current files in <span wicket:id="dir">(dir)</span>:</h4>
+ <table>
+ <tr wicket:id="fileList">
+ <td width="200"><span wicket:id="file">(file)</span></td>
+ <td><a href="#" wicket:id="delete"><img src="delete.gif" border="0"/></a></td>
+ </tr>
+ </table>
+ </div>
+
+
+
+
+</body>
+</html>
Added: incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.java?view=auto&rev=513162
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.java (added)
+++ incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.java Wed Feb 28 22:14:13 2007
@@ -0,0 +1,218 @@
+/*
+ * $Id: UploadPage.java 4619 2006-02-23 14:25:06 -0800 (Thu, 23 Feb 2006)
+ * jdonnerstag $ $Revision: 511234 $ $Date: 2006-02-23 14:25:06 -0800 (Thu, 23
+ * Feb 2006) $
+ *
+ * ==============================================================================
+ * Licensed 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 wicket.examples.upload;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import wicket.Application;
+import wicket.PageParameters;
+import wicket.examples.WicketExamplePage;
+import wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar;
+import wicket.markup.html.basic.Label;
+import wicket.markup.html.form.Form;
+import wicket.markup.html.form.upload.FileUpload;
+import wicket.markup.html.form.upload.FileUploadField;
+import wicket.markup.html.form.upload.MultiFileUploadField;
+import wicket.markup.html.link.Link;
+import wicket.markup.html.list.ListItem;
+import wicket.markup.html.list.ListView;
+import wicket.markup.html.panel.FeedbackPanel;
+import wicket.model.IModel;
+import wicket.model.LoadableDetachableModel;
+import wicket.model.PropertyModel;
+import wicket.util.file.Files;
+import wicket.util.file.Folder;
+import wicket.util.lang.Bytes;
+
+/**
+ * Upload example.
+ *
+ * @author Eelco Hillenius
+ */
+public class MultiUploadPage extends WicketExamplePage
+{
+ /**
+ * List view for files in upload folder.
+ */
+ private class FileListView extends ListView
+ {
+ /**
+ * Construct.
+ *
+ * @param name
+ * Component name
+ * @param files
+ * The file list model
+ */
+ public FileListView(String name, final IModel files)
+ {
+ super(name, files);
+ }
+
+ /**
+ * @see ListView#populateItem(ListItem)
+ */
+ protected void populateItem(ListItem listItem)
+ {
+ final File file = (File)listItem.getModelObject();
+ listItem.add(new Label("file", file.getName()));
+ listItem.add(new Link("delete")
+ {
+ public void onClick()
+ {
+ Files.remove(file);
+ MultiUploadPage.this.info("Deleted " + file);
+ }
+ });
+ }
+ }
+
+ /**
+ * Form for uploads.
+ */
+ private class FileUploadForm extends Form
+ {
+ // collection that will hold uploaded FileUpload objects
+ private final Collection uploads = new ArrayList();
+
+ public Collection getUploads()
+ {
+ return uploads;
+ }
+
+ /**
+ * Construct.
+ *
+ * @param name
+ * Component name
+ */
+ public FileUploadForm(String name)
+ {
+ super(name);
+
+ // set this form to multipart mode (allways needed for uploads!)
+ setMultiPart(true);
+
+ // Add one multi-file upload field
+ add(new MultiFileUploadField("fileInput", new PropertyModel(this, "uploads"), 5));
+
+ // Set maximum size to 100K for demo purposes
+ setMaxSize(Bytes.kilobytes(100));
+ }
+
+ /**
+ * @see wicket.markup.html.form.Form#onSubmit()
+ */
+ protected void onSubmit()
+ {
+ Iterator it = uploads.iterator();
+ while (it.hasNext())
+ {
+ final FileUpload upload = (FileUpload)it.next();
+ // Create a new file
+ File newFile = new File(getUploadFolder(), upload.getClientFileName());
+
+ // Check new file, delete if it allready existed
+ checkFileExists(newFile);
+ try
+ {
+ // Save to new file
+ newFile.createNewFile();
+ upload.writeTo(newFile);
+
+ MultiUploadPage.this.info("saved file: " + upload.getClientFileName());
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException("Unable to write file");
+ }
+ }
+ }
+ }
+
+ /** Log. */
+ private static final Log log = LogFactory.getLog(MultiUploadPage.class);
+
+ /** Reference to listview for easy access. */
+ private FileListView fileListView;
+
+ /**
+ * Constructor.
+ *
+ * @param parameters
+ * Page parameters
+ */
+ public MultiUploadPage(final PageParameters parameters)
+ {
+ Folder uploadFolder = getUploadFolder();
+
+ // Create feedback panels
+ final FeedbackPanel uploadFeedback = new FeedbackPanel("uploadFeedback");
+
+ // Add uploadFeedback to the page itself
+ add(uploadFeedback);
+
+ // Add simple upload form, which is hooked up to its feedback panel by
+ // virtue of that panel being nested in the form.
+ final FileUploadForm simpleUploadForm = new FileUploadForm("simpleUpload");
+ add(simpleUploadForm);
+
+ // Add folder view
+ add(new Label("dir", uploadFolder.getAbsolutePath()));
+ fileListView = new FileListView("fileList", new LoadableDetachableModel()
+ {
+ protected Object load()
+ {
+ return Arrays.asList(getUploadFolder().listFiles());
+ }
+ });
+ add(fileListView);
+
+ }
+
+ /**
+ * Check whether the file allready exists, and if so, try to delete it.
+ *
+ * @param newFile
+ * the file to check
+ */
+ private void checkFileExists(File newFile)
+ {
+ if (newFile.exists())
+ {
+ // Try to delete the file
+ if (!Files.remove(newFile))
+ {
+ throw new IllegalStateException("Unable to overwrite " + newFile.getAbsolutePath());
+ }
+ }
+ }
+
+ private Folder getUploadFolder()
+ {
+ return ((UploadApplication)Application.get()).getUploadFolder();
+ }
+}
\ No newline at end of file
Added: incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.properties
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.properties?view=auto&rev=513162
==============================================================================
--- incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.properties (added)
+++ incubator/wicket/branches/wicket-1.x/wicket-examples/src/main/java/wicket/examples/upload/MultiUploadPage.properties Wed Feb 28 22:14:13 2007
@@ -0,0 +1,2 @@
+simpleUpload.uploadTooLarge = File must be less than ${maxSize}.
+simpleUpload.uploadFailed = File failed to upload: ${exception.localizedMessage}