HelpManager.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @(#)file HelpManager.java
  3. * @(#)author cho sung geun
  4. * @(#)version 1.0
  5. * @(#)date Jul 10, 2009
  6. * @(#)since JDK 1.4.2
  7. *
  8. * Copyright (c) www.hwenc.co.kr, Inc.
  9. * All rights reserved.
  10. * This software is the proprietary information of Hanwha E&C, Inc.
  11. */
  12. package kr.co.udapsoft.common.util;
  13. import java.io.BufferedReader;
  14. import java.io.InputStream;
  15. import java.io.InputStreamReader;
  16. import java.net.URL;
  17. import java.net.URLConnection;
  18. import javax.servlet.http.HttpServletRequest;
  19. import kr.co.hsnc.common.base.WAFLogger;
  20. import kr.co.hsnc.common.config.WAFConfig;
  21. import kr.co.hsnc.common.util.ValueObject;
  22. import kr.co.hsnc.j2ee.waf.controller.web.util.WebKeys;
  23. public class HelpManager {
  24. private HttpServletRequest request = null;
  25. private String EMP_NO = "";
  26. public HelpManager(HttpServletRequest request) {
  27. this.request = request;
  28. ValueObject user = (ValueObject)request.getSession().getAttribute(WebKeys.SIGNED_ON_USER);
  29. if( user != null ) {
  30. EMP_NO = user.get("USER_ID");
  31. }
  32. }
  33. /**
  34. * URLConnection 으로 Template 을 실행한 후 결과를 HTML 로 생성한다.
  35. * 각 메뉴화면에서 연결할 경우 사용한다.
  36. * @param currentURI -- 선택하 메뉴의 currentURI
  37. * @param useSystem -- VOC , PCMS 등 카테고리
  38. * @return String
  39. * @throws Exception
  40. */
  41. public String createHtmlFile(String currentURI, String useSystem) {
  42. URL url = null;
  43. URLConnection urlConn = null;
  44. InputStream input = null;
  45. BufferedReader reader = null;
  46. StringBuffer html = null;
  47. String rtnStr = "";
  48. try {
  49. html = new StringBuffer();
  50. String protocol = ""; //"http";
  51. String host = ""; //"127.0.0.1";
  52. int port = 20000; //8888;
  53. //2008.8.15 L4 IP Drop(소스 ip와 목적지 ip가 같은경우) 해결위해 URL변경.
  54. if(WAFConfig.get("waf.was.ip").equals("")||WAFConfig.get("waf.was.port").equals("")){
  55. protocol = request.getScheme();
  56. host = request.getServerName();
  57. }else{
  58. protocol = request.getScheme();
  59. host = WAFConfig.get("waf.was.ip");
  60. }
  61. String urlStr = protocol+"://"+host+":"+port+"/returnIcon.screen?emp_no="+EMP_NO+"&category="+useSystem+"&menu_name="+currentURI;
  62. url = new URL(urlStr);
  63. urlConn = url.openConnection();
  64. if (urlConn!=null) {
  65. String line = null;
  66. input = urlConn.getInputStream();
  67. reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
  68. while((line = reader.readLine()) != null){
  69. html.append(line);
  70. }
  71. rtnStr = html.toString();
  72. rtnStr = rtnStr.replaceAll("\r", "");
  73. rtnStr = rtnStr.replaceAll("\n", "");
  74. }
  75. } catch(Exception e) {
  76. WAFLogger.error("헬프 아이콘을 받아오는 중 에러가 발생 하였습니다.\n");
  77. } finally {
  78. try {
  79. if (reader != null) reader.close();
  80. } catch (Exception ex_close) {}
  81. }//end of try
  82. return rtnStr;
  83. }//end of method
  84. /**
  85. * 상단 메인 화면에서 연결할 경우 사용한다.
  86. * 각 시스템에 help.js를 제공해 callHelp()를 구현하도록 한다.
  87. * @return String
  88. * @throws Exception
  89. */
  90. public String getTopHelpIcon( String useSystem , String fontColor ) {
  91. String rtnStr = "";
  92. //rtnStr = "<A href=\"javascript:callHelp('"+EMP_NO+"','"+useSystem+"');\" title=\"도움말 보기\"><img src='/img/main/help.gif'> </A>";
  93. rtnStr = "<img src=\"/img/main/help.gif\" alt=\"도움말 보기\" onclick=\"callHelp('"+EMP_NO+"','"+useSystem+"');\" style='cursor:hand'>";
  94. return rtnStr;
  95. }//end of method
  96. }