View Javadoc

1   // FaxStat.java - gnu.hylafax implementation of the faxstat utility
2   // $Id: FaxStat.java,v 1.5 2007/05/07 18:26:53 sjardine Exp $
3   //
4   // - basically gives an example for getting the status a FAX job
5   //
6   // Copyright 2001, Joe Phillips <jaiger@net-foundry.com>
7   //
8   // This library is free software; you can redistribute it and/or
9   // modify it under the terms of the GNU Library General Public
10  // License as published by the Free Software Foundation; either
11  // version 2 of the License, or (at your option) any later version.
12  //
13  // This library is distributed in the hope that it will be useful,
14  // but WITHOUT ANY WARRANTY; without even the implied warranty of
15  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  // Library General Public License for more details.
17  //
18  // You should have received a copy of the GNU Library General Public
19  // License along with this library; if not, write to the Free
20  // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  //
22  //
23  // for information on the HylaFAX FAX server see
24  //  http://www.hylafax.org/
25  //
26  // TODO make this class more flexible
27  //  
28  
29  package gnu.hylafax.util;
30  
31  
32  import gnu.hylafax.HylaFAXClient;
33  import gnu.hylafax.HylaFAXClientProtocol;
34  import gnu.hylafax.Job;
35  
36  import java.util.Enumeration;
37  import java.util.StringTokenizer;
38  import java.util.Vector;
39  
40  /***
41   * This class implements most of the faxstat program as supplied with the
42   * HylaFAX distribution. The following command line options are supported.
43   * <P>
44   * 
45   * <PRE>
46   * 
47   * -a get status of archive/ (IGNORED) -d get status of doneq/ -f get status of
48   * docq/ -g display GMT timestamps -h<host>specifiy server hostname -l display
49   * local timestamps -i get additional status info -r get status of receive queue
50   * -s get status of send queue -u user to login to the server with -v verbose
51   * mode
52   * 
53   * </PRE>
54   * 
55   * <P>
56   * Refer to the faxstat man page (from the HylaFAX distribution) for more
57   * information. This program depends on the gnu.getopt package for command line
58   * parsing. gnu.getopt (java-getopt) can be found at <a
59   * href="http://www.urbanophile.com/arenn/">http://www.urbanophile.com/arenn/
60   * </a>
61   */
62  public class FaxStat {
63  
64  	public static void main(String arguments[]) {
65  		Vector list = new Vector();
66  		HylaFAXClient c = new HylaFAXClient();
67  		try {
68  			c.open("10.0.0.205");
69  
70  			try {
71  				c.user("fax");
72  				// c.admin(PASSADMIN);
73  				c.tzone(HylaFAXClientProtocol.TZONE_LOCAL);
74  				for (int i = 1; i <= 2; i++) {
75  					list = c.getList(i == 1 ? "sendq" : "doneq");
76  					list.addAll(c.getList(""));
77  					Enumeration lines = list.elements();
78  					String line;
79  					long jobidL = -1;
80  					while (lines.hasMoreElements()) {
81  						try {
82  							line = (String) lines.nextElement();
83  							String jobid = new StringTokenizer(line)
84  									.nextToken();
85  							// --> First time returns "206...", next time
86  							// returns "[Job time limit..."
87  							jobidL = Long.parseLong(jobid);
88  							Job j = c.getJob(jobidL);
89  							String etatEnvoi = j.getProperty("STATE");
90  							// --> hylafax replied FAILED
91  							etatEnvoi = j.getProperty("STATE");
92  							// --> hylafax replied FAILED
93  							etatEnvoi = j.getProperty("STATE");
94  							// --> hylafax replied FAILED
95  							etatEnvoi = j.getProperty("STATE");
96  							// --> hylafax replied FAILED
97  							String status = j.getProperty("STATUS");
98  							// --> hylafax replied \ [Job time limit exceeded]\
99  							status = j.getProperty("STATUS");
100 							// --> hylafax replied \ [Job time limit exceeded]\
101 							status = j.getProperty("STATUS");
102 							// --> hylafax replied \ [Job time limit exceeded]\
103 							status = j.getProperty("STATUS");
104 							// --> hylafax replied \ [Job time limit exceeded]\
105 							// String IDtelecopie = j.getProperty("JOBINFO");
106 							// --> command jparm JOBINFO doesn't appear in the
107 							// log
108 							String sDateEnvoi = j.getProperty("SENDTIME");
109 							// --> hylafax replied 20050523133531
110 							sDateEnvoi = j.getProperty("SENDTIME");
111 							// --> hylafax replied 20050523133531
112 							sDateEnvoi = j.getProperty("SENDTIME");
113 							// --> hylafax replied 20050523133531
114 							sDateEnvoi = j.getProperty("SENDTIME");
115 							// --> hylafax replied 20050523133531
116 							sDateEnvoi = j.getProperty("SENDTIME");
117 							// --> hylafax replied 20050523133531
118 							int nbPages = Integer.parseInt(j
119 									.getProperty("TOTPAGES"));
120 							nbPages = Integer.parseInt(j
121 									.getProperty("TOTPAGES"));
122 							nbPages = Integer.parseInt(j
123 									.getProperty("TOTPAGES"));
124 							nbPages = Integer.parseInt(j
125 									.getProperty("TOTPAGES"));
126 							nbPages = Integer.parseInt(j
127 									.getProperty("TOTPAGES"));
128 							// --> command jparm TOTPAGES doesn't appear in the
129 							// log...
130 							String correspondant = j.getProperty("EXTERNAL");
131 							// --> hylafax replied 0475019884
132 							correspondant = j.getProperty("EXTERNAL");
133 							// --> hylafax replied 0475019884
134 							correspondant = j.getProperty("EXTERNAL");
135 							// --> hylafax replied 0475019884
136 							correspondant = j.getProperty("EXTERNAL");
137 							// --> hylafax replied 0475019884
138 							correspondant = j.getProperty("EXTERNAL");
139 							// --> hylafax replied 0475019884
140 							String initColl = j.getProperty("OWNER");
141 							// --> command jparm OWNER doesn't appear in the
142 							initColl = j.getProperty("OWNER");
143 							// --> command jparm OWNER doesn't appear in the
144 							initColl = j.getProperty("OWNER");
145 							// --> command jparm OWNER doesn't appear in the
146 							initColl = j.getProperty("OWNER");
147 							// --> command jparm OWNER doesn't appear in the
148 							initColl = j.getProperty("OWNER");
149 							// --> command jparm OWNER doesn't appear in the
150 							// log...
151 							// IDtelecopie = j.getProperty("JOBINFO"); // yes,
152 							// another
153 							// time...
154 							// --> hylafax replied 000000213082
155 							// --> exception
156 							// ...some statements...
157 							// ...write the status and message error in our
158 							// logs...
159 
160 						} finally {
161 							if (i == 2) // if doneq, delete the job
162 								c.jdele(jobidL);
163 						}
164 					}
165 				}
166 			} catch (Exception e) {
167 				e.printStackTrace();
168 
169 			}
170 		} catch (Exception e) {
171 			e.printStackTrace();
172 
173 		}
174 
175 	}// main
176 }// FaxStat
177 
178 // FaxStat.java