1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package gnu.hylafax.util;
31
32
33 import gnu.hylafax.job.ReceiveEvent;
34 import gnu.hylafax.job.ReceiveListener;
35 import gnu.hylafax.job.SendEvent;
36 import gnu.hylafax.job.SendListener;
37
38 import java.sql.Connection;
39 import java.sql.DriverManager;
40 import java.sql.PreparedStatement;
41
42 import org.apache.commons.logging.Log;
43 import org.apache.commons.logging.LogFactory;
44
45 /***
46 * This class implements an example fax job listener.
47 *
48 * @author $Author: sjardine $
49 * @version $Id: SampleListener.java,v 1.4 2007/02/21 00:07:49 sjardine Exp $
50 * @see gnu.hylafax.job.SendNotifier
51 * @see gnu.hylafax.job.SendEvent
52 * @see gnu.hylafax.job.ReceiveNotifier
53 * @see gnu.hylafax.job.ReceiveEvent
54 * @see gnu.hylafax.util.Notifier
55 */
56 public class SampleListener implements SendListener, ReceiveListener {
57
58 private final static Log log = LogFactory.getLog(SampleListener.class);
59
60 public final static String KEY_DBUSER = "notifier.db.user";
61
62 public final static String KEY_DBPASSWORD = "notifier.db.password";
63
64 public final static String KEY_DBDRIVER = "notifier.db.driver";
65
66 public final static String KEY_DBURI = "notifier.db.uri";
67
68 String DB_USER = System.getProperties().getProperty(KEY_DBUSER);
69
70 String DB_PASSWORD = System.getProperties().getProperty(KEY_DBPASSWORD);
71
72 String DB_URI = System.getProperties().getProperty(KEY_DBURI);
73
74 String DB_CLASS = System.getProperties().getProperty(KEY_DBDRIVER);
75
76 /***
77 *
78 *
79 */
80 public void onSendEvent(SendEvent event) {
81 try {
82
83 Class.forName(DB_CLASS);
84 Connection connection = DriverManager.getConnection(DB_URI,
85 DB_USER, DB_PASSWORD);
86 String sql = "insert into send (reason,filename,jobid,jobtime,next) values (?,?,?,?,?)";
87 PreparedStatement stmt = connection.prepareStatement(sql);
88 stmt.setString(1, event.getReason());
89 stmt.setString(2, event.getFilename());
90 stmt.setLong(3, event.getJobId());
91 stmt.setLong(4, event.getElapsedTime());
92 stmt.setString(5, event.getNextAttempt());
93 stmt.execute();
94 stmt.close();
95 connection.close();
96
97 } catch (Exception e) {
98 log.error(e.getMessage(), e);
99 }
100 }
101
102 /***
103 * This method is called when a fax-received event occurs.
104 */
105 public void onReceiveEvent(ReceiveEvent event) {
106 try {
107
108 Class.forName(DB_CLASS);
109 Connection connection = DriverManager.getConnection(DB_URI,
110 DB_USER, DB_PASSWORD);
111 String sql = "insert into receive (filename,modem,commid,message,cidnumber,cidname) values (?,?,?,?,?,?)";
112 PreparedStatement stmt = connection.prepareStatement(sql);
113 stmt.setString(1, event.getFilename());
114 stmt.setString(2, event.getModem());
115 stmt.setString(3, event.getCommunicationIdentifier());
116 stmt.setString(4, event.getMessage());
117 stmt.setString(5, event.getCidNumber());
118 stmt.setString(6, event.getCidName());
119 stmt.execute();
120 stmt.close();
121 connection.close();
122
123 } catch (Exception e) {
124 log.error(e.getMessage(), e);
125 }
126 }
127
128 }
129