View Javadoc
1 /* 2 * PROJECT : DAR Runtime and Tools 3 * COPYRIGHT : Copyright (C) 1999-2004 tim.stephenson@enableit.org 4 * LICENSE : GNU LESSER GENERAL PUBLIC LICENSE 5 * Version 2.1, February 1999 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 */ 21 package org.enableit.db.darrt.web; 22 23 import javax.servlet.http.HttpServletRequest; 24 25 import org.apache.log4j.Category; 26 import org.apache.struts.action.ActionError; 27 import org.apache.struts.action.ActionErrors; 28 import org.apache.struts.action.ActionForm; 29 import org.apache.struts.action.ActionMapping; 30 import org.apache.struts.upload.FormFile; 31 import org.apache.struts.upload.MultipartRequestHandler; 32 33 34 /*** 35 * Struts form supporting the Upload Action. 36 * 37 * @author Tim Stephenson (based on Struts upload example) 38 * 39 * @struts:form name="UploadForm" 40 */ 41 public class UploadForm extends ActionForm { 42 public static final String ERROR_PROPERTY_MAX_LENGTH_EXCEEDED = "org.apache.struts.webapp.upload.MaxLengthExceeded"; 43 44 /*** 45 * The Log4J <code>Category</code> doing the logging. 46 */ 47 private static Category logger = Category.getInstance(UploadForm.class); 48 49 /*** 50 * The value of the text the user has sent as form data 51 */ 52 private String theText; 53 54 /*** 55 * Whether or not to write to a file 56 */ 57 private boolean writeFile = true; 58 59 /*** 60 * The file that the user has uploaded 61 */ 62 private FormFile theFile; 63 64 /*** 65 * The file path to write to 66 */ 67 private String filePath; 68 69 /*** 70 * Default constructor. 71 */ 72 public UploadForm() { 73 super(); 74 } 75 76 /*** 77 * Retrieve the value of the text the user has sent as form data 78 */ 79 public String getTheText() { 80 return theText; 81 } 82 83 /*** 84 * Set the value of the form data text 85 */ 86 public void setTheText(String theText) { 87 this.theText = theText; 88 } 89 90 /*** 91 * Retrieve a representation of the file the user has uploaded 92 */ 93 public FormFile getTheFile() { 94 logger.info("METHOD_ENTRY: getTheFile"); 95 logger.info("METHOD_EXIT: getTheFile, theFile: " + theFile); 96 97 return theFile; 98 } 99 100 /*** 101 * Set a representation of the file the user has uploaded 102 */ 103 public void setTheFile(FormFile theFile) { 104 this.theFile = theFile; 105 } 106 107 /*** 108 * Set whether or not to write to a file 109 */ 110 public void setWriteFile(boolean writeFile) { 111 this.writeFile = writeFile; 112 } 113 114 /*** 115 * Get whether or not to write to a file 116 */ 117 public boolean getWriteFile() { 118 return writeFile; 119 } 120 121 /*** 122 * Set the path to write a file to 123 */ 124 public void setFilePath(String filePath) { 125 this.filePath = filePath; 126 } 127 128 /*** 129 * Get the path to write a file to 130 */ 131 public String getFilePath() { 132 return filePath; 133 } 134 135 public void reset() { 136 writeFile = false; 137 } 138 139 /*** 140 * Check to make sure the client hasn't exceeded the maximum allowed 141 * upload size inside of this validate method. 142 */ 143 public ActionErrors validate(ActionMapping mapping, 144 HttpServletRequest request) { 145 ActionErrors errors = null; 146 147 //has the maximum length been exceeded? 148 Boolean maxLengthExceeded = (Boolean) request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED); 149 150 if ((maxLengthExceeded != null) && maxLengthExceeded.booleanValue()) { 151 errors = new ActionErrors(); 152 errors.add(ERROR_PROPERTY_MAX_LENGTH_EXCEEDED, 153 new ActionError("maxLengthExceeded")); 154 } 155 156 return errors; 157 } 158 }

This page was automatically generated by Maven