1
2
3
4
5 package comum.util;
6
7 import java.io.FileInputStream;
8 import java.io.FileNotFoundException;
9 import java.io.IOException;
10 import java.util.Properties;
11
12 import javax.servlet.ServletContext;
13 import javax.servlet.jsp.PageContext;
14
15 import org.apache.log4j.Logger;
16
17
18
19
20 public class Mensagem {
21
22 private static Properties p = null;
23 private ServletContext context;
24
25 private Logger logger = null;
26
27
28
29
30
31
32
33
34
35 public Mensagem(ServletContext application){
36 this.logger = Logger.getLogger(this.getClass());
37
38 context = application;
39 try {
40 if(p == null) {
41 p = new Properties();
42 p.load(new FileInputStream(application.getRealPath("/WEB-INF/classes/properties/ecar.properties")));
43 }
44 } catch (FileNotFoundException e) {
45 logger.error(e);
46 } catch (IOException e) {
47 logger.error(e);
48 }
49 }
50
51
52
53
54
55
56
57
58
59
60 public String getMensagem(String key){
61
62 if(p != null && p.containsKey(key))
63 return p.get(key).toString();
64 else
65 return "Mensagem não econtrada";
66
67 }
68
69
70
71
72
73
74
75
76
77
78
79 public static void alert(PageContext page, String msg) throws Exception {
80 try {
81 page.getOut().println("<script language=\"javascript\">");
82 page.getOut().println("alert(\"" + msg + "\");");
83 page.getOut().println("</script>");
84 } catch(IOException e) {
85 throw new Exception(e);
86 }
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100 public static void setInput(PageContext page, String input, String value) throws Exception {
101 try {
102 page.getOut().println("<script language=\"javascript\">");
103 page.getOut().println(input + " = \"" + value + "\"");
104 page.getOut().println("</script>");
105 } catch(IOException e) {
106 throw new Exception(e);
107 }
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121 public String getPathUploadRaiz(String key) {
122
123 if(p.containsKey(key))
124 return p.get(key).toString();
125 else
126 return context.getRealPath("");
127 }
128
129
130
131
132
133
134
135
136
137
138
139 public int getQtdeItensPaginaPesquisa(String key) {
140 if(p.containsKey(key))
141 return Integer.parseInt(p.get(key).toString());
142 else
143 return 10;
144 }
145
146 }