论坛首页 Java企业应用论坛

留言内容转换通用Bean

浏览 1906 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-06-15   最后修改:2010-03-22

 

package com.web; 

import java.text.*; 
import java.util.Date; 
import java.io.*; 

public class commonBean 
{ 

    public commonBean() 
    { 
    } 

    public static String FilterSingleQuotes(String s) 
    { 
    s = Replace(s, "'", "''"); 
    return s; 
    } 
//替换成html标记 
    public static String ReplaceHtml(String s) 
    { 
        s = Replace(s, "&", "&"); 
        s = Replace(s, "", ">"); 
        s = Replace(s, "\t", "    "); 
        s = Replace(s, "\r\n", "\n"); 
        s = Replace(s, "\n", ""); 
        s = Replace(s, "  ", "  "); 
        s = Replace(s, "'", "'"); 
        s = Replace(s, "\\", "\"); 
        return s; 
    } 
//去除html标记 
    public static String RecoverHtml(String s) 
    { 
        s = Replace(s, "", "\n"); 
        s = Replace(s, "<", ""); 
        s = Replace(s, " ", " "); 
        return s; 
    } 
    
//显示中文 
    public static String ShowCH(String s) 
    { 
    if (s==null) 
        return null; 
        String s1=""; 
        try 
        { 
        s1=new String(s.getBytes("ISO-8859-1"),"utf-8"); 
        } 
        catch (Exception e) 
        { 
            e.printStackTrace(); 
            return s; 
        } 
        return s1; 

    } 
//用于替换的函数 
    public static String Replace(String s, String s1, String s2) 
    { 
        if(s == null) 
        { 
            return null; 
        } 
        StringBuffer stringbuffer = new StringBuffer(); 
        int i = s.length(); 
        int j = s1.length(); 
        int k; 
        int l; 
        for(k = 0; (l = s.indexOf(s1, k)) >= 0; k = l + j) 
        { 
            stringbuffer.append(s.substring(k, l)); 
            stringbuffer.append(s2); 
        } 

        if(k  bt) 
 { 
 //bt = bt - 2; 
 str = str.substring(0, bt)+"……"; 
 }else{ 
 str = str; 
 } 
 return str; 
 } 

 //删除文件 
 public static String deleteFile(String path){ 
 String str; 
 File file = new File(path); 
 if (file.exists()) 
 { 
 try 
 { 
 file.delete(); 
 str = "文件“"+path+"”删除成功!"; 
 } 
 catch (Exception e) 
 { 
 str = e.toString(); 
 } 
 }else{ 
 str = "文件“"+path+"”不存在!"; 
 } 
 return str; 
 } 
 //判断文件大小,然后生成合理的大小值 
 public static String fileSizeFormat(int i){ 
 String str; 
 if (i = 1048576) 
 { 
 double j = (double)i/1048576; 
 str = new DecimalFormat(".00").format(j);//保留两位小数 
 str = str + " MB"; 
 }else{ 
 str = "文件大小错误!"; 
 } 
 return str; 
 } 
 //判断是否为管理员 
 public static String adminFormat(String str){ 
 if (str.equals("super")) 
 { 
 str = "1"; 
 }else if (str.equals("common")) 
 { 
 str = "2"; 
 }else if (str.equals("1")) 
 { 
 str = "super"; 
 }else if (str.equals("2")) 
 { 
 str = "common"; 
 }else{ 
 str = null; 
 } 
 return str; 
 } 
 //判断是否超出字符限制 
 public static String byteForm(String str, int i){ 
 if (str == null) 
 { 
 return "没有说明!"; 
 } 
 if (i >= str.length()) 
 { 
   return str; 
 }else{ 
   return null; 
 } 
 } 
}

 

 

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics