Esempio n. 1
0
  /** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */
  public static void main(String argv[]) {
    RTConfig.setCommandLineArgs(argv);

    /* decode URI argument strings */
    if (RTConfig.hasProperty(ARG_DECODE)) {
      String a = RTConfig.getString(ARG_DECODE, "");
      String s = URIArg.decodeArg(new StringBuffer(), a).toString();
      Print.sysPrintln("ASCII: " + s);
      System.exit(0);
    }

    /* encode Base64 strings */
    if (RTConfig.hasProperty(ARG_ENCODE)) {
      String s = RTConfig.getString(ARG_ENCODE, "");
      String a = URIArg.encodeArg(new StringBuffer(), s).toString();
      Print.sysPrintln("Args: " + a);
      System.exit(0);
    }

    /* RTP decode */
    if (RTConfig.hasProperty(ARG_RTPDEC)) {
      URIArg rtpUrl = new URIArg(RTConfig.getString(ARG_RTPDEC, ""));
      URIArg decUrl = rtpUrl.rtpDecode("rtp");
      Print.sysPrintln("URL: " + decUrl.toString());
      System.exit(0);
    }

    /* RTP encode */
    if (RTConfig.hasProperty(ARG_RTPENC)) {
      URIArg decUrl = new URIArg(RTConfig.getString(ARG_RTPENC, ""));
      URIArg rtpUrl = decUrl.rtpEncode("rtp");
      Print.sysPrintln("URL: " + rtpUrl.toString());
      System.exit(0);
    }

    /* no options */
    usage();
  }
Esempio n. 2
0
 /**
  * ** Hex-encodes a URL argument ** @param s The URL argument to encode ** @param obfuscateAll
  * True to force hex-encoding on all argument characters ** @return The hex-encoded String
  */
 private String encodeArg(String s, boolean obfuscateAll) {
   StringBuffer sb = URIArg.encodeArg(null, s, obfuscateAll);
   return sb.toString();
 }
Esempio n. 3
0
 /**
  * ** Obfuscates (hex-encodes) all characters in the String ** @param s The String to hex-encode
  * ** @return The hex-encoded String
  */
 public static String obfuscateArg(String s) {
   return URIArg.encodeArg(new StringBuffer(), s, true).toString();
 }
Esempio n. 4
0
 /**
  * ** Hex-encodes a URL argument (if required) ** @param sb The StringBuffer where the hex encoded
  * String argument will be placed ** @param s The URL argument to encode (if required) ** @return
  * The StringBuffer where the hex-encoded String will be placed
  */
 public static StringBuffer encodeArg(StringBuffer sb, String s) {
   return URIArg.encodeArg(sb, s, false);
 }
Esempio n. 5
0
 /**
  * ** Hex-encodes a URL argument (if required) ** @param s The URL argument to encode (if
  * required) ** @return The hex encoded argument
  */
 public static String encodeArg(String s) {
   return URIArg.encodeArg(null, s, false).toString();
 }
Esempio n. 6
0
  /* encode GeoPoint into nearest address URI */
  protected String getGeoPointGeocodeURL(String address, String country) {
    StringBuffer sb = new StringBuffer();
    GoogleSig sig = this.getSignature();

    /* country */
    if (StringTools.isBlank(country)) {
      country = this.getProperties().getString(PROP_countryCodeBias, DEFAULT_COUNTRY);
    }

    /* predefined URL */
    String gcURL = this.getProperties().getString(PROP_geocodeURL, null);
    if (!StringTools.isBlank(gcURL)) {
      sb.append(gcURL);
      sb.append("&q=").append(URIArg.encodeArg(address));
      if (!StringTools.isBlank(country)) {
        // country code bias: http://en.wikipedia.org/wiki/CcTLD
        sb.append("&gl=").append(country);
      }
      return sb.toString();
    }

    /* assemble URL */
    sb.append(this.getGeoPointGeocodeURI());
    sb.append("output=xml");
    sb.append("&oe=utf8");

    /* address/country */
    sb.append("&q=").append(URIArg.encodeArg(address));
    if (!StringTools.isBlank(country)) {
      sb.append("&gl=").append(country);
    }

    /* sensor */
    String sensor = this.getProperties().getString(PROP_sensor, null);
    if (!StringTools.isBlank(sensor)) {
      sb.append("&sensor=").append(sensor);
    }

    /* channel */
    String channel = this.getProperties().getString(PROP_channel, null);
    if (!StringTools.isBlank(channel)) {
      sb.append("&channel=").append(channel);
    }

    /* key */
    String auth = this.getAuthorization();
    if (StringTools.isBlank(auth) || auth.startsWith("*")) {
      // invalid key
    } else if (auth.startsWith(CLIENT_ID_PREFIX)) {
      sb.append("&client=").append(auth);
    } else {
      sb.append("&key=").append(auth);
    }

    /* return url */
    String defURL = sb.toString();
    if (sig == null) {
      return defURL;
    } else {
      String urlStr = sig.signURL(defURL);
      return (urlStr != null) ? urlStr : defURL;
    }
  }