KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > gnupg > LineProcessors > KeySearchResultProcessor


1 package SnowMailClient.gnupg.LineProcessors;
2
3 import SnowMailClient.gnupg.model.*;
4 import java.util.*;
5 import java.io.*;
6
7 public class KeySearchResultProcessor implements LineProcessor
8 {
9   private final Vector<KeyIDFromSearchResult> keys = new Vector<KeyIDFromSearchResult>();
10   private KeyIDFromSearchResult actual = null;
11
12   public KeySearchResultProcessor()
13   {
14
15   } // Constructor
16

17   public Vector<KeyIDFromSearchResult> getKeyIDs() { return keys; }
18
19   public void processLine(String JavaDoc _line)
20   {
21     String JavaDoc line = _line.trim();
22     if(line.startsWith("gpg:"))
23     {
24       // ignore messages from gpg, they are conversion errors, not very illuminating...
25
// like gpg: conversion from `utf-8' to `CP850' failed: Illegal byte sequence
26
}
27     else if(line.startsWith("("))
28     {
29       actual = new KeyIDFromSearchResult();
30       keys.addElement(actual);
31       int pos = line.indexOf(")");
32       if(pos>0) line = line.substring(pos+1).trim();
33       actual.addAddress(line);
34     }
35     else if(line.indexOf("@")>0)
36     {
37       actual.addAddress(line);
38     }
39     else
40     {
41       actual.parseIDLine(line);
42     }
43
44   }
45
46
47   public String JavaDoc toString()
48   {
49     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
50     for(KeyIDFromSearchResult k: keys)
51     {
52        sb.append(""+k+"\n");
53     }
54     return sb.toString();
55   }
56
57
58
59   public static void main(String JavaDoc[] a)
60   {
61     KeySearchResultProcessor kr = new KeySearchResultProcessor();
62     kr.test();
63   }
64
65   private void test()
66   {
67     try
68     {
69
70       FileInputStream fis = new FileInputStream("c:/temp/kex.txt");
71       BufferedReader r= new BufferedReader(new InputStreamReader(fis));
72       String JavaDoc line;
73       while((line=r.readLine())!=null)
74       {
75         processLine(line);
76       }
77       System.out.println(""+this);
78
79     }
80     catch(Exception JavaDoc e)
81     {
82       e.printStackTrace();
83     }
84   }
85
86
87 } // KeySearchResultProcessor
88

89
90 /*
91
92 (1) Vanessa Karlo <vanessa.karlo@iba-media.com>
93     Vanessa Karlo <vanessa@professionalexpert.com>
94       1024 bit DSA key 49D5900B, created: 2005-01-10
95 (2) Vanessa Gomes de Oliveira <gomes@comput.ibilce.unesp.br>
96       1024 bit DSA key 6071465E, created: 2004-11-30
97 (3) Vanessa <kf132595@hotmail.com>
98       2048 bit RSA key 5F0D372F, created: 2004-11-21, expires: 2004-12-22 (expired)
99 (4) Vanessa <99190001@webmail.stut.edu.tw>
100       2048 bit RSA key 0AFF37FF, created: 2004-11-16, expires: 2004-12-20 (expired)
101 (5) Vanessa Michele Rose Warner (personal gpg key) <ness@nessuk.org>
102       1024 bit DSA key 59309409, created: 2004-11-05
103 (6) Vanessa Karlo <vanessa@professionalexpert.com>
104       1024 bit DSA key 67D501DD, created: 2004-10-20 (revoked)
105 (7) Vanesssa Karlo <vanessa@professionalexpert.com>
106       1024 bit DSA key 5A887734, created: 2004-10-16
107 (8) Vanessa Innes <vji@georgetown.edu>
108       1024 bit DSA key 4BD5B818, created: 2004-08-13
109 (9) vanessa de lima lopez <guachiguachi70@hotmail.com>
110       1024 bit DSA key 46C76F12, created: 2004-06-14
111 (10) Vanessa Vieira <yeye149@hotmail.com>
112       1024 bit DSA key 3566F0D9, created: 2004-06-11
113 (11) Vanessa Matas (Ambar) <ambar@fibranet.org>
114       1024 bit DSA key 1167FE29, created: 2004-05-16
115
116 */
Popular Tags