Exemple #1
0
 /**
  * ** Returns a new URIArg with this URIArg's arguments encoded into a ** single RTProperties
  * added with a specified key [CHECK] ** @param rtpKey The key to add the encoded args at
  * ** @param exclKeys keys to exclude from encoding ** @return A new URIArg with non excluded
  * arguments encoded
  */
 public URIArg rtpEncode(String rtpKey, String... exclKeys) {
   URIArg rtpUrl = new URIArg(this.getURI());
   RTProperties rtp = new RTProperties();
   for (KeyVal kv : this.getKeyValList()) {
     String kn = kv.getKey();
     if (ListTools.contains(exclKeys, kn)) {
       rtpUrl.addArg(kv);
     } else {
       rtp.setString(kn, kv.getValue());
     }
   }
   rtpUrl.addArg(rtpKey, rtp);
   return rtpUrl;
 }
Exemple #2
0
 /**
  * ** Returns a new URIArg with this URIArg's arguments decoded from a ** single RTProperties
  * added a specified key [CHECK] ** @param rtpKey The key of the RTProperties to decode the
  * encoded args from ** @return A new URIArg with non excluded arguments encoded
  */
 public URIArg rtpDecode(String rtpKey) {
   URIArg cpyUrl = new URIArg(this.getURI());
   for (KeyVal kv : this.getKeyValList()) {
     String kn = kv.getKey();
     if (!kn.equals(rtpKey)) {
       cpyUrl.addArg(kv);
     } else {
       RTProperties rtp = URIArg.parseRTP(kv.getValue());
       for (Object rpk : rtp.getPropertyKeys()) {
         String rk = rpk.toString();
         String rv = rtp.getString(rk, "");
         cpyUrl.addArg(rk, rv);
       }
     }
   }
   return cpyUrl;
 }
Exemple #3
0
 /**
  * ** Adds an argument to the URI ** @param key The key name of the argument to add ** @param rtp
  * The RTP encoded values of the new key ** @return This URIArg, with the argument added
  */
 public URIArg addArg(String key, RTProperties rtp) {
   String r = (rtp != null) ? rtp.toString() : null;
   if (!StringTools.isBlank(r)) {
     return this._addArg(key, URIArg.encodeRTP(rtp), false /*encode*/, false /*obfuscate*/);
   } else {
     return this.addArg(key, "");
   }
 }
Exemple #4
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();
  }
Exemple #5
0
 /** ** Sets the 'port' */
 public boolean setPort(int _port) {
   String uri = this.getURI();
   if ((_port > 0) && URIArg.isAbsoluteURL(uri)) {
     try {
       URL oldURI = new URL(uri);
       String proto = oldURI.getProtocol();
       String host = oldURI.getHost();
       int port = _port;
       String file = oldURI.getFile();
       URL newURI = new URL(proto, host, port, file);
       this._setURI(newURI.toString());
       return true;
     } catch (MalformedURLException mue) {
       // error
     }
   }
   return false;
 }
Exemple #6
0
 /**
  * ** Hex-encodes a URL argument ** @param sb The StringBuffer where the hex encoded String
  * argument will be placed ** @param s The URL argument to encode ** @param obfuscateAll True to
  * force hex-encoding on all argument characters ** @return The StringBuffer where the hex-encoded
  * String will be placed
  */
 public static StringBuffer encodeArg(StringBuffer sb, String s, boolean obfuscateAll) {
   if (sb == null) {
     sb = new StringBuffer();
   }
   if (s != null) {
     char ch[] = new char[s.length()];
     s.getChars(0, s.length(), ch, 0);
     for (int i = 0; i < ch.length; i++) {
       if (obfuscateAll || URIArg.shouldEncodeArgChar(ch[i])) {
         // escape non-alphanumeric characters
         sb.append("%");
         sb.append(Integer.toHexString(0x100 + (ch[i] & 0xFF)).substring(1));
       } else {
         // letters and digits are ok as-is
         sb.append(ch[i]);
       }
     }
   }
   return sb;
 }
Exemple #7
0
 /**
  * ** Decodes the specified hex-encoded argument (not yet fully tested) ** @param s The String to
  * decode ** @return The decoded String
  */
 private String decodeArg(String s) {
   StringBuffer sb = URIArg.decodeArg(null, s);
   return sb.toString();
 }
Exemple #8
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();
 }
Exemple #9
0
 /** ** Copy Constructor */
 public URIArg(URIArg uriArg) {
   this.setUniqueKeys(uriArg.hasUniqueKeys());
   this._setURI(uriArg.uri);
   this.setKeys(uriArg.keys); // deep copy
 }
Exemple #10
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();
 }
Exemple #11
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);
 }
Exemple #12
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();
 }