`

开发使用的一些常用方法

阅读更多
/**
*常用工具包
*/
package com.cmsz.common.util;

import java.io.File;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.CRC32;
import java.util.zip.CheckedOutputStream;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/***************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
* Copyright China-Mobile(SZ) 2005. All rights reserved.
*
* @file: Tools.java
* @date: 2005/09/28
* @brief: 常用工具包
* @author: fkueje001
* @version: 1.0.0 Other: Change Log: <author> <time> <version> <description> fkueje001 2005/09/28 1.0.0 create
**************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************/

public class Tools {
public static HashMap hs_transaction=new HashMap();

    /**
     * 返回系统当前年月日时分秒
     */
public static String lastRecFirstMonth()
{
Calendar car=Calendar.getInstance();
car.add(Calendar.MONTH, -1);
//car.add(Calendar.DATE, -1);
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
return format.format(car.getTime());
// return car.get(Calendar.YEAR)+"-"+(car.get(Calendar.MONTH)+1)+"-"+car.get(Calendar.DAY_OF_MONTH);
}

public static String currenctDate()
{
Calendar car=Calendar.getInstance();
//car.add(Calendar.MONTH, -1);
//car.add(Calendar.DATE, -1);
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
return format.format(car.getTime());
// return car.get(Calendar.YEAR)+"-"+(car.get(Calendar.MONTH)+1)+"-"+car.get(Calendar.DAY_OF_MONTH);
}
    public static String getDBDateTime() {     
        Calendar car=Calendar.getInstance(); 
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(car.getTime());
    }

    /**
     * 返回系统当前日期
     */
    public static String getDBDate() {
      Calendar car=Calendar.getInstance(); 
          SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
          return format.format(car.getTime());       
    }

    /**
     * 返回数据库处理结果
     */
    public static String getDBDate(String paramStr) {
        ConversionBean convert = new ConversionBean();
        String temp = "select " + paramStr + " from dual";
        convert.setSql(temp);
        temp = convert.getConversionBean();
        return temp;
    }

    /**
     * 返回系统当前日期
     */
    public static java.sql.Date getDate() {

        /**
         * Calendar calendar = Calendar.getInstance(); int day = calendar.get(Calendar.DAY_OF_MONTH); int month = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); String date = year+"-"+month+"-"+day; return date;
         */
        java.util.Calendar calendar = java.util.Calendar.getInstance();
        // java.sql.Date dd=new java.sql.Date(calendar.get(Calendar.YEAR)-1900,calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH));
        java.util.Date ss = new java.util.Date();
        java.sql.Date dd = new java.sql.Date(ss.getTime());

        /**
         * java.util.Date ss=new java.util.Date(); //java.sql.Date dd=java.sql.Date.valueOf(ss.toString()); getTime java.sql.Date dd=new java.sql.Date(ss.getTime()); System.out.println(ss.toString());
         */
        return dd;
    }

    /**
     * 空判断处理
     */
    public static boolean isEmpty(String input) {
        if (input == null) {
            return true;
        }
        if ("".equals(input.trim())) {
            return true;
        }
        return false;
    }

    /**
     * 校验是否数字
     */
    public static boolean isDigit(String input) {
        if (Tools.isEmpty(input)) {
            return false;
        }
        boolean reUse = false;
        for (int i = 0; i < input.length(); i++) {

            if (input.indexOf(".") == 0 || input.indexOf(".") == input.length()) {
                return false;
            }
            // 是否有多余的.
            if (input.substring(i, i + 1).equals(".")) {

                if (!reUse) {
                    reUse = true;
                    continue;
                } else {
                    return false;
                }

            }

            if (!Character.isDigit(input.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * double参数,进行给定精度格式化
     */
    public static String numberFormat(double parameter, int digit) {
        StringBuffer temp = new StringBuffer();
        for (int i = 0; i < digit; i++) {
            temp.append("0");
        }
        DecimalFormat df2 = new DecimalFormat("###0." + temp.toString());
        return df2.format(parameter);
    }

    /**
     * 空对象处理
     */
    public static String checkNull(Object ob) {
        if ((ob == null) || (ob.equals("null"))) {
            return "";
        } else {
            return ob.toString();
        }
    }

    /**
     * 空对象"0"处理
     */
    public static String checkNullNum(Object ob) {
        if ((ob == null) || (ob.equals("null")) || (ob.equals(""))) {
            return "0";
        } else {
            return ob.toString();
        }
    }
    /**
     * 空对象"0"处理
     */
    public static String checkNullTitle(Object ob) {
        if ((ob == null) || (ob.equals("null")) || (ob.equals(""))) {
            return "";
        } else {
            return ob.toString();
        }
    }
   
    /**
     * 空对象处理(用于数据库操作)
     */
    public static String checkDBNull(Object ob) {
        if ((ob == null) || (ob.equals(""))) {
            return "null";
        } else {
            return ob.toString();
        }
    }

    /**
     * 定义默认查询列表的行图标
     */
    public static String getListImage() {
        return "/images/dot.gif";
    }

    /**
     * 输出给定脚本的完整javaScripts语法
     */
    public static String outScripts(String Str) {
        return "<SCRIPT LANGUAGE=\"JavaScript\"> " + Str + " </script>";
    }

 

    /**
     * 输出给定session中的变量信息,输出结束,然后,删除.
     */
    public static String outInfo(HttpSession session, String varStr, String type) {
        String out_str = "";

        if (type.equals("1")) {
            if (!isEmpty((String) session.getAttribute(varStr))) {
                out_str = "<SCRIPT LANGUAGE=\"JavaScript\"> ";
                out_str = out_str
                        + "alert(\""
                        + DoTextBean.replace((String) session
                                .getAttribute(varStr), "<br>", "") + "\");";
                out_str = out_str + "  </SCRIPT>";
                session.removeAttribute(varStr);
            }
        } else {
            if (!isEmpty((String) session.getAttribute(varStr))) {

                session.setAttribute("returnType", "close");
                session.removeAttribute("returnPage");
                out_str = "<SCRIPT LANGUAGE=\"JavaScript\"> ";

                String str = "'scrollbars=yes,resizable=yes, Height='+(screen.availheight-400)+',Width='+(screen.width-300)+',top=50,left=50'";
                out_str = out_str
                        + "window.open(\"/jsp/common/success.jsp\",''," + str
                        + ");";
                out_str = out_str + "  </SCRIPT>";

            }
        }

        return out_str;
    }

    /**
     * 输出给定request中的变量信息,输出结束,然后,删除.
     */
    public static String outInfo(HttpServletRequest request, String varStr) {
        String out_str = "";

        if (!isEmpty((String) request.getAttribute(varStr))) {
            out_str = "<SCRIPT LANGUAGE=\"JavaScript\"> ";
            out_str = out_str
                    + "alert(\""
                    + DoTextBean.replace((String) request.getAttribute(varStr),
                            "<br>", "") + "\");";
            out_str = out_str + "  </SCRIPT>";
            request.removeAttribute(varStr);
        }
        return out_str;

    }

    /**
     * 输出给定request中的变量信息,输出结束,然后,删除.
     */
    public static String outInfo(HttpServletRequest request,
            HttpSession session, String varStr, String type) {
        String out_str = "";

        if (type.equals("1")) {
            if (!isEmpty((String) request.getAttribute(varStr))) {
                out_str = "<SCRIPT LANGUAGE=\"JavaScript\"> ";
                out_str = out_str
                        + "alert(\""
                        + DoTextBean.replace((String) request
                                .getAttribute(varStr), "<br>", "") + "\");";
                out_str = out_str + "  </SCRIPT>";
                request.removeAttribute(varStr);
            }
        } else {
            if (!isEmpty((String) request.getAttribute(varStr))) {

                session.setAttribute("returnType", "close");
                session.setAttribute(varStr, (String) request
                        .getAttribute(varStr));
                session.removeAttribute("returnPage");
                request.removeAttribute(varStr);
                out_str = "<SCRIPT LANGUAGE=\"JavaScript\"> ";

                String str = "'scrollbars=yes,Height='+(screen.availheight-200)+',Width='+(screen.width-250)+',top=50,left=50'";

                out_str = out_str
                        + "window.open(\"/jsp/common/success.jsp\",''," + str
                        + ");";
                out_str = out_str + "  </SCRIPT>";

            }
        }

        return out_str;
    }

    /**
     * 提示给定字符串的信息.
     */
    public static String outInfo(String outInfo) {
        if (isEmpty(outInfo)) {
            return "";
        }
        outInfo = DoTextBean.replace(outInfo, "<br>", "");
        String outStr = null;
        outStr = "<SCRIPT LANGUAGE=\"JavaScript\"> ";
        outStr = outStr + "alert(\"" + outInfo + "\");";
        outStr = outStr + "  </SCRIPT>";
        return outStr;
    }

    /**
     * 输出图片单击函数参数的javaScripts语法,主要用于查询列表业务控制的image button服务
     */
    public static String outClick(String Str) {
        if (isEmpty(Str)) {
            return "";
        } else {
            return " onclick='" + Str + " ; return false;'";
        }
    }

   
  

    /**
     * 返回系统当前时间
     */
    public static String getTime() {
        java.util.Date ss = new java.util.Date();
        return String.valueOf(ss.getTime());
    }

    /**
     * 字符串转为日期类型
     */
    public static java.sql.Date convertDate(String param) {

        java.sql.Date returnDate = null;
        if (!isEmpty(param)) {
            returnDate = java.sql.Date.valueOf(param);
        }
        return returnDate;
    }

    /**
     * 字符串转为time类型
     */
    public static java.sql.Time convertTime(String param) {

        java.sql.Time returnTime = null;
        if (!isEmpty(param)) {
            returnTime = java.sql.Time.valueOf(param);
        }
        return returnTime;

    }

    /**
     * 字符串转为Datetime类型
     */
    public static java.sql.Timestamp convertDatatime(String param) {

        java.sql.Timestamp returnTime = null;
        if (!isEmpty(param)) {
            returnTime = java.sql.Timestamp.valueOf(param);
        }
        return returnTime;

    }

    /**
     * 返回给定文件的扩展名
     */
    public static String getFileExtName(String fileName) {

        return fileName.substring(fileName.lastIndexOf("."), fileName.length());
    }

    /**
     * @brief: 取参数表(sys_param)中参数值
     * @param paramType
     *            参数类型
     * @param code
     *            参数代码
     * @return 参数代码code对应的参数值;
     */
    public static Sys_paramVo getParam(String paramType, String code) {
        Sys_paramVo returnVo = null;
        try {
//             String codeName = null;
//             ConversionBean getValueObject = new ConversionBean();
//             getValueObject.setSql(ICommonPolicy.getParamSql
//             + "where index_type = '" + paramType + "' and index_code='"
//             + code + "'");
//             codeName = getValueObject.getConversionBean();
//             return codeName;
       
            List sysList = null;
            sysList = new ArrayList();
            Delegate cachesDel = new Delegate();
            List list1 = (List) cachesDel.getCashDataList("sys_param");
            String index_code = "";
            String index_type = "";

            Sys_paramVo vo = null;
            for (int i = 0; i < list1.size(); i++) {
                vo = (Sys_paramVo) list1.get(i);
                index_code = vo.getIndex_code();
                index_type = vo.getIndex_type();
                if (paramType.equals(index_type) && (code.equals(index_code))) {
                    returnVo = vo;
                    break;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();

        }
        return returnVo;
    }

    /**
     * @brief: 取参数表(sys_param)中参数值 依次根据参数类型,索引,代码,取代码值
     */
    public static String getParamNumCode(String indexType, String indexNum,
            String indexCode) {
        try {
            String indexValue = null;
            ConversionBean getValueObject = new ConversionBean();
            getValueObject.setSql(ICommonPolicy.getParamSql
                    + "where index_type = '" + indexType + "' and index_num='"
                    + indexNum + "' and index_code='" + indexCode + "'");
            indexValue = getValueObject.getConversionBean();
            return indexValue;

        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    /**
     * @brief: 取参数表(sys_param)中参数值 依次根据参数类型,索引,取代码值
     */
    public static String getParamNum(String indexType, String indexNum) {
        try {
            String indexValue = null;
            ConversionBean getValueObject = new ConversionBean();
            getValueObject.setSql(ICommonPolicy.getParamSql
                    + "where index_type = '" + indexType + "' and index_num="
                    + indexNum);
            indexValue = getValueObject.getConversionBean();
            return indexValue;

        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getParamNumWhere(String indexType, String indexNum,
            String whereStr) {
        try {
            String indexValue = null;
            ConversionBean getValueObject = new ConversionBean();
            getValueObject.setSql(ICommonPolicy.getParamSql
                    + "where index_type = '" + indexType + "' and index_num="
                    + indexNum + whereStr);
            indexValue = getValueObject.getConversionBean();
            return indexValue;

        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    /**
     * @brief:根据错误信息标题和详细错误信息统一生成提示信息。
     * @param infoName
     *            错误信息标题
     * @param infoDetail
     *            详细错误信息
     * @return 在公共提示页面要显示的信息;
     */
    public static String getErrNote(String infoName, String infoDetail) {
        try {
            String rnStr = null;
            if (infoName == null) {
                infoName = "";
            }
            if (infoDetail == null) {
                infoDetail = "";
            }
            rnStr = "<div  align='center' >操作错误</div><br>&nbsp;&nbsp;"
                    + "错误说明:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                    + infoName + "<br>&nbsp;&nbsp;详细错误:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + infoDetail;
            return rnStr;

        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    /**
     * @brief:根据信息标题统一生成提示信息。
     * @param infoName
     *            信息标题
     * @return 在公共提示页面要显示的信息;
     */
    public static String getOkNote(String infoName) {
        try {
            String rnStr = null;
            if (infoName == null) {
                infoName = "";
            }
            rnStr = "操作完成!<br>处理结果:<br>" + infoName;
            return rnStr;

        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

  

    /**
     * if参数为空,则返回当前日期(格式:2004-9-5) 否则直接返回原参数值。 主要用于页面结束时间默认值处理
     */
    public static String getCurDtIfNullEnd(String paramValue) {
        String endDate = null;
        if (Tools.isEmpty(paramValue))
        // 取当前值
        {
            // DateBean dateBean = new DateBean();
            // endDate = dateBean.getPageDate();
            ConversionBean convert = new ConversionBean();
            convert.setSql("select to_char(sysdate,'YYYY-MM-DD') from dual");
            endDate = convert.getConversionBean();

            return endDate;
        } else {
            return paramValue;
        }
    }

    /**
     * if参数为空,则返回当前日期早3天的日期(格式:2004-9-5) 否则直接返回原参数值。 主要用于页面开始时间默认值处理
     */
    public static String getCurDtIfNullBegin(String paramValue) {
        String endDate = null;
        if (Tools.isEmpty(paramValue))
        // 取当前值
        {
            // DateBean dateBean = new DateBean();
            // endDate = dateBean.getDateBeforeToDay(3);
            ConversionBean convert = new ConversionBean();
            convert.setSql("select to_char(sysdate-3,'YYYY-MM-DD') from dual");
            endDate = convert.getConversionBean();
            return endDate;
        } else {
            return paramValue;
        }
    }

    // 取当系统当前时间
    public static String getCurDateTime() {
          ConversionBean convert = new ConversionBean();
            convert.setSql("select to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') from dual");         
            return convert.getConversionBean();
      
    }
    /**
     * if参数为空,则返回当前日期早1月的日期(格式:2004-9-5) 否则直接返回原参数值。 主要用于页面开始时间默认值处理
     */
    public static String getCurMonthIfNullBegin(String paramValue) {
        String endDate = null;
        if (Tools.isEmpty(paramValue))
        // 取当前值
        {
            ConversionBean convert = new ConversionBean();
            convert
                    .setSql("select to_char(add_months(sysdate,-1),'YYYY-MM-DD') from dual");
            endDate = convert.getConversionBean();
            return endDate;
        } else {
            return paramValue;
        }
    }

    /**
     * 如果paramValue参数为空,则返回当前日期-dtInterval的日期(格式:2005-03-25) 如果paramValue不为空,则直接返回paramValue 主要用于页面开始时间默认值处理
     */
    public static String getPageDtIfNull(String paramValue, int dtInterval) {
        String pageDate = null;
        if (paramValue == null) {
            ConversionBean convert = new ConversionBean();
            convert.setSql("select to_char(sysdate-" + dtInterval
                    + ",'YYYY-MM-DD') from dual");
            pageDate = convert.getConversionBean();
            return pageDate;
        } else {
            // 直接返回
            return paramValue;
        }
    }

    /**
     * 如果paramValue参数为空,则返回当前日期-dtInterval的日期(格式:2005-03-25) 如果paramValue不为空,则直接返回paramValue 主要用于页面开始时间默认值处理 增加对"NULL"的判断
     */
    public static String getPageDateTimeIfNull(String paramValue, int dtInterval) {
        String pageDate = null;
        if (paramValue == null || "null".equalsIgnoreCase(paramValue)) {
            ConversionBean convert = new ConversionBean();
            convert.setSql("select to_char(sysdate -  "  + dtInterval
                    + ",'YYYY-MM-DD') from dual");
            pageDate = convert.getConversionBean();
            return pageDate;
        } else {
            // 直接返回
            return paramValue;
        }
    }

   
   
    public static String getDateAdd(String paramValue, int dtInterval) {
        String pageDate = null;
        if (paramValue == null || "null".equalsIgnoreCase(paramValue)) {
            ConversionBean convert = new ConversionBean();
            convert.setSql("select to_char(sysdate +  "  + dtInterval
                    + ",'YYYY-MM-DD') from dual");
            pageDate = convert.getConversionBean();
            return pageDate;
        } else {
            // 直接返回
            return paramValue;
        }
    }
    /**
     * 如果paramValue参数为空,则返回当前日期-dtInterval的月份(格式:03) 如果paramValue不为空,则直接返回paramValue 主要用于页面开始时间默认值处理
     */
    public static String getPageMonthIfNull(String paramValue, int dtInterval) {
        String pageDate = null;
        if (Tools.isEmpty(paramValue)) {
            ConversionBean convert = new ConversionBean();
            convert.setSql("select to_char(add_months(sysdate,-" + dtInterval
                    + "),'MM') from dual");
            pageDate = convert.getConversionBean();
            return pageDate;
        } else {
            // 直接返回
            return paramValue;
        }
    }

    /**
     * 如果paramValue参数为空,则返回当前日期-dtInterval的月份(格式:200503) 如果paramValue不为空,则直接返回paramValue 主要用于页面开始时间默认值处理
     */
    public static String getPageYearMonthIfNull(String paramValue,
            int dtInterval) {
        String pageDate = null;
        if (Tools.isEmpty(paramValue)) {
            ConversionBean convert = new ConversionBean();
            convert.setSql("select to_char(add_months(sysdate,-" + dtInterval
                    + "),'YYYYMM') from dual");
            pageDate = convert.getConversionBean();
            return pageDate;
        } else {
            // 直接返回
            return paramValue;
        }
    }

    /**
     * 如果paramValue参数为空,则返回当前日期-dtInterval的年月(格式:200503) 如果paramValue不为空,则返回paramValue - dtInterval的年月(格式:200503) 主要用于页面开始时间默认值处理
     */
    public static String getAddMonths(String paramValue, int dtInterval) {
        String pageDate = null;
        ConversionBean convert = new ConversionBean();
        if (Tools.isEmpty(paramValue)) {
            convert.setSql("select to_char(add_months(sysdate,-" + dtInterval
                    + "),'YYYYMM') from dual");
        } else {
            convert.setSql("select to_char(add_months(to_date( '" + paramValue
                    + "', " + " 'yyyy-mm-dd'),-" + dtInterval
                    + "),'YYYYMM') from dual");
        }
        pageDate = convert.getConversionBean();
        return pageDate;
    }

    /**
     * 生成年选择框,范围为:2000-2050
     */
    public static String outYearDDlist(String selectName, String defaultValue1,
            String property) {
        String defaultValue = defaultValue1;
        int yearBegin = 1997; // 定义起始年
        int yearEnd = 2017; // 定义结束年
        DateBean dateBean = new DateBean();
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = dateBean.getYear();
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:55;' class='selectBox' " + property);
        tempString.append(">");
        for (int i = yearBegin; i <= yearEnd; i++) {
            if (defaultValue.trim().equals(new Integer(i).toString())) {
                tempString.append("<option value='" + new Integer(i).toString()
                        + "' selected>" + new Integer(i).toString()
                        + "</option>\n");
            } else {
                tempString.append("<option value='" + new Integer(i).toString()
                        + "' >" + new Integer(i).toString() + "</option>\n");
            }

        }
        tempString.append("</select>");
        return tempString.toString();
    }

    public static String outYearDDlist(String selectName, String defaultValue1) {
        String defaultValue = defaultValue1;
        int yearBegin = 1900; // 定义起始年
        int yearEnd = 2099; // 定义结束年
        DateBean dateBean = new DateBean();
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = dateBean.getYear();
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:55;' class='selectBox' ");
        tempString.append(">");
        for (int i = yearBegin; i <= yearEnd; i++) {
            if (defaultValue.trim().equals(new Integer(i).toString())) {
                tempString.append("<option value='" + new Integer(i).toString()
                        + "' selected>" + new Integer(i).toString()
                        + "</option>\n");
            } else {
                tempString.append("<option value='" + new Integer(i).toString()
                        + "' >" + new Integer(i).toString() + "</option>\n");
            }

        }
        tempString.append("</select>");
        return tempString.toString();
    }

    /**
     * 生成月选择框,范围为:1-12
     */
    public static String outMonthDDlist(String selectName, String defaultValue1) {
        String defaultValue = defaultValue1;
        int monthBegin = 1; // 定义起始月
        int monthEnd = 12; // 定义结束月
        DateBean dateBean = new DateBean();
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = dateBean.getMonth();
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' ");
        tempString.append(">");
        for (int i = monthBegin; i <= monthEnd; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    /**
     * 生成季选择框,范围为:1-4
     */
    public static String outQuarterDDlist(String selectName,
            String defaultValue1) {
        String defaultValue = defaultValue1;
        int quarterBegin = 1;
        int quarterEnd = 4;
        DateBean dateBean = new DateBean();
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = "4";
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' ");
        tempString.append(">");
        for (int i = quarterBegin; i <= quarterEnd; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    /**
     * 生成季选择框,范围为:1-4
     */
    public static String outQuarterDDlist(String selectName,
            String defaultValue1, String property) {
        String defaultValue = defaultValue1;
        int quarterBegin = 1;
        int quarterEnd = 4;
        DateBean dateBean = new DateBean();
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = "4";
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' " + property);
        tempString.append(">");
        for (int i = quarterBegin; i <= quarterEnd; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    public static String outMonthDDlist(String selectName,
            String defaultValue1, String property) {
        String defaultValue = defaultValue1;
        int monthBegin = 1; // 定义起始月
        int monthEnd = 12; // 定义结束月
        DateBean dateBean = new DateBean();
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = dateBean.getMonth();
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' " + property);
        tempString.append(">");
        for (int i = monthBegin; i <= monthEnd; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    /**
     * 生成月选择框,范围为:1-12
     */
    public static String outDayDDlist(String selectName, String defaultValue1) {
        String defaultValue = defaultValue1;
        int dayBegin = 1; // 定义起始日
        int dayEnd = 31; // 定义结束日
        DateBean dateBean = new DateBean();
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = dateBean.getDay();
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' ");
        tempString.append(">");
        for (int i = dayBegin; i <= dayEnd; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    public static String outDayDDlist(String selectName, String defaultValue1,
            String property) {
        String defaultValue = defaultValue1;
        int dayBegin = 1; // 定义起始日
        int dayEnd = 31; // 定义结束日
        DateBean dateBean = new DateBean();
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = dateBean.getDay();
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' " + property);
        tempString.append(">");
        for (int i = dayBegin; i <= dayEnd; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    /**
     * 生成时选择框,范围为:00-23
     */
    public static String outHourDDlist(String selectName, String defaultValue1) {
        String defaultValue = defaultValue1;
        int begin = 0; // 定义起始时
        int end = 23; // 定义结束时
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = "00";
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' ");
        tempString.append(">");
        for (int i = begin; i <= end; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    /**
     * 生成分选择框,范围为:00-59
     */
    public static String outMinuteDDlist(String selectName, String defaultValue1) {
        String defaultValue = defaultValue1;
        int begin = 0; // 定义起始分
        int end = 59; // 定义结束分
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = "00";
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' ");
        tempString.append(">");
        for (int i = begin; i <= end; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    /**
     * 生成秒选择框,范围为:00-59
     */
    public static String outSecondDDlist(String selectName, String defaultValue1) {
        String defaultValue = defaultValue1;
        int begin = 0; // 定义起始秒
        int end = 59; // 定义结束秒
        StringBuffer tempString = new StringBuffer("");
        if (defaultValue == null) {
            defaultValue = "00";
        }
        tempString.append("<select name=" + selectName);
        tempString.append(" style='width:40;'  class='selectBox' ");
        tempString.append(">");
        for (int i = begin; i <= end; i++) {
            if (defaultValue.trim()
                    .equals(getNumStr(new Integer(i).toString()))) {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' selected>"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            } else {
                tempString.append("<option value='"
                        + getNumStr(new Integer(i).toString()) + "' >"
                        + getNumStr(new Integer(i).toString()) + "</option>\n");
            }

        }
        tempString.append("</select>");

        return tempString.toString();
    }

    /**
     * 数字转为两位字符串
     */
    public static String getNumStr(String numStr) {
        String rt = null;
        rt = numStr;
        if (numStr == null) {
            return "";
        }
        if (numStr.length() == 1) {
            rt = "0" + numStr;
        }
        return rt;

    }

    /**
     * 数据追加新的数组元素
     */
    public static String[] arrayAdd(String[] array1, String[] array2) {
        int ai = 0;
        if (array2 == null || array1 == null) {
            return array1;
        }
        ai = array1.length + array2.length;
        String[] retList = new String[ai];

        for (int i = 0; i < array1.length; i++) {
            retList[i] = array1[i];
        }

        for (int i = 0; i < array2.length; i++) {
            retList[ai - array2.length + i] = array2[i];
        }

        return retList;

    }

    /**
     * URL编码
     */
    public static String getEncodeStr(String str) {
        String temp = str;
        if (temp == null) {
            return "";
        }
        try {
            temp = URLEncoder.encode(temp, "UTF-8");
        } catch (Exception e) {
            return "";
        }
        return temp;

    }

    /**
     * URL解码
     */

    public static String getDecodeStr(String str) {
        String temp = str;
        if (temp == null) {
            return "";
        }
        try {
            temp = URLDecoder.decode(temp, "UTF-8");
        } catch (Exception e) {
            return "";
        }
        return temp;

    }

    /**
     * 月份转换函数 MM -> 中文月或 MM ->英文简写月 flag=E,英文,例如May flag=CHN,中文月,例如5月 flag=C,中文月,例如五月
     */
    public static String getShortMonth(String month, String flag) {
        String tempE = "";
        String tempC = "";
        String tempCHN = "";

        try {
            switch (Integer.parseInt(month)) {
            case 1:
                tempE = ICommonPolicy.shortEMonth1;
                tempCHN = ICommonPolicy.shortCHNMonth1;
                tempC = ICommonPolicy.shortCMonth1;
                break;
            case 2:
                tempE = ICommonPolicy.shortEMonth2;
                tempCHN = ICommonPolicy.shortCHNMonth2;
                tempC = ICommonPolicy.shortCMonth2;
                break;
            case 3:
                tempE = ICommonPolicy.shortEMonth3;
                tempCHN = ICommonPolicy.shortCHNMonth3;
                tempC = ICommonPolicy.shortCMonth3;
                break;
            case 4:
                tempE = ICommonPolicy.shortEMonth4;
                tempCHN = ICommonPolicy.shortCHNMonth4;
                tempC = ICommonPolicy.shortCMonth4;
                break;
            case 5:
                tempE = ICommonPolicy.shortEMonth5;
                tempCHN = ICommonPolicy.shortCHNMonth5;
                tempC = ICommonPolicy.shortCMonth5;
                break;
            case 6:
                tempE = ICommonPolicy.shortEMonth6;
                tempCHN = ICommonPolicy.shortCHNMonth6;
                tempC = ICommonPolicy.shortCMonth6;
                break;
            case 7:
                tempE = ICommonPolicy.shortEMonth7;
                tempCHN = ICommonPolicy.shortCHNMonth7;
                tempC = ICommonPolicy.shortCMonth7;
                break;
            case 8:
                tempE = ICommonPolicy.shortEMonth8;
                tempCHN = ICommonPolicy.shortCHNMonth8;
                tempC = ICommonPolicy.shortCMonth8;
                break;
            case 9:
                tempE = ICommonPolicy.shortEMonth9;
                tempCHN = ICommonPolicy.shortCHNMonth9;
                tempC = ICommonPolicy.shortCMonth9;
                break;
            case 10:
                tempE = ICommonPolicy.shortEMonth10;
                tempCHN = ICommonPolicy.shortCHNMonth10;
                tempC = ICommonPolicy.shortCMonth10;
                break;
            case 11:
                tempE = ICommonPolicy.shortEMonth11;
                tempCHN = ICommonPolicy.shortCHNMonth11;
                tempC = ICommonPolicy.shortCMonth11;
                break;
            case 12:
                tempE = ICommonPolicy.shortEMonth12;
                tempCHN = ICommonPolicy.shortCHNMonth12;
                tempC = ICommonPolicy.shortCMonth12;
                break;
            }
        } catch (Exception e) {
            tempE = "";
            tempCHN = "";
            tempC = "";
        }
        if ("E".equals(flag))
            return tempE;
        else if ("CHN".equals(flag))
            return tempCHN;
        else
            return tempC;
    }

    /**
     * 字符串补齐(后面追加) str:原串 strLen:补齐后的长度 ch:补齐用的字符
     */
    public static String strAppendChr(String str, int strLen, String ch) {

        if (Tools.isEmpty(str) || Tools.isEmpty(ch) || (strLen == 0))
            return str;

        if (str.length() >= strLen)
            return str;
        int j = strLen - str.length();
        for (int i = 0; i < j; i++) {
            str = str + ch;
        }
        return str;
    }

    /**
     * 字符串补齐(前面追加) str:原串 strLen:补齐后的长度 ch:补齐用的字符
     */
    public static String strInsertChr(String str, int strLen, String ch) {
        String temp = "";
        if (Tools.isEmpty(str) || Tools.isEmpty(ch) || (strLen == 0))
            return str;

        if (str.length() >= strLen)
            return str;
        int j = strLen - str.length();
        for (int i = 0; i < j; i++) {
            str = ch + str;
        }
        return str;
    }

    /**
     * 时区偏移处理 time1:原时间 offSet:时区偏移量 flag:D:精确到日;S精确到秒 计算公式:time1 - (offSet) + 0800
     */
    public static String getOffSetDate(String time1, String offSet, String flag) {
        String temp = "";
        String temp0 = "";
        String temp1 = "";
        String temp2 = "";
        /* 计算公式为:用time - offSet + 北京时区0800 */

        if (Tools.isEmpty(time1))
            return "";
        if (Tools.isEmpty(offSet))
            return time1;

        try {
            temp0 = offSet.substring(0, 1); // 取出操作符(+/-)
            temp1 = offSet.substring(1, 3); // 取出小时
            temp2 = offSet.substring(3, 5); // 取出分钟(为00或30或45)

            /* 判断时区偏移 */
            if ("+".equals(temp0))
                temp0 = "-";
            else
                temp0 = "+";

            if ("30".equals(temp2)) {// 如果带30分钟
                if ("S".equals(flag))// 精确到秒
                    temp = " TO_CHAR((TO_DATE('" + time1
                            + "','YYYY-MM-DD HH24:MI:SS') " + temp0
                            + " (TO_NUMBER('" + temp1
                            + "') + TO_NUMBER(0.5))/24 "
                            + " + (8/24)),'YYYY-MM-DD HH24:MI:SS') ";
                else
                    // 精确到日
                    temp = " TO_CHAR((TO_DATE('" + time1 + "','YYYY-MM-DD') "
                            + temp0 + " (TO_NUMBER('" + temp1
                            + "') + TO_NUMBER(0.5))/24 "
                            + " + (8/24)),'YYYY-MM-DD HH24:MI:SS')";
            } else if ("45".equals(temp2)) {// 如果带45分钟
                if ("S".equals(flag))// 精确到秒
                    temp = " TO_CHAR((TO_DATE('" + time1
                            + "','YYYY-MM-DD HH24:MI:SS') " + temp0
                            + " (TO_NUMBER('" + temp1
                            + "') + TO_NUMBER(0.75))/24 "
                            + " + (8/24)),'YYYY-MM-DD HH24:MI:SS') ";
                else
                    // 精确到日
                    temp = " TO_CHAR((TO_DATE('" + time1 + "','YYYY-MM-DD') "
                            + temp0 + " (TO_NUMBER('" + temp1
                            + "') + TO_NUMBER(0.75))/24 "
                            + " + (8/24)),'YYYY-MM-DD HH24:MI:SS')";
            } else {
                if ("S".equals(flag))// 精确到秒
                    temp = " TO_CHAR((TO_DATE('" + time1
                            + "','YYYY-MM-DD HH24:MI:SS') " + temp0
                            + " TO_NUMBER('" + temp1 + "')/24"
                            + " + (8/24)),'YYYY-MM-DD HH24:MI:SS')  ";
                else
                    // 精确到日
                    temp = " TO_CHAR((TO_DATE('" + time1 + "','YYYY-MM-DD') "
                            + temp0 + " TO_NUMBER('" + temp1 + "')/24 "
                            + " + (8/24)),'YYYY-MM-DD HH24:MI:SS') ";
            }
            System.out.println(temp);
            temp = Tools.getDBDate(temp);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

        return temp;
    }
   
    /**
     * ORA错误代码翻译,用于提示信息到JSP页面,不显示SQL异常
     */
    public static String getORASQLException(String ex) {
        String temp = "";
        if (!Tools.isEmpty(ex)) {
            if (ex.lastIndexOf("ORA-00001") > 0) {
                temp = "数据库表已存在相同的记录,请检查您的输入,谢谢!";
            } else if (ex.lastIndexOf("ORA-01401") > 0) {
                temp = "您输入的字段的长度超过数据库字段允许的最大长度限制,请检查您的输入,谢谢!";
            } else
                temp = ex;
        } else
            temp = ex;

        return temp;
    }

    /**
     *
     * @param value
     * @return
     */
    public static boolean isEmptyStr(String value) {

        if (value == null || value.trim().length() == 0)
            return true;

        return false;

    }

    /**
     *
     * @param value
     * @return
     */
    public static String toSqlString(String value) {
        return "'" + Tools.checkNull(value) + "'";

    }

    /**
     * @param queryStr
     * @param string
     * @param provValues
     */
    public static void appendSqlInCondition(StringBuffer queryStr,
            String fieldName, String[] fieldValues) {
        if (fieldValues != null && fieldValues.length > 0) {
            StringBuffer values = new StringBuffer("");
            for (int i = 0; i < fieldValues.length; i++) {
                if (isEmptyStr(fieldValues[i])) {
                    continue;
                }
                if (i != fieldValues.length - 1) {
                    values.append(toSqlString(fieldValues[i]) + ",");
                } else {
                    values.append(toSqlString(fieldValues[i]));
                }
            }
            if (!isEmptyStr(values.toString())) {
                queryStr.append(" AND " + fieldName + " IN (" + values + ")");
            }
        }
    }

    /**
     * @param queryStr
     * @param fieldValue
     * @param fieldValue2
     */
    public static void appendSqlStringCondition(StringBuffer queryStr,
            String fieldName, String fieldValue) {
        if (!isEmptyStr(fieldValue)) {
            queryStr
                    .append(" AND " + fieldName + "=" + toSqlString(fieldValue));
        }
    }

    /**
     *
     * @param obj
     * @param nullIfRet
     * @param ret
     * @return
     */
    public static String nvlStr(String obj, String nullIfRet, String ret) {

        return obj == null ? nullIfRet : ret;

    }

    /**
     * 去空格,主要用于从JSP页面获取输入项
     */
    public static String checkSpace(String value) {

        if (!Tools.isEmpty(value))
            return value.trim();
        else
            return value;

    }

    /**
     * @brief: 取参数表(sys_param)中参数值
     * @param paramType
     *            参数类型
     * @param code
     *            参数代码
     * @return 参数代码code对应的参数值;
     */
    public static String getPrintParam(String param, String report_id) {

        String value = null;
        ConversionBean getValueObject = new ConversionBean();
        getValueObject.setConnType(ICommonPolicy.pubdbaConn);
        getValueObject.setSql("select " + param
                + " from pubdba.report_print_param where report_id = '"
                + report_id + "'");
        value = getValueObject.getConversionBean();
        return value;
    }

    /**
     * 格式化double输出 d:需要格式化的数值 p: 格式化类型,例如#,##0.#####
     */
    public static String formatNumber(double d, String p) {
        String s = "";
        try {
            DecimalFormat f = (DecimalFormat) NumberFormat.getInstance();
            f.applyPattern(p);
            s = f.format(d);
            return s;
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

 

    // 得到前三天的时间
    public static String getBeforeTime(String str) {
        return DateFormatUtil.getBeforeTime(str);
    }
    // 得到前i天的时间
    public static String getBeforeTime(String str,int i) {
        return DateFormatUtil.getBeforeTime(str,i);
    }
    // 得到当天的时间YYYY-MM-DD
    public static String getCurrentData(String str) {
        return DateFormatUtil.getDataYYYYMMDD(str);
    }

    // 得到上个月:
    public static String getBeforeMonth(String pm_EndtTm) {
        return DateFormatUtil.getBeforeMonth(pm_EndtTm);
    }

    // 得到年度:
    public static String getCurrentYear(String operateTmBegin) {
        return DateFormatUtil.getFormatStartEndTmByYYYY(operateTmBegin);
    }
    /**
     * 返回当前年份上个月的第一天
     * @param month
     * @return
     */
    public static String getFirstDateOfLastMonth(String format) {
    int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR) ;
    int lastMonth = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH) ;
    DecimalFormat sf = new DecimalFormat();
    SimpleDateFormat sfDate = new SimpleDateFormat();
    SimpleDateFormat sfStr = new SimpleDateFormat();
    sfDate.applyPattern("yyyyMMdd");
    sfStr.applyPattern(Tools.isEmpty(format)?"yyyy-MM-dd":format);
        sf.applyPattern("00");
        java.util.Date dTmp = null;
try {
dTmp = sfDate.parse(year + "" + sf.format(lastMonth) + "01");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
       
        return sfStr.format(dTmp);
    }
    /**
     * 返回当前年份上个月的最后一天
     * @param format 设置返回日期的格式如:yyyy-MM-dd  yyyyMMdd  yyyy/MM/dd
     */
    public static String getLastDateOfLastMonth(String format) {

    int year = java.util.Calendar.getInstance().get(java.util.Calendar.YEAR) ;
    int lastMonth = java.util.Calendar.getInstance().get(java.util.Calendar.MONTH) ;
    DecimalFormat sf = new DecimalFormat();
        sf.applyPattern("00");
    return getLastDate(year+"",sf.format(lastMonth),Tools.isEmpty(format)?"yyyy-MM-dd":format);

    }
    /**
     * 根据年、月 取得 当月最后一天的完整日期
     *
     * @param year   2006
     * @param month  01
     * @return 20060131
     */
    public static String getLastDate(String year,String month,String fmt){
        if(year!=null && month!=null){
            if(year.length()!=4 && month.length()!=2){
                return null;
            }else{
                return getLastDate(year+month,fmt);
            }
        }
        return null;
    }
   
    /**
     * 根据年、月 取得 当月最后一天的完整日期
     * @param yearMonth    年月
     * @param fmt    日期格式.如:yyyy-MM-dd
     * @return    返回年月中的最后一天日期
     */
    public static String getLastDate(String yearMonth,String fmt){       
       
        String str = null;
        boolean isLeaf = false;
       
        /**
         * 计算时间
         */
        if (!Tools.isEmpty(yearMonth) && yearMonth.length() == 6) {
        //计算润年和大月
        int year = Integer.parseInt(yearMonth.substring(0, 4));
            int month = Integer.parseInt(yearMonth.substring(4, 6));
            int day = 30;
           
            if (((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0)) {
                isLeaf = true;
            }
            if (month == 1 || month == 3 || month == 5
                    || month == 7 || month == 8
                    || month == 10 || month == 12) {
                day = 31;
            } else if (month == 2) {
                if (isLeaf) {
                    day = 29;
                } else {
                    day = 28;
                }
            } else {
                day = 30;
            }
           
            //如果是1-9月份和1-9日的话则要前面加一个“0”
            DecimalFormat sf = new DecimalFormat();
            sf.applyPattern("00");
            String monthStr = sf.format(month);
            String dayStr = sf.format(day);
            String formatDate = year + monthStr + dayStr;        
           
            //应用日期格式
            fmt = Tools.isEmpty(fmt)?"yyyyMMdd":fmt;
            SimpleDateFormat formatStr = new SimpleDateFormat(fmt);
            try  {
            SimpleDateFormat sfTmp = new SimpleDateFormat("yyyyMMdd");
                Date date = sfTmp.parse(formatDate);
                str = formatStr.format(date);
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
        return str;
    }

   
  
   
    /**
     * 生成要设置多个<select>状态的javaScript代码
     * #注意:必须将common.js包含在<select>所有在JSP页面中
     * @param selectNames <select>控件名称
     * @param request
     * @param time 延时执行时间1000=1秒
     * @return
     */
    public static String generateJSOfSelectState(String[] selectNames,HttpServletRequest request,int time ) {
   
    if (selectNames != null && selectNames.length > 0) {
    String [][]selectValues = new String [selectNames.length][];
    for (int i = 0; i < selectNames.length; i++ ) {
    String[] _state = request.getParameterValues(selectNames[i]);
    if (_state != null && _state.length > 0)
    selectValues[i] = _state;
    }
    return generateJSOfSelectState(selectNames,selectValues,time);
    }
    return "";
    }
   
  
   
    /**
     * 批量压缩文件
     *
     * @param filePath   源文件的路径
     * @param fileName   源文件名列表
     * @param zipPath    压缩文件要保存的路径
     * @param zipFileName  保存的压缩文件名
     */
    public static void zipFile(String filePath, List fileName, String zipPath,
            String zipFileName) {
        try {
            FileOutputStream f = new FileOutputStream(zipPath+File.separator+zipFileName);
            CheckedOutputStream ch = new CheckedOutputStream(f, new CRC32());
            ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(ch));
           
            for (int i = 0; i < fileName.size(); i++) {
                //完整文件路径
                String fn=(String)fileName.get(i);

                String full=filePath+File.separator+fn;
               
                BufferedReader in = new BufferedReader(new InputStreamReader(
                        new FileInputStream(full), "ISO8859_1"));
                int c;               
                ZipEntry entry=new ZipEntry(DoTextBean.gb2iso(fn));
               
                out.putNextEntry(entry);
                while ((c = in.read()) != -1)
                    out.write(c);
                in.close();
                out.closeEntry();
            }
           
            out.close();
            System.out.println("文件压缩成功");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
   
    /**
     * 批量压缩文件
     *
     * @param fileName   源文件名列表
     * @param zipPath    压缩文件要保存的路径
     * @param zipFileName  保存的压缩文件名
     */
    public static void zipFile(List fileName, String zipPath,
            String zipFileName) {
        try {
            FileOutputStream f = new FileOutputStream(zipPath+File.separator+zipFileName);
            CheckedOutputStream ch = new CheckedOutputStream(f, new CRC32());
            ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(ch));
           
            for (int i = 0; i < fileName.size(); i++) {
                //完整文件路径
                String fn=(String)fileName.get(i);
                File file=new File(fn);
               
               
                BufferedReader in = new BufferedReader(new InputStreamReader(
                        new FileInputStream(fn), "ISO8859_1"));
                int c;               
                ZipEntry entry=new ZipEntry(DoTextBean.gb2iso(file.getName()));
               
                out.putNextEntry(entry);
                while ((c = in.read()) != -1)
                    out.write(c);
                in.close();
                out.closeEntry();
            }
           
            out.close();
            System.out.println("文件压缩成功");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
   
    public static String checkDownFile(HttpServletRequest request ) {
    String downFile = (String) request.getAttribute("_ZIP_FILE_NAME");
if (!Tools.isEmpty(downFile) ) {
try {
downFile = java.net.URLEncoder.encode(downFile,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "document.location.href='/zipDownload?_ZIP_FILE_NAME=" + downFile + "';";
}
return "";
    }
   
/**
*
* @param value
* @return boolean 为空返回 true, 不为空返回 false
*/

public static boolean isEmpty(String value) {
return (null == value || Constants.SPACE.equals(value) || Constants.ZERO == value
.trim().length()) ? true : false;
}

/**
*
* @param str
* @return boolean 为数字返回true,不为数字或者为空返回 false
*/

public static boolean isNumeric(String str) {
return CommonUtils.isEmpty(str) ? false : Pattern
.compile(Constants.VALIDATE_STRING_ISNUMBERIC).matcher(str)
.matches();
}

/**
*
* @param fileName
* @return 是文件返回true, 文件名不是文件或为空返回false
*/
public static boolean isFile(String fullFileNamePath) {
return CommonUtils.isEmpty(fullFileNamePath) ? false : new File(
fullFileNamePath).isFile();
}

/**
*
* @param filePath
*            文件路径
* @return 文件后缀
*/
public static String filePostfix(String filePath) {
return CommonUtils.isEmpty(filePath) ? Constants.SPACE : filePath
.substring(filePath.lastIndexOf(Constants.SPOT));
}
/**
* @see 判断 map里面的值是否为空,是否为文件真实名
* @param fileMap 文件路径,文件类型
* @return 参数是文件真实名返回true,否则返回false
*/
public static boolean isFile(Map<String, String> fileMap) {
boolean bool = false;
if (fileMap.isEmpty()) {
bool = false;
} else {
for (Iterator<Entry<String, String>> iterator = fileMap.entrySet().iterator(); iterator
.hasNext();) {
Map.Entry<String, String> mapInstance = (Map.Entry<String, String>) iterator
.next();

File file = new File(mapInstance.getKey());
if (file.isFile()) {
return true;
} else {
bool = false;
}
}
}
return bool;
}

}





分享到:
评论

相关推荐

    项目开发常用的JS方法

    里面包含6个JS函数,有获取设备类型、获取url参数、格式化时间戳、复制到粘贴板、去除首位空格、获取cookie。可供学习使用

    Unity开发中一些常用的方法和组件——DevilFramework.zip

    Unity开发中一些常用的方法和组件——DevilFramework

    JAVA常用类的使用方法

    常用方法有 `length()`、`charAt(int index)`、`substring(int beginIndex, int endIndex)`、`concat(String str)`、`indexOf(String str)`、`replace(char oldChar, char newChar)` 等,用于字符串操作。...

    JAVA 工具类 项目开发常用方法

    java 工具类 项目开发常用方法,如:字符转换函数,字符处理,数组相关的处理函数

    jsp网站开发常用方法

    jsp网站开发常用方法 IE6浏览器兼容开发方法 关于jsp下载/上传出现的问题

    Java编程常用方法

    下面是使用 ArrayList 类的一些常用方法: 1. get(int index):获取指定索引处的元素,该方法返回指定索引处的元素,如果索引越界将抛出 IndexOutOfBoundsException。 例如:ArrayList&lt;String&gt; list = new ...

    开发中的一些常用jar包下载

    这里提到的"开发中的一些常用jar包下载"涵盖了几个非常关键的Java库,它们在各种项目中都有广泛的应用。下面我们将分别详细介绍这些库的作用、功能以及如何在项目中使用它们。 1. **MySQL Connector**: MySQL ...

    java常用开发词汇

    9. Java开发词汇的学习方法:学习Java开发词汇需要一定的学习方法,例如通过实践、阅读书籍、观看视频等。 10. Java开发词汇的实际应用:Java开发词汇广泛应用于实际的软件开发项目中,例如开发一个android应用程序...

    金蝶云星空二次开发常用调用方法.docx

    金蝶云星空二次开发常用调用方法

    管理软件开发常用方法

    本文是我们将日常开发管理系统中常用的方式方法进行整理,目的是为方便开发者查阅、使用,尤其是刚刚进入软件开发行业的新人。里面收录了关于SQL、JS、VB等常用方法。

    asp.net 开发常用代码

    asp.net 开发常用代码,常用方法,常用技术!

    js常用技术,包括一些常用方法

    本资源包“JavaScript常用技术”包含了图片处理特效、文字特效以及一系列常用的JavaScript方法,是开发者学习和实践JavaScript技术的宝贵资料。 一、图片处理特效 在Web开发中,图片处理是不可或缺的一部分。...

    游戏开发常用算法

    ### 游戏开发常用算法详解 #### 一、算法与数据结构基础 在游戏开发过程中,算法和数据结构是至关重要的。算法是指解决问题的一系列步骤,而数据结构则是组织和管理数据的方式。良好的算法和数据结构能够提高游戏...

    GUI界面开发常用方法

    NULL 博文链接:https://beck5859509.iteye.com/blog/1482242

    一些java常用的工具类

    Java是一种广泛使用的编程语言,其灵活性和强大的功能使其在各种应用程序开发中占据核心地位。在Java编程中,工具类(Utility Classes)是非常重要的组成部分,它们提供了许多通用的功能,以简化开发人员的工作。...

    软件开发常用方法 SQL、js

    本文是我们将日常开发管理系统中常用的方式方法进行整理,目的是为方便开发者查阅、使用,尤其是刚刚进入软件开发行业的新人。里面收录了关于SQL、JS、VB等常用方法。

    js开发中常用的工具类

    js开发中常用的工具类

    android开发常用工具类

    "Android开发常用工具类"通常包含各种实用方法,如图片加载、异常处理、数据存储与读取以及对话框的定制等。下面将对这些知识点进行详细说明。 1. **图片加载(ImageLoader)**: 在Android应用中,图片加载是常见...

    工作11年总结的常用java工具类,上百种方法,开发中绝对用得到

    下面将详细阐述一些重要的Java工具类及其常用方法。 1. **Apache Commons Lang**: Apache Commons Lang 是一个非常实用的工具库,提供了大量Java语言没有内置的功能。例如,`StringUtils` 类包含了大量的字符串操作...

    java常用方法大全

    一份很全面关于java的常用方法总结,开发时,我们记不了那么多方法,所以这个htm文档很适合大家在开中应用 字符串 1、获取字符串的长度 length() 2 、判断字符串的前缀或后缀与已知字符串是否相同 前缀 startsWith...

Global site tag (gtag.js) - Google Analytics