Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jhfc/FaxViewer.java


1   package jhfc;
2   
3   import java.io.*;
4   //import java.awt.*;
5   import javax.swing.*;
6   
7   public class FaxViewer
8   implements Runnable
9   {
10  //  private HylaFaxJobController    hjc;
11  //  private HylaFaxConnectionManager  hfcm;
12    private boolean        debug;
13    private String        viewer;
14  //  private int        jobID;
15  //  private String        tmpDir;
16    private String        tmpFile;
17  /*
18                  FaxViewer fv=new FaxViewer(
19                    hjc, 
20                    hfcm
21                  )
22                  fv.view(hjdm.getJob(i).getID());
23  
24  
25  
26                    hjc, 
27                    hfcm, 
28                    hjdm.getJob(i).getID());
29  
30  
31    String fileNameOnServer=hjc.getFileName(hfcm, hjdm.getJob(i).getID());
32  
33    FileOutputStream out=new FileOutputStream("c:\\x.ps");
34      
35    out.write(hfcm.getReceived(fileNameOnServer));
36    out.close();
37  
38                
39    Runtime rt=Runtime.getRuntime();
40    rt.exec(viewer+" c:\\x.ps");
41  
42  */
43  
44    
45  public FaxViewer
46  (
47    HylaFaxJobController    hjc, 
48    HylaFaxConnectionManager  hfcm, 
49    String        viewer, 
50    int        jobID, 
51    String        tmpDir, 
52    boolean        debug
53  )
54    throws jhfc.ProtocollException
55  {
56    String fileNameOnServer;
57    FileOutputStream out;
58  
59    out=null;
60    this.debug = debug;
61  //  this.hjc=hjc;
62  //  this.hfcm=hfcm;
63    this.viewer=viewer;
64  //  this.tmpDir=tmpDir;
65  //  this.jobID=jobID;
66  
67    try
68    {
69      tmpFile = 
70        tmpDir+
71        File.separator+
72        "jhfc" + 
73        new Integer(Math.abs(new java.util.Random().nextInt())).toString() +
74        ".tiff";
75  
76      fileNameOnServer=hjc.getFileName(hfcm, jobID);
77  
78  
79      out=new FileOutputStream(tmpFile);
80  
81      out.write(hfcm.getReceived(fileNameOnServer));
82      out.close();
83  
84          
85  
86      Thread t=new Thread(this);
87      t.start();
88    }
89    catch (jhfc.ProtocollException ex)
90    {
91      // temporaere Datei loeschen
92      try
93      {
94        if(out!=null)
95        {
96          out.close();
97        }
98        (new File(tmpFile)).delete();
99      }
100     catch (Exception exx)
101     {
102     }
103 
104     throw new ProtocollException(ex.getMessage(), ex.nr);
105   }
106   catch (Exception ex)
107   {
108     // temporaere Datei loeschen
109     try
110     {
111       if(out!=null)
112       {
113         out.close();
114       }
115       (new File(tmpFile)).delete();
116     }
117     catch (Exception exx)
118     {
119     }
120   }
121 }
122 
123 /*
124   )
125   {
126     String fileNameOnServer=hjc.getFileName(hfcm, jobID);
127 
128     FileOutputStream out=new FileOutputStream("c:\\x.ps");
129     
130     out.write(hfcm.getReceived(fileNameOnServer));
131     out.close();
132 
133               
134     Runtime rt=Runtime.getRuntime();
135     rt.exec(viewer+" c:\\x.ps");
136   }
137 */
138 /*
139     TMPTIFF = "SuSEFaxTIFFG3IMG" +
140       new Integer(Math.abs(new java.util.Random().nextInt())).toString() +
141       ".tmp";
142 
143     // Kommando parsen
144     String parsedCmd = parseCommand(command);
145     if( parsedCmd == null )
146       state = NOPLACEHOLDER;
147     else {
148       if( debug )
149   for(int i=0; i<cmdArray.length; i++)
150     System.out.println(cmdArray[i]);
151       
152       /* In der folgenden Zeile wird zum Schein ein FileInputStream auf
153        * das Programm für den externen Viewer geoeffnet. Resultat:
154        * Wenn die Datei nicht vorhanden ist, wird FileNotFoundException
155        * erzeugt und an das Hauptprogramm weitergereicht 
156       new FileInputStream(cmdArray[0]);
157 
158       if( debug )
159   System.out.println("FaxViewer: Hole Datei <" + faxfile +
160          "> vom Server");
161       // Datei vom Server holen
162       getFaxImage();
163     }
164 
165     this.start();
166 }
167 */
168 
169 /*
170   private void getFaxImage() throws Exception {
171     // Diese Funktion holt die angeforderte Datei vom Server
172     FileOutputStream out =
173       new FileOutputStream(FaxSetup.tmpdir + File.separator + TMPTIFF);
174     
175     out.write(con.getReceived(faxfile));
176     out.flush();
177     out.close();
178   }
179 */
180 
181 /*
182   private String parseCommand(String c) {
183     String ret = null;
184 
185     // Kommt der Platzhalter ueberhaupt vor?
186     if( c.indexOf("$F") >= 0 ) {
187       ret = "";
188 
189       // Ersetzen des Platzhalters mit Pfad auf temporaere Datei
190       ret = c.substring(0, c.indexOf("$F")) + FaxSetup.tmpdir +
191   File.separator + TMPTIFF +
192   c.substring(c.indexOf("$F") + 2, c.length());
193       
194       // Kommando-Array anlegen
195       PhoneTokenizer pt = new PhoneTokenizer(ret, " ");
196       cmdArray = new String[pt.countTokens()];
197       
198       // Kommando-Array fuellen
199       for(int i=0; i<pt.countTokens(); i++)
200   cmdArray[i] = pt.nextToken();
201     }
202 
203     return ret;
204   }
205 */
206 /*
207     String fileNameOnServer=hjc.getFileName(hfcm, jobID);
208 
209     FileOutputStream out=new FileOutputStream("c:\\x.ps");
210     
211     out.write(hfcm.getReceived(fileNameOnServer));
212     out.close();
213 
214               
215     Runtime rt=Runtime.getRuntime();
216     rt.exec(viewer+" c:\\x.ps");
217 */
218   public void run
219   (
220   )
221   {
222     try {
223       // Prozess-Thread erzeugen
224       Process p = Runtime.getRuntime().exec(viewer+" "+tmpFile);
225     
226       // STDERR und STDOUT des Prozesses besorgen
227       BufferedReader err = 
228         new BufferedReader(new InputStreamReader(p.getErrorStream()));
229       BufferedReader in =
230         new BufferedReader(new InputStreamReader(p.getInputStream()));
231     
232       // Ausgabe von STDERR und STDOUT auf STDERR
233       String line;
234       while( (line = err.readLine()) != null ) {
235         System.err.println(line);
236       }
237       while( (line = in.readLine()) != null ) {
238         System.err.println(line);
239       }
240     
241       in.close();
242       err.close();
243     
244       // temporaere Datei loeschen
245       (new File(tmpFile)).delete();
246     }
247     catch(Exception ex)
248     {
249       // temporaere Datei loeschen
250       (new File(tmpFile)).delete();
251 
252       JOptionPane.showMessageDialog(
253         null,
254         ex+": "+ex.getMessage(),  
255         "JHFC",
256 //        JOptionPane.INFORMATION_MESSAGE);
257         JOptionPane.ERROR_MESSAGE);
258     }
259   }
260 }
261