Ejemplo n.º 1
0
 private void actionListener() {
   String artist = StringUtils.removeIllegalChars(searchArtist.getText().toString());
   String title = StringUtils.removeIllegalChars(searchTitle.getText().toString());
   String album = StringUtils.removeIllegalChars(searchAlbum.getText().toString());
   boolean noArtist = TextUtils.isEmpty(artist);
   boolean noTitle = TextUtils.isEmpty(title);
   boolean noAlbum = TextUtils.isEmpty(album);
   String key = "";
   if (noArtist && noTitle && noAlbum) return;
   //          "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
   // "<audio schema=\"http://www.limewire.com/schemas/audio.xsd\"" +
   // " title=\"lady gaga\" artist=\"lady gaga\"/>";
   StringBuilder b = new StringBuilder(256);
   b.append(
       "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <audio schema=\"http://www.limewire.com/schemas/audio.xsd\"");
   if (!noArtist) {
     Constants.dbAdapter.insertHistory(artist, DbAdapter.TYPE_ARTIST);
     b.append("artist=\"");
     b.append(artist);
     b.append("\" ");
     key += artist + " ";
   }
   if (!noTitle) {
     Constants.dbAdapter.insertHistory(title, DbAdapter.TYPE_TITLE);
     b.append("title=\"");
     b.append(title);
     b.append("\" ");
     key += title + " ";
   }
   if (!noAlbum) {
     Constants.dbAdapter.insertHistory(album, DbAdapter.TYPE_TITLE);
     b.append("album=\"");
     b.append(album);
     b.append("\" ");
     key += album;
   }
   b.append("/>");
   SearchResultActivity.handleMp3ListXMLIntent(this, key, b.toString());
 }
Ejemplo n.º 2
0
  /**
   * Constructs a new endpoint. If requireNumeric is true, or strict is false, no DNS lookups are
   * ever involved. If requireNumeric is false or strict is true, a DNS lookup MAY be performed if
   * the hostname is not numeric.
   *
   * <p>To never block, make sure strict is false.
   */
  public Endpoint(String hostAndPort, boolean requireNumeric, boolean strict) {
    final int DEFAULT = 6346;
    int j = hostAndPort.indexOf(":");
    if (j < 0) {
      this.hostname = hostAndPort;
      this.port = DEFAULT;
    } else if (j == 0) {
      throw new IllegalArgumentException();
    } else if (j == (hostAndPort.length() - 1)) {
      this.hostname = hostAndPort.substring(0, j);
      this.port = DEFAULT;
    } else {
      this.hostname = hostAndPort.substring(0, j);
      try {
        this.port = Integer.parseInt(hostAndPort.substring(j + 1));
      } catch (NumberFormatException e) {
        throw new IllegalArgumentException();
      }

      if (!NetworkUtils.isValidPort(getPort())) throw new IllegalArgumentException("invalid port");
    }

    if (requireNumeric) {
      // TODO3: implement with fewer allocations
      String[] numbers = StringUtils.split(hostname, '.');
      if (numbers.length != 4) throw new IllegalArgumentException();
      for (int i = 0; i < numbers.length; i++) {
        try {
          int x = Integer.parseInt(numbers[i]);
          if (x < 0 || x > 255) throw new IllegalArgumentException();
        } catch (NumberFormatException fail) {
          throw new IllegalArgumentException();
        }
      }
    }

    if (strict && !NetworkUtils.isValidAddress(hostname))
      throw new IllegalArgumentException("invalid address: " + hostname);
  }
  /**
   * Parses a new ExtendedEndpoint. Strictly validates all data. For example, addresses MUST be in
   * dotted quad format.
   *
   * @param line a single line read from the stream
   * @return the endpoint constructed from the line
   * @exception IOException problem reading from in, e.g., EOF reached prematurely
   * @exception ParseException data not in proper format. Does NOT necessarily set the offset of the
   *     exception properly.
   * @see write
   */
  public static ExtendedEndpoint read(String line) throws ParseException {
    // Break the line into fields.  Skip if badly formatted.  Note that
    // subsequent delimiters are NOT coalesced.
    String[] linea = StringUtils.splitNoCoalesce(line, FIELD_SEPARATOR);
    if (linea.length == 0) throw new ParseException("Empty line", 0);

    // 1. Host and port.  As a dirty trick, we use existing code in Endpoint.
    // Note that we strictly validate the address to work around corrupted
    // gnutella.net files from an earlier version
    boolean pureNumeric;

    String host;
    int port;
    try {
      Endpoint tmp = new Endpoint(linea[0], true); // require numeric.
      host = tmp.getAddress();
      port = tmp.getPort();
      pureNumeric = true;
    } catch (IllegalArgumentException e) {
      // Alright, pure numeric failed -- let's try constructing without
      // numeric & without requiring a DNS lookup.
      try {
        Endpoint tmp = new Endpoint(linea[0], false, false);
        host = tmp.getAddress();
        port = tmp.getPort();
        pureNumeric = false;
      } catch (IllegalArgumentException e2) {
        ParseException e3 =
            new ParseException("Couldn't extract address and port from: " + linea[0], 0);
        e3.initCause(e2);
        throw e3;
      }
    }

    // Build endpoint without any optional data.  (We'll set it if possible
    // later.)
    ExtendedEndpoint ret = new ExtendedEndpoint(host, port, false);

    // 2. Average uptime (optional)
    if (linea.length >= 2) {
      try {
        ret.dailyUptime = Integer.parseInt(linea[1].trim());
      } catch (NumberFormatException e) {
      }
    }

    // 3. Time of pong (optional).  Do NOT use current system tome
    //   if not set.
    ret.timeRecorded = DEFAULT_TIME_RECORDED;
    if (linea.length >= 3) {
      try {
        ret.timeRecorded = Long.parseLong(linea[2].trim());
      } catch (NumberFormatException e) {
      }
    }

    // 4. Time of successful connects (optional)
    if (linea.length >= 4) {
      try {
        String times[] = StringUtils.split(linea[3], LIST_SEPARATOR);
        for (int i = times.length - 1; i >= 0; i--)
          ret.recordConnectionAttempt(ret.connectSuccesses, Long.parseLong(times[i].trim()));
      } catch (NumberFormatException e) {
      }
    }

    // 5. Time of failed connects (optional)
    if (linea.length >= 5) {
      try {
        String times[] = StringUtils.split(linea[4], LIST_SEPARATOR);
        for (int i = times.length - 1; i >= 0; i--)
          ret.recordConnectionAttempt(ret.connectFailures, Long.parseLong(times[i].trim()));
      } catch (NumberFormatException e) {
      }
    }

    // 6. locale of the connection (optional)
    if (linea.length >= 6) {
      ret.setClientLocale(linea[5]);
    }

    // 7. udp-host
    if (linea.length >= 7) {
      try {
        int i = Integer.parseInt(linea[6]);
        if (i >= 0) ret.udpHostCacheFailures = i;
      } catch (NumberFormatException nfe) {
      }
    }

    // validate address if numeric.
    if (pureNumeric && !NetworkUtils.isValidAddress(host))
      throw new ParseException("invalid dotted addr: " + ret, 0);

    // validate that non UHC addresses were numeric.
    if (!ret.isUDPHostCache() && !pureNumeric)
      throw new ParseException("illegal non-UHC endpoint: " + ret, 0);

    return ret;
  }