KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > FileSignatureGenerator


1 package net.suberic.pooka;
2 import java.io.*;
3
4 /**
5  * This is a simple SignatureGenerator which reads a file and returns its
6  * contents as a signature.
7  */

8 public class FileSignatureGenerator extends SignatureGeneratorImpl {
9
10     public FileSignatureGenerator() {
11     }
12
13     /**
14      * Returns the contents of the file UserProfile.username.signatureFile
15      * as a signature.
16      */

17     
18     public String JavaDoc generateSignature(String JavaDoc text) {
19     if (profile != null) {
20         String JavaDoc fileName = Pooka.getProperty("UserProfile." + profile.getName() + ".signatureFile", "");
21         if (!fileName.equals("")) {
22         File f = new File(fileName);
23         if (f.exists() && f.canRead()) {
24             try {
25             StringBuffer JavaDoc returnValue = new StringBuffer JavaDoc();
26             BufferedReader reader = new BufferedReader(new FileReader(f));
27             boolean done = false;
28             while (!done) {
29                 String JavaDoc nextLine = reader.readLine();
30                 if (nextLine != null) {
31                 returnValue.append(nextLine);
32                 returnValue.append("\n");
33                 } else {
34                 done = true;
35                 }
36             }
37
38             return returnValue.toString();
39             } catch (Exception JavaDoc e) {
40             e.printStackTrace();
41             }
42         }
43         }
44     }
45
46     return null;
47     }
48
49 }
50
Popular Tags