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

📄 waputil.java

📁 WAP PUSH后台源码,WAP PUSH后台源码
💻 JAVA
字号:
package com.sxit.wap.common;import java.sql.*;import java.util.*;import com.sxit.wap.exception.*;public class WapUtil { public static String word(String word) {    if (Database.dbType == DBType.ORACLE) {      try {      return word;      } catch (Exception e) {        return word;      }    } else {      try {        return word;//new String(word.getBytes("GB2312"),"ISO-8859-1");      } catch (Exception e) {        return word;      }    }  } public static String uword(String word) {   if (Database.dbType == DBType.ORACLE) {     try {     Decode dc = new Decode();     word = dc.strToUtf8(new String(word.getBytes("ISO-8859-1"),"GB2312"));     return word;     } catch (Exception e) {       return word;     }   } else {     try {       return word;//new String(word.getBytes("GB2312"),"ISO-8859-1");     } catch (Exception e) {       return word;     }   } }  public static String data(String data) {    if (Database.dbType == DBType.ORACLE) {      try {        return new String(data.getBytes("GB2312"),"ISO-8859-1");      } catch (Exception e) {        return data;      }    } else {      try {        return data;//new String(data.getBytes("GB2312"),"ISO-8859-1");      } catch (Exception e) {        return data;      }    }  } public static String udata(String data) {    if (Database.dbType == DBType.ORACLE) {      try {        Decode dc = new Decode();        data = dc.strToUtf8(data);        return data;      } catch (Exception e) {        return data;      }    } else {      try {        return data;//new String(data.getBytes("GB2312"),"ISO-8859-1");      } catch (Exception e) {        return data;      }    }  }  public static String parseString(String value, String errorMessage) throws AppException {    if (value == null) value = "";    return encode(value);  }  public static String parseString(String value) throws Exception {    return parseString(value, "");  }  public static int parseInt(String value, String errorMessage) throws AppException {    int result = 0;    try {      result = Integer.parseInt(value);      return result;    }catch(Exception e) {      System.out.println("Integer.parseInt(" + value + ")" + " :\n" + e);      throw new AppException(errorMessage);    }  }  public static int parseInt(String value) throws Exception {    return Integer.parseInt(value);  }  public static short parseShort(String value, String errorMessage) throws AppException {    short result = 0;    try {      result = Short.parseShort(value);      return result;    }catch(Exception e) {      System.out.println("Short.parseShort(" + value + ")" + " :\n" + e);      throw new AppException(errorMessage);    }  }  public static short parseShort(String value) throws Exception {    return Short.parseShort(value);  }  public static float parseFloat(String value, String errorMessage) throws AppException {    float result = 0;    try {      result = Float.parseFloat(value);      return result;    }catch(Exception e) {      System.out.println("Float.parseFloat(" + value + ")" + " :\n" + e);      throw new AppException(errorMessage);    }  }  public static float parseFloat(String value) throws Exception {    return Float.parseFloat(value);  }  public static long parseLong(String value, String errorMessage) throws AppException {    long result = 0;    try {      result = Long.parseLong(value);      return result;    }catch(Exception e) {      System.out.println("Long.parseLong(" + value + ")" + " :\n" + e);      throw new AppException(errorMessage);    }  }  public static long parseLong(String value) throws Exception {    return Long.parseLong(value);  }  public static Timestamp parseTimestamp(String value, String errorMessage) throws AppException {    if (StringUtil.isEmpty(value)) {      if (StringUtil.isNotEmpty(errorMessage)) {        throw new AppException(errorMessage);      } else {        throw new AppException("parseTimestamp error");      }    }    StringTokenizer st = new StringTokenizer(value, "-/");    String year = "", month = "", day = "";    int yyyy = 0, mm = 0, dd = 0;    if ( st.hasMoreTokens() ) {      year = st.nextToken();    }    if (!(year.length() == 4 || year.length() == 2)) throw new AppException(errorMessage);    try {yyyy=Integer.parseInt(year);}catch(Exception e){throw new AppException(errorMessage);}    if ( st.hasMoreTokens() ) {      month = st.nextToken();    }    if (!(month.length() == 2 || month.length() == 1)) throw new AppException(errorMessage);    try {mm=Integer.parseInt(month);}catch(Exception e){throw new AppException(errorMessage);}    if ( st.hasMoreTokens() ) {      day = st.nextToken();    }    if (!(day.length() == 2 || day.length() == 1)) throw new AppException(errorMessage);    try {dd=Integer.parseInt(day);}catch(Exception e){throw new AppException(errorMessage);}    return DateUtil.getTimestamp(yyyy, mm, dd);  }  public static Timestamp parseTimestamp(String value) throws AppException {    return parseTimestamp(value, "");  }  public static String[] parseStringArray(String[] value, String errorMessage) throws AppException {    if (value == null) return new String[0];    String result[] = new String[value.length];    try {      for (int i = 0; i < value.length; i++) {        result[i] = (value[i] == null ? "" : encode(value[i]));      }      return result;    }catch(Exception e) {      throw new AppException(errorMessage);    }  }  public static String[] parseStringArray(String[] value) throws Exception {    String result[] = new String[value.length];    for (int i = 0; i < value.length; i++) {      result[i] = (value[i] == null ? "" : encode(value[i]));    }    return result;  }  public static int[] parseIntArray(String[] value, String errorMessage) throws AppException {    if (value == null) return new int[0];    int result[] = new int[value.length];    try {      for (int i = 0; i < value.length; i++) {        result[i] = Integer.parseInt(value[i]);      }      return result;    }catch(Exception e) {      System.out.println("Integer.parseInt(" + value + ")" + " :\n" + e);      throw new AppException(errorMessage);    }  }  public static long[] parseLongArray(String[] value, String errorMessage) throws AppException {    if (value == null) return new long[0];    long result[] = new long[value.length];    try {      for (int i = 0; i < value.length; i++) {        result[i] = Long.parseLong(value[i]);      }      return result;    }catch(Exception e) {      System.out.println("Long.parseLong(" + value + ")" + " :\n" + e);      throw new AppException(errorMessage);    }  }  public static int[] parseIntArray(String[] value) throws Exception {    int result[] = new int[value.length];    for (int i = 0; i < value.length; i++) {      result[i] = Integer.parseInt(value[i]);    }    return result;  }  public static int parseIntOfSubString(String value, int pos, String errorMessage) throws AppException {    StringTokenizer st = new StringTokenizer(value, ";");    int i = 0;    while (st.hasMoreTokens()) {      i++;st.nextToken();    }    String[] arr = new String[i];    i = 0;    st = new StringTokenizer(value, ";");    while (st.hasMoreTokens()) {      arr[i++] = st.nextToken();    }    if (pos < arr.length) {      return parseInt(arr[pos], errorMessage);    } else {      throw new AppException(errorMessage);    }  }  public static int parseIntOfSubString(String value, int pos) throws AppException {    return parseIntOfSubString(value, pos, "");  }  public static int[] parseIntArrayOfSubString(String value[], int pos, String errorMessage) throws AppException {    if (value == null) return new int[0];    int[] returnValue = new int[value.length];    for (int i=0; i<value.length; i++) {      returnValue[i] = parseIntOfSubString(value[i], pos, errorMessage);    }    return returnValue;  }  public static int[] parseIntArrayOfSubString(String value[], int pos) throws AppException {    return parseIntArrayOfSubString(value, pos, "");  }  public static String parseStringField(String value, String cFieldName, boolean enableNull, int length) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return "";      else throw new AppException(cFieldName + "不能为空");    }    String t = parseString(value, cFieldName + "错误");    //if (value.getBytes().length == 0 && !enableNull) throw new AppException(cFieldName + "不能为空");    if (value.getBytes().length > length) throw new AppException(cFieldName + "长度不能超过" + length + "位");    return t;  }  public static String parseStringField(String value, String cFieldName, boolean enableNull) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return "";      else throw new AppException(cFieldName + "不能为空");    }    String t = parseString(value, cFieldName + "错误");    //if (value.getBytes().length == 0 && !enableNull) throw new AppException(cFieldName + "不能为空");    return t;  }  public static int parseIntField(String value, String cFieldName, boolean enableNull, int low, int high) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return 0;      else throw new AppException(cFieldName + "不能为空");    }    int t = parseInt(value, cFieldName + "只能为大于" + low + "小于" + high + "的整数");    if (t == 0 && !enableNull) throw new AppException(cFieldName + "不能为空或0");    if (t < low || t > high) throw new AppException(cFieldName + "只能为大于" + low + "小于" + high + "的整数");    return t;  }  public static int parseIntField(String value, String cFieldName, boolean enableNull) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return 0;      else throw new AppException(cFieldName + "不能为空");    }    int t = parseInt(value, cFieldName + "只能为大于0小于65535的整数");    if (t == 0 && !enableNull) throw new AppException(cFieldName + "不能为空或0");    return t;  }  public static long parseLongField(String value, String cFieldName, boolean enableNull, long low, long high) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return 0L;      else throw new AppException(cFieldName + "不能为空");    }    long t = parseLong(value, cFieldName + "只能为大于" + low + "小于" + high + "的整数");    if (t == 0 && !enableNull) throw new AppException(cFieldName + "不能为空或0");    if (t < low || t > high) throw new AppException(cFieldName + "只能为大于" + low + "小于" + high + "的整数");    return t;  }  public static long parseLongField(String value, String cFieldName, boolean enableNull) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return 0L;      else throw new AppException(cFieldName + "不能为空");    }    long t = parseLong(value, cFieldName + "只能为大于0小于4294967295的整数");    if (t == 0 && !enableNull) throw new AppException(cFieldName + "不能为空或0");    return t;  }  public static float parseFloatField(String value, String cFieldName, boolean enableNull, float low, float high) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return 0F;      else throw new AppException(cFieldName + "不能为空");    }    float t = parseFloat(value, cFieldName + "只能为大于" + low + "小于" + high + "的数据");    if (t == 0 && !enableNull) throw new AppException(cFieldName + "不能为空或0");    if (t < low || t > high) throw new AppException(cFieldName + "只能为大于" + low + "小于" + high + "的数据");    return t;  }  public static float parseFloatField(String value, String cFieldName, boolean enableNull) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return 0F;      else throw new AppException(cFieldName + "不能为空");    }    float t = parseFloat(value, cFieldName + "数值输入错误");    if (t == 0 && !enableNull) throw new AppException(cFieldName + "不能为空或0");    return t;  }  public static Timestamp parseDateField(String value, String cFieldName, boolean enableNull) throws AppException {    if (StringUtil.isEmpty(value)) {      if (enableNull) return null;      else throw new AppException(cFieldName + "不能为空");    }    Timestamp t = parseTimestamp(value, cFieldName + "输入错误");    return t;  }  public static String encode(String value) {return value;    /*try {      return new String(value.getBytes("gb2312"));//iso-8859-1    } catch (Exception e) {      return "";    }*/  }}

⌨️ 快捷键说明

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