Пример #1
0
 private void encodeParams(Hashtable params, Writer writer) throws IOException {
   Enumeration en = params.keys();
   for (int i = 0; en.hasMoreElements(); i++) {
     if (i > 0) writer.write('&');
     String key = (String) en.nextElement();
     String value = (String) params.get(key);
     writer.write(key);
     writer.write('=');
     writer.write((urlEncode(value.getBytes(this.encoding))));
   }
 }
Пример #2
0
 public void receive() throws Exception {
   Object root =
       this.request("http://twitter.com/statuses/friends_timeline.json", false, null, true, true);
   if (!(root instanceof Vector)) throw new Exception("Timeline is not an array");
   Hashtable names = new Hashtable();
   Enumeration en = ((Vector) root).elements();
   while (en.hasMoreElements()) {
     Object status = en.nextElement();
     if (!(status instanceof Hashtable)) throw new Exception("Timeline status is not an object");
     Hashtable statusht = (Hashtable) status;
     Object text = statusht.get("text");
     String textstr = (String) text;
     if (!textstr.startsWith(MESSAGE_PREFIX)) continue;
     textstr = textstr.substring(MESSAGE_PREFIX.length());
     if (!(text instanceof String)) throw new Exception("Status text is not a string");
     Object user = statusht.get("user");
     if (!(user instanceof Hashtable)) throw new Exception("Status user is not an object");
     Object name = ((Hashtable) user).get("name");
     if (!(name instanceof String)) throw new Exception("Status user name is not a string");
     String namestr = (String) name;
     if (names.containsKey(namestr)) continue;
     names.put(namestr, Boolean.TRUE);
     String where = strip(textstr, '|', 0);
     String time = strip(textstr, '|', 1);
     String latlon = strip(textstr, '|', 2);
     if ((where == null) || (time == null) || (latlon == null)) continue;
     int colon = latlon.indexOf(':');
     if (colon < 0) continue;
     double lat, lon;
     try {
       lat = Double.parseDouble(latlon.substring(0, colon));
       lon = Double.parseDouble(latlon.substring(colon + 1));
     } catch (Exception e) {
       continue;
     }
     this.main.updateSignPosition(namestr, lat, lon, where, time);
   }
 }