01: package org.claros.intouch.common.utility;
02:
03: import java.sql.Connection;
04:
05: import org.apache.commons.dbcp.BasicDataSource;
06: import org.claros.commons.db.DbConfigList;
07:
08: import com.jenkov.mrpersister.itf.IGenericDao;
09:
10: /**
11: * @author Umut Gokbayrak
12: */
13: public class Utility {
14:
15: public static IGenericDao getDbConnection() throws Exception {
16: return getDbConnection("file");
17: }
18:
19: public static IGenericDao getTxnDbConnection() throws Exception {
20: return getDbConnection("file");
21: }
22:
23: public static IGenericDao getDbConnection(String name)
24: throws Exception {
25: BasicDataSource bs = (BasicDataSource) DbConfigList
26: .getDataSourceById(name);
27:
28: Connection con = bs.getConnection();
29: return Constants.persistMan.getGenericDaoFactory().createDao(
30: con);
31: }
32:
33: public static IGenericDao getTxnDbConnection(String name)
34: throws Exception {
35: Connection con = DbConfigList.getDataSourceById(name)
36: .getConnection();
37: con.setAutoCommit(false);
38: return Constants.persistMan.getGenericDaoFactory().createDao(
39: con);
40: }
41:
42: /**
43: *
44: * @param str
45: * @return
46: */
47: public static String htmlCheck(String str) {
48: if (str == null) {
49: return "";
50: }
51: str = org.claros.commons.utility.Utility.replaceAllOccurances(
52: str, "<", "<");
53: str = org.claros.commons.utility.Utility.replaceAllOccurances(
54: str, ">", ">");
55: str = org.claros.commons.utility.Utility.replaceAllOccurances(
56: str, "\"", """);
57: return str;
58: }
59:
60: public static String tooltipCheck(String str) {
61: str = htmlCheck(str);
62: str = org.claros.commons.utility.Utility.replaceAllOccurances(
63: str, "[", "(");
64: str = org.claros.commons.utility.Utility.replaceAllOccurances(
65: str, "]", ")");
66: str = org.claros.commons.utility.Utility.replaceAllOccurances(
67: str, "\"", "");
68: str = org.claros.commons.utility.Utility.replaceAllOccurances(
69: str, "'", "");
70: return str;
71: }
72:
73: }
|