001: /**
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: * --------------------------------------------------------------------------
017: * $Id: UploadForm.java 7486 2005-10-07 22:30:10Z glapouch $
018: * --------------------------------------------------------------------------
019: */package org.objectweb.jonas.webapp.jonasadmin.deploy;
020:
021: import javax.servlet.http.HttpServletRequest;
022:
023: import org.apache.struts.action.ActionErrors;
024: import org.apache.struts.action.ActionForm;
025: import org.apache.struts.action.ActionMapping;
026: import org.apache.struts.action.ActionMessage;
027: import org.apache.struts.action.ActionMessages;
028: import org.apache.struts.upload.FormFile;
029: import org.apache.struts.upload.MultipartRequestHandler;
030:
031: /**
032: * This class is a placeholder for form values. In a multipart request, files are represented by
033: * set and get methods that use the class org.apache.struts.upload.FormFile, an interface with
034: * basic methods to retrieve file information. The actual structure of the FormFile is dependant
035: * on the underlying impelementation of multipart request handling. The default implementation
036: * that struts uses is org.apache.struts.upload.CommonsMultipartRequestHandler.
037: *
038: * @version $Rev: 7486 $ $Date: 2005-10-07 22:30:10 +0000 (Fri, 07 Oct 2005) $
039: */
040: public class UploadForm extends ActionForm {
041:
042: /**
043: * The file that the user has uploaded
044: */
045: private FormFile uploadedFile;
046:
047: /**
048: * Is the current context a domain management action?
049: */
050: private boolean isDomain;
051:
052: /**
053: * Is the current type of deployment currently configurable?
054: */
055: private boolean isConfigurable;
056:
057: /**
058: * Overwrite value
059: */
060: private boolean overwrite = false;
061:
062: /**
063: * Return if the action is a domain management operation.
064: * @return if the action is a domain management operation.
065: */
066: public boolean getIsDomain() {
067: return this .isDomain;
068: }
069:
070: /**
071: * Sets if the action is a domain management operation.
072: * @param isDomain if the action is a domain management operation.
073: */
074: public void setIsDomain(boolean isDomain) {
075: this .isDomain = isDomain;
076: }
077:
078: /**
079: * @return a representation of the file the user has uploaded
080: */
081: public FormFile getUploadedFile() {
082: return uploadedFile;
083: }
084:
085: /**
086: * Set a representation of the file the user has uploaded
087: * @param uploadedFile the file uploaded
088: */
089: public void setUploadedFile(FormFile uploadedFile) {
090: this .uploadedFile = uploadedFile;
091: }
092:
093: /**
094: * Check to make sure the client hasn't exceeded the maximum allowed upload size inside of this
095: * validate method.
096: * @param mapping the mapping used to select this instance
097: * @param request the servlet request we are processing
098: * @return Errors if it fails
099: */
100: public ActionErrors validate(ActionMapping mapping,
101: HttpServletRequest request) {
102:
103: ActionErrors errors = null;
104: //has the maximum length been exceeded?
105: Boolean maxLengthExceeded = (Boolean) request
106: .getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
107:
108: if ((maxLengthExceeded != null)
109: && (maxLengthExceeded.booleanValue())) {
110: errors = new ActionErrors();
111: errors.add(ActionMessages.GLOBAL_MESSAGE,
112: new ActionMessage("maxLengthExceeded"));
113: errors.add(ActionMessages.GLOBAL_MESSAGE,
114: new ActionMessage("maxLengthExplanation"));
115: }
116: return errors;
117:
118: }
119:
120: /**
121: * @return true if the file will be overwritten
122: */
123: public boolean isOverwrite() {
124: return overwrite;
125: }
126:
127: /**
128: * Replace the existing file ?
129: * @param overwrite true/false
130: */
131: public void setOverwrite(boolean overwrite) {
132: this .overwrite = overwrite;
133: }
134:
135: /**
136: * Return if the current deployment type is configurable.
137: * @return if the current deployment type is configurable.
138: */
139: public boolean getIsConfigurable() {
140: return this .isConfigurable;
141: }
142:
143: /**
144: * Sets if the current deployment type is configurable.
145: * @param isDomain if current deployment type is configurable.
146: */
147: public void setIsConfigurable(boolean isConfigurable) {
148: this.isConfigurable = isConfigurable;
149: }
150: }
|