KickJava   Java API By Example, From Geeks To Geeks.

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


1 package SnowMailClient.gnupg.model;
2
3 import java.util.*;
4 import java.io.*;
5 import java.text.*;
6
7
8 /**
9    represent a single uid as in
10      uid:f::::::::Werner Koch <wk@gnupg.org>:
11    A key can have severa uid records
12 */

13 public final class UIDRecord
14 {
15   private String JavaDoc name;
16   private String JavaDoc mail;
17
18   public UIDRecord()
19   {
20   }
21
22   public final String JavaDoc getName() { return name; }
23   public final String JavaDoc getMail() { return mail; }
24
25   /** parse name and mail
26   */

27   public void parseUID_colon_format(String JavaDoc line) throws Exception JavaDoc
28   {
29     Scanner scanner = new Scanner(line);
30     scanner.useDelimiter(":");
31
32     String JavaDoc r1 = scanner.next();
33     if(!r1.equalsIgnoreCase("uid")) throw new Exception JavaDoc("UID reader read only uid records!, not "+r1);
34
35     String JavaDoc ignored = scanner.next();
36     skip(scanner, 3, "UID0"); // forget
37
ignored = scanner.next();
38     skip(scanner, 1, "UID1"); // forget
39

40     String JavaDoc id1 = scanner.next();
41
42     skip(scanner, 1, "UID2");
43     String JavaDoc nameAndMail = scanner.next();
44     //System.out.println("UID1= "+id1);
45
//System.out.println("UID2= "+id2);
46

47     // search mail
48
int posS = nameAndMail.indexOf("<");
49     int posE = nameAndMail.indexOf(">", posS+1);
50
51     if(posS>=0&&posE>0)
52     {
53       name = nameAndMail.substring(0,posS).trim();
54       mail = nameAndMail.substring(posS+1, posE).trim();
55     }
56     else
57     {
58       name = nameAndMail.trim();
59     }
60     //System.out.println("Name="+name);
61
//System.out.println("Mail="+mail);
62

63
64
65     skip(scanner, 0, "UID"); //no more entries
66
}
67
68   private void skip(Scanner scanner, int n, String JavaDoc prefix)
69   {
70      for(int i=0; i<n; i++)
71      {
72         if(!scanner.hasNext())
73         {
74           System.out.println(""+prefix+" has no more entries, stopped skip("+n+") after "+i);
75           return;
76         }
77
78         String JavaDoc ent = scanner.next();
79         if(ent.length()>0)
80         {
81           System.out.println(prefix+" unread rec("+i+")="+ent);
82         }
83      }
84   }
85
86 } // UIDRecord
Popular Tags