1 package SnowMailClient.gnupg.model; 2 3 import java.util.*; 4 import SnowMailClient.Language.Language; 5 import java.text.*; 6 7 25 public final class KeyIDFromSearchResult 26 { 27 private final Vector<String > addresses = new Vector<String >(); 28 private boolean revoked = false; 29 private boolean expired = false; 30 private int keyLength = -1; 31 private long created = -1; 32 private long expires = -1; private String shortID = null; 34 private String algorithm = null; 35 36 public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); 37 38 public KeyIDFromSearchResult() 39 { 40 41 } 43 45 public void addAddress(String add) 46 { 47 addresses.add(add); 48 } 49 50 public void parseIDLine(String kid) 51 { 52 Scanner s = new Scanner(kid); 53 keyLength = s.nextInt(); 54 s.next(); 55 algorithm = s.next(); 56 s.next(); 57 shortID = this.removeComa(s.next()); 58 s.next(); if(!s.hasNext()) return; 60 61 String n = s.next(); 62 63 try 64 { 65 created = dateFormat.parse(n).getTime(); 66 } 67 catch(Exception e) 68 { 69 e.printStackTrace(); 70 } 71 72 73 if(!s.hasNext()) return; 74 75 n = s.next(); 76 77 if(n.startsWith("expired")) 78 { 79 expired = true; 80 return; 81 } 82 83 if(n.indexOf("revoked")>=0) 84 { 85 revoked = true; 86 } 87 88 if(n.equalsIgnoreCase("expires:")) 89 { 90 try 91 { 92 n = s.next(); 93 this.expires = dateFormat.parse(n).getTime(); 94 if(System.currentTimeMillis() > expires) expired=true; 95 } 96 catch(Exception e) 97 { 98 e.printStackTrace(); 99 } 100 } 101 } 102 103 private String removeComa(String in) 104 { 105 if(in.endsWith(","))return in.substring(0,in.length()-1); 106 return in; 107 } 108 109 public String getKeyShortID() 110 { 111 return shortID; 112 } 113 114 public String getRemarks() 115 { 116 if(revoked) return Language.translate("Revoqued").toUpperCase(); 117 if(expired) return Language.translate("Expired").toUpperCase(); 118 return ""; 119 } 120 121 public String toString() 122 { 123 StringBuffer sb = new StringBuffer (); 124 if(getRemarks().length()>0) 125 { 126 sb.append(getRemarks()+"\t"); 127 } 128 sb.append(toStringAddresses()); 129 sb.append("\t"); 130 sb.append(shortID); 131 sb.append("\t, created "); 132 sb.append(dateFormat.format(new Date(this.created))); 133 sb.append("\t, expires "); 134 sb.append(dateFormat.format(new Date(this.expires))); 135 return sb.toString(); 136 } 137 138 public String toStringAddresses() 139 { 140 StringBuffer sb = new StringBuffer (); 141 if(addresses.size()==1) 142 { 143 sb.append(addresses.elementAt(0)); 144 } 145 else 146 { 147 sb.append(addresses); 148 } 149 return sb.toString(); 152 } 153 154 } | Popular Tags |