KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > sandbox > FileUploadTestAction


1 /*
2  * Copyright (c) 2002-2005 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.sandbox;
6
7 import com.opensymphony.xwork.ActionSupport;
8
9 import java.io.File JavaDoc;
10
11 /**
12  * TestAction for the FileUploadInterceptor.
13  */

14 public class FileUploadTestAction extends ActionSupport {
15
16     private File JavaDoc uploadedItem;
17     private String JavaDoc uploadedItemContentType;
18     private String JavaDoc uploadedItemFileName;
19
20     // Properties -------------------------------------------------
21

22     public void setUploadedItem(File JavaDoc uploadedItem) {
23         this.uploadedItem = uploadedItem;
24     }
25
26     public void setUploadedItemContentType(String JavaDoc uploadedItemContentType) {
27         this.uploadedItemContentType = uploadedItemContentType;
28     }
29
30     public void setUploadedItemFileName(String JavaDoc uploadedItemFileName) {
31         this.uploadedItemFileName = uploadedItemFileName;
32     }
33
34     // Methods -------------------------------------------------
35

36     public String JavaDoc execute() throws Exception JavaDoc {
37         return SUCCESS;
38     }
39
40     public String JavaDoc attemptUpload() throws Exception JavaDoc {
41         if (uploadedItem != null) {
42             addActionMessage("Uploaded File: " + uploadedItemFileName +
43                     ", with a contentType of " + uploadedItemContentType);
44         } else {
45             addActionError("File upload unsuccessful. Please verify that the file is allowed and within the size limits.");
46         }
47
48         return SUCCESS;
49     }
50 }
51
Popular Tags