281b177ea3803645feee3acd42b35297b0cde8d7.svn-base 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package xin.glue.ui.common.component;
  2. import java.util.List;
  3. import javax.servlet.http.Cookie;
  4. import javax.servlet.http.HttpServletRequest;
  5. import com.posdata.glue.context.PosContext;
  6. import com.posdata.glue.dao.PosGenericDao;
  7. import com.posdata.glue.dao.manager.PosQueryDefinition;
  8. import com.posdata.glue.dao.manager.PosQueryManagerImpl;
  9. import com.posdata.glue.dao.vo.PosParameter;
  10. public class PosSiteLog {
  11. public static boolean writeLog(PosContext ctx, PosGenericDao dao, String queryId, List params) {
  12. if (!PosSiteConfig.isWriteLog())
  13. return true;
  14. try {
  15. PosParameter param = new PosParameter();
  16. PosQueryManagerImpl queryManager = (PosQueryManagerImpl)PosContext.getBeanFactory().getBeanObject("queryManager");
  17. PosQueryDefinition query = queryManager.getQueryDefinition(queryId);
  18. if (query == null) {
  19. param.setValueParamter(0, "程序内嵌语句");
  20. param.setValueParamter(1, queryId);
  21. } else {
  22. param.setValueParamter(0, queryId);
  23. param.setValueParamter(1, query.getQueryStatement().replaceAll("&", "&"));
  24. }
  25. String paramValue = "";
  26. int count = params.size();
  27. for (int i=0; i<count; i++)
  28. paramValue += "parameter " + i + ": " + params.get(i) + "\n";
  29. param.setValueParamter(2, paramValue);
  30. HttpServletRequest request = (HttpServletRequest)ctx.findRequestAttr("HttpServletRequest");
  31. Cookie[] cookies = request.getCookies();
  32. param.setValueParamter(3, cookies[2].getValue());
  33. param.setValueParamter(4, cookies[1].getValue());
  34. String[] address = cookies[0].getValue().split("\\|");
  35. param.setValueParamter(5, "外网IP:\n" + address[0] + "\n\n内网IP:\n" + address[1].replace(',', '\n'));
  36. dao.insert("site.log.insert", param);
  37. } catch (Exception e) {
  38. e.printStackTrace();
  39. return false;
  40. }
  41. return true;
  42. }
  43. }