KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > gnupg > model > SignatureVerificationResult


1 package SnowMailClient.gnupg.model;
2
3 import java.text.*;
4 import java.util.*;
5 import SnowMailClient.Language.*;
6
7 public final class SignatureVerificationResult
8 {
9   final static private SimpleDateFormat madeFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
10   private boolean goodSignature = false;
11
12   private String JavaDoc madeString = "";
13   private long madeDate = -1;
14   private String JavaDoc signatureFrom = "";
15   private String JavaDoc warning = "";
16
17   public SignatureVerificationResult()
18   {
19   }
20
21   /**
22       gpg: Signature made 02/13/05 21:34:22 Westeuropäische Normalzeit using DSA key ID 3CDE995E
23   */

24   public void parseLine(String JavaDoc line) throws Exception JavaDoc
25   {
26     int pos = line.indexOf("Signature made");
27     if(pos>=0)
28     {
29       madeString = line.substring(pos+15);
30       //System.out.println("MadeString: "+madeString);
31
try
32       {
33         madeDate = madeFormat.parse(madeString).getTime();
34       }
35       catch(Exception JavaDoc e) { e.printStackTrace(); }
36     }
37
38     pos = line.indexOf("Good signature");
39     if(pos>=0)
40     {
41        goodSignature = true;
42        pos = line.indexOf("from");
43        if(pos==-1) throw new Exception JavaDoc("No from in the good signature text");
44        signatureFrom = line.substring(pos+5);
45     }
46
47     pos = line.indexOf("BAD signature");
48     if(pos>=0)
49     {
50        goodSignature = false;
51        pos = line.indexOf("from");
52        if(pos==-1) throw new Exception JavaDoc("No from in the good signature text");
53        signatureFrom = line.substring(pos+5);
54     }
55
56     pos = line.toUpperCase().indexOf("WARNING");
57     if(pos>=0)
58     {
59        warning = line.substring(pos+9).trim();
60     }
61   }
62
63   public boolean isSignatureGood() { return goodSignature; }
64   public String JavaDoc getSigner() { return signatureFrom; }
65   public long getSignatureDate() { return this.madeDate; }
66
67
68   public String JavaDoc toString()
69   {
70     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
71     if(goodSignature)
72     {
73       //return Language.translate("GOOD signature from %1 made at %2", signatureFrom, madeString);
74
sb.append( Language.translate("GOOD signature from %", signatureFrom) + " ("+madeFormat.format(new Date(madeDate))+")" );
75     }
76     else
77     {
78       sb.append( Language.translate("BAD signature from %", signatureFrom) );
79     }
80
81     if(warning.length()>0)
82     {
83       sb.append("\n "+Language.translate("Warning")+": "+warning);
84     }
85
86     return sb.toString();
87   }
88
89
90
91
92 } // SignatureVerificationResult
Popular Tags