⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadfileform.java

📁 用Hibernate开发的JiveJdon
💻 JAVA
字号:
/*
 * Copyright 2003-2006 the original author or authors.
 * 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 com.jdon.jivejdon.presentation.form;


import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;

import com.jdon.jivejdon.model.ForumMessage;
import com.jdon.jivejdon.model.message.upload.UploadHelper;

/**
 * @author <a href="mailto:banqiao@jdon.com">banq</a>
 *
 */
public class UpLoadFileForm extends BaseForm {
    
    private UploadHelper uploadHelper;

    private String contextPath;
    
    private String applicationPath;
    
    private Long fileId;
    
    private String tempId;    
    
    private int size;
    
    private String name;

    private FormFile theFile;

    
    private ForumMessage forumMessage = new ForumMessage();
    
    
    private boolean authenticated= true;

	public boolean isAuthenticated() {
		return authenticated;
	}

	public void setAuthenticated(boolean authenticated) {
		this.authenticated = authenticated;
	}
	
    
    public UpLoadFileForm() {
        this.uploadHelper = new UploadHelper();
    }

    public void setTheFile(FormFile theFile) {
        this.theFile = theFile;
    }
    
    
	/**
     * Check to make sure the client hasn't exceeded the maximum allowed upload
     * size inside of this validate method.
     */
    public void doValidate(ActionMapping mapping, HttpServletRequest request, List errors) {

        //has the maximum length been exceeded?
        Boolean maxLengthExceeded = (Boolean) request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
        if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {

            errors.add("exceed the upload max length");

        } else if (theFile != null) {
            //retrieve the file name
             String fileName = theFile.getFileName();
             if (!uploadHelper.canBeUpload(fileName))
                errors.add(new ActionMessage("illegal file type! "));
        }

    }
   
   
    /**
     * @return Returns the fileTypes.
     */
    public List getFileTypes() {
        return uploadHelper.getFileTypes();
    }       
    
   
    /**
     * @return Returns the imagesTypes.
     */
    public List getImagesTypes() {
        return uploadHelper.getImagesTypes();
    }



	public Long getFileId() {
		return fileId;
	}

	public void setFileId(Long fileId) {
		this.fileId = fileId;
	}


   public String getName() {
	        if (theFile!= null)
	           return theFile.getFileName();
	        return "";
   }
	    
   public int getSize() {
	        try {
	            if (theFile != null){
	                int size = theFile.getFileSize();
	                return size/1000;
	            }
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return 0;
   }
   
   public byte[] getData() {
       try {
           if (theFile != null)
               return theFile.getFileData();
       } catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
       return null;
   }
   
   /**
    * @return Returns the contentType.
    */
   public String getContentType() {
       try {
           if (theFile != null){
               return theFile.getContentType();
           }
       } catch (Exception e) {
           e.printStackTrace();
       }
       return "html/text";
   }

	public void setSize(int size) {
		this.size = size;
	}

	
	public void setName(String name) {
		this.name = name;
	}

	public FormFile getTheFile() {
		return theFile;
	}


	public ForumMessage getForumMessage() {
		return forumMessage;
	}

	public void setForumMessage(ForumMessage forumMessage) {
		this.forumMessage = forumMessage;
	}


	public void setTempId(String tempId) {
		this.tempId = tempId;
	}

	public String getTempId() {
		return tempId;
	}

	public String getContextPath() {
		return contextPath;
	}

	public void setContextPath(String contextPath) {
		this.contextPath = contextPath;
	}

	public String getApplicationPath() {
		return applicationPath;
	}

	public void setApplicationPath(String applicationPath) {
		this.applicationPath = applicationPath;
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -