package zr.zrpower.web.bean;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import zr.zrpower.common.util.SysPreperty;



public class MessageBox extends HttpServlet {

   protected PrintWriter out = null;
   protected boolean isOk = false;
   protected String Msg = "非法调用，操作不被接受，你的操作已被记录！";
   protected String returnPath = "javascript:history.go(-1)";


    //显示消息对话框
    //传入参数：out          输出源
    //         isOk         成功消息还是失败消息
    //         Msg          消息内容
    //         returnPath   返回路径
    public  void GetBox() throws FileNotFoundException,IOException{

      BufferedReader br = null;

      String strPath = SysPreperty.getProperty().AppUrl + "images/windowimg";
      String imgPath = SysPreperty.getProperty().AppUrl + "images/windowimg/Msg_Error.gif";
      String soundPath = SysPreperty.getProperty().AppUrl + "images/error.wav";

      if (isOk){
        imgPath = SysPreperty.getProperty().AppUrl + "images/windowimg/Msg_OK.gif";
        soundPath = SysPreperty.getProperty().AppUrl + "images/succeed.wav";
      }
      String strServerPath = getServletContext().getRealPath("/");
      if (strServerPath==null)
      {
          strServerPath = SysPreperty.getProperty().WebPath;
      }
      br = new BufferedReader(new InputStreamReader(new FileInputStream(
          strServerPath + "/messagebox.htm")));
      String data = null;
      while ( (data = br.readLine()) != null) {
        data = data.replaceAll("BPIP_PATH",strPath);
        data = data.replaceAll("BPIP_MESSAGE", Msg);
        data = data.replaceAll("BPIP_IMG", imgPath);
        data = data.replaceAll("BPIP_SOUND",soundPath);
        data = data.replaceAll("BPIP_RETURN", returnPath);
        out.println(data);
      }
    }


}
