Beispiel #1
0
 /**
  * ** Returns true if the specified character should be hex-encoded in a URL ** @param ch The
  * character to test ** @return True if the specified character should be hex-encoded in a URL
  */
 private static boolean shouldEncodeArgChar(char ch) {
   if (Character.isLetterOrDigit(ch)) {
     return false;
   } else if ((ch == '_') || (ch == '-') || (ch == '.')) {
     return false;
   } else {
     return true;
   }
 }
Beispiel #2
0
 /**
  * Codage d'une chaine pour servir en tant que nom de fichier. Remplace tous ce qui n'est ni
  * lettre ni chiffre en code hexa préfixé par _
  */
 private static String codage(String s) {
   StringBuffer r = new StringBuffer();
   char a[] = s.toCharArray();
   for (int i = 0; i < a.length; i++) {
     char c = a[i];
     if (!Character.isLetterOrDigit(c)) r.append(PREFIX + Util.hex(c));
     else r.append(c);
   }
   return r.toString();
 }
Beispiel #3
0
 /**
  * Helper routine to get the scheme part of a URI. The scheme part is "http:" or "file:" or "ftp:"
  * most commonly. This functions searches for the first ':' that doesn't follow a '/'.
  *
  * @return The length of the scheme component, not counting the colon, (or alternatively the index
  *     of the colon), or -1 if the is no scheme.
  */
 public static int uriSchemeLength(String uri) {
   int len = uri.length();
   for (int i = 0; i < len; i++) {
     char ch = uri.charAt(i);
     if (ch == ':') return i;
     if (i == 0
         ? !Character.isLetter(ch)
         : (!Character.isLetterOrDigit(ch) && ch != '+' && ch != '-' && ch != '.')) return -1;
   }
   return -1;
 }
  /**
   * This method gets called when a property we're interested in is about to change. In case we
   * don't like the new value we throw a PropertyVetoException to prevent the actual change from
   * happening.
   *
   * @param evt a <tt>PropertyChangeEvent</tt> object describing the event source and the property
   *     that will change.
   * @exception PropertyVetoException if we don't want the change to happen.
   */
  public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
    if (evt.getPropertyName().equals(PROP_STUN_SERVER_ADDRESS)) {
      // make sure that we have a valid fqdn or ip address.

      // null or empty port is ok since it implies turning STUN off.
      if (evt.getNewValue() == null) return;

      String host = evt.getNewValue().toString();
      if (host.trim().length() == 0) return;

      boolean ipv6Expected = false;
      if (host.charAt(0) == '[') {
        // This is supposed to be an IPv6 litteral
        if (host.length() > 2 && host.charAt(host.length() - 1) == ']') {
          host = host.substring(1, host.length() - 1);
          ipv6Expected = true;
        } else {
          // This was supposed to be a IPv6 address, but it's not!
          throw new PropertyVetoException("Invalid address string" + host, evt);
        }
      }

      for (int i = 0; i < host.length(); i++) {
        char c = host.charAt(i);
        if (Character.isLetterOrDigit(c)) continue;

        if ((c != '.' && c != ':') || (c == '.' && ipv6Expected) || (c == ':' && !ipv6Expected))
          throw new PropertyVetoException(host + " is not a valid address nor host name", evt);
      }

    } // is prop_stun_server_address
    else if (evt.getPropertyName().equals(PROP_STUN_SERVER_PORT)) {

      // null or empty port is ok since it implies turning STUN off.
      if (evt.getNewValue() == null) return;

      String port = evt.getNewValue().toString();
      if (port.trim().length() == 0) return;

      try {
        Integer.valueOf(evt.getNewValue().toString());
      } catch (NumberFormatException ex) {
        throw new PropertyVetoException(port + " is not a valid port! " + ex.getMessage(), evt);
      }
    }
  }
Beispiel #5
0
 /**
  * ** Returns true if the URL starts with a protocol definition (ie. "http://...") ** @param url
  * The URL to test ** @return True if the URL starts with a protocol definition
  */
 public static boolean isAbsoluteURL(String url) {
   if (url == null) {
     return false;
   } else {
     // per "http://en.wikipedia.org/wiki/URI_scheme" all URL "schemes" contain only
     // alphanumeric or "." characters, and appears to be < 16 characters in length.
     for (int i = 0; (i < 16) && (i < url.length()); i++) {
       char ch = url.charAt(i);
       if (ch == ':') {
         return true; // A colon is the first non-alphanumeric we ran in to
       } else if (!Character.isLetterOrDigit(ch) && (ch != '.')) {
         return false;
       }
     }
     return false;
   }
 }