com.wabacusdemo.TestFileUploadInterceptor.java Source code

Java tutorial

Introduction

Here is the source code for com.wabacusdemo.TestFileUploadInterceptor.java

Source

/* 
 * Copyright (C) 2010-2012 <349446658@qq.com>
 * 
 * This file is part of Wabacus 
 * 
 * Wabacus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.wabacusdemo;

import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem;

import com.wabacus.system.intercept.AbsFileUploadInterceptor;

public class TestFileUploadInterceptor extends AbsFileUploadInterceptor {
    public boolean beforeDisplayFileUploadInterface(HttpServletRequest request,
            Map<String, String> mFormAndConfigValues, PrintWriter out) {
        String inputboxid = null;
        String param_no = null;
        String param_name = null;
        String param_txtno = null;
        String oldvalue = null;
        String testfieldname = null;
        if (mFormAndConfigValues != null) {//??
            inputboxid = mFormAndConfigValues.get("INPUTBOXID");
            if (inputboxid != null && !inputboxid.trim().equals("")) {//????request????enctype="multipart/form-data"mFormAndConfigValues???
                param_no = mFormAndConfigValues.get("param_no");
                param_name = mFormAndConfigValues.get("param_name");
                param_txtno = mFormAndConfigValues.get("param_txtno");
                oldvalue = mFormAndConfigValues.get("OLDVALUE");
            }
            testfieldname = mFormAndConfigValues.get("testfieldname");
            System.out.println("????.........");
        } else {//??
            inputboxid = request.getParameter("INPUTBOXID");
            if (inputboxid != null && !inputboxid.trim().equals("")) {//??
                param_no = request.getParameter("param_no");
                param_name = request.getParameter("param_name");
                param_txtno = request.getParameter("param_txtno");
                oldvalue = request.getParameter("OLDVALUE");
            }
            testfieldname = request.getParameter("testfieldname");
            System.out.println("??.........");
        }
        if (inputboxid != null && !inputboxid.trim().equals("")) {//?fileuploadpage1.report5<inputbox inputboxparams="param_no=@{no}&amp;param_name=@{name}&amp;param_txtno=condition{txtno}"???
            out.println("??<b>?</b>" + param_no + ";<b>??</b>" + param_name
                    + ";<b>??</b>" + param_txtno + ";<b></b>" + oldvalue
                    + "<hr>");
        }
        testfieldname = testfieldname == null ? "" : testfieldname.trim();
        out.println("?<input type='text' name='testfieldname' value='" + testfieldname + "'><hr>");
        return true;
    }

    public boolean beforeFileUpload(HttpServletRequest request, FileItem fileitemObj,
            Map<String, String> mFormAndConfigValues, PrintWriter out) {
        String testfieldvalue = mFormAndConfigValues.get("testfieldname");//???
        if (testfieldvalue == null)
            testfieldvalue = "";
        String inputboxid = mFormAndConfigValues.get(INPUTBOXID_KEY);
        if (inputboxid != null && !inputboxid.trim().equals("")) {//
            String filename = mFormAndConfigValues.get(FILENAME_KEY);//????
            String savedvalue = filename;
            if (!testfieldvalue.trim().equals(""))
                testfieldvalue = "(" + testfieldvalue + ")";
            savedvalue = testfieldvalue + savedvalue + "[" + fileitemObj.getSize() / 1024 + "kb]";//???
            mFormAndConfigValues.put(SAVEVALUE_KEY, savedvalue);//??
        } else {//
            if (testfieldvalue != null && !testfieldvalue.trim().equals("")) {
                out.println("?" + testfieldvalue + "<br>");
            }
            if (fileitemObj != null) {
                out.println("?" + fileitemObj.getSize() + "<br>");
            }
        }
        return true;//?
    }

    /**
     * ??/??????
     */
    public boolean beforeDisplayFileUploadPrompt(HttpServletRequest request, List lstFieldItems,
            Map<String, String> mFormAndConfigValues, String failedMessage, PrintWriter out) {
        if (lstFieldItems == null || lstFieldItems.size() == 0)
            return true;
        FileItem fItemTmp;
        StringBuffer fileNamesBuf = new StringBuffer();
        for (int i = 0; i < lstFieldItems.size(); i++) {
            fItemTmp = (FileItem) lstFieldItems.get(i);
            if (fItemTmp.isFormField())
                continue;//?
            fileNamesBuf.append(fItemTmp.getName()).append(";");
        }
        if (fileNamesBuf.charAt(fileNamesBuf.length() - 1) == ';')
            fileNamesBuf.deleteCharAt(fileNamesBuf.length() - 1);
        if (failedMessage != null && !failedMessage.trim().equals("")) {//
            out.println("<h4>??" + fileNamesBuf.toString() + "" + failedMessage
                    + "</h4>");
        } else {//?
            out.println("<script language='javascript'>");
            out.println("alert('" + fileNamesBuf.toString() + "?');");

            String inputboxid = mFormAndConfigValues.get("INPUTBOXID");
            if (inputboxid != null && !inputboxid.trim().equals("")) {//?
                String name = mFormAndConfigValues.get("param_name");
                name = name + "[" + fileNamesBuf.toString() + "]";
                out.println("selectOK('" + name + "','name',null,true);");
            }
            out.println("</script>");
        }
        return false;//????
    }

}