Changeset 6659


Ignore:
Timestamp:
2004-01-29T14:40:35+13:00 (20 years ago)
Author:
jmt12
Message:

Due to popular demand, the URLField now has basic validation again. This means it prevent some perfectly good URLs, but only when mirrorings, my precious.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/URLField.java

    r6631 r6659  
    66import javax.swing.event.*;
    77import javax.swing.text.*;
     8import org.greenstone.gatherer.Gatherer;
    89
    910public class URLField
     
    1112    implements DocumentListener {
    1213
    13     static final public Pattern URL_PATTERN = Pattern.compile("(h|ht|htt|http|http:|http:/|http://|http://)?(([a-zA-Z]([a-zA-Z]|[0-9]|[\\$\\-_\\&\\+]|[!\\*\"\'\\(\\)]|(%[0-9A-Fa-f][0-9A-Fa-f]))*(\\.[a-zA-Z]([a-zA-Z]|[0-9]|[\\$\\-_\\&\\+]|[!\\*\"\'\\(\\)]|(%[0-9A-Fa-f][0-9A-Fa-f]))*)*)|(([0-9])+\\.([0-9])+\\.([0-9])+\\.([0-9])+))(:([0-9])+)?(/([a-zA-Z]|[0-9]|[\\$\\-_\\.\\&\\+]|[!\\*\"\'\\(\\),]|(%[0-9A-Fa-f][0-9A-Fa-f]))*)*");
     14    static final public Pattern URL_PATTERN = Pattern.compile("(h|ht|htt|http|http:|http:/|http://|http://)(([a-zA-Z]([a-zA-Z]|[0-9]|[\\$\\-_\\&\\+]|[!\\*\"\'\\(\\)]|(%[0-9A-Fa-f][0-9A-Fa-f]))*(\\.[a-zA-Z]([a-zA-Z]|[0-9]|[\\$\\-_\\&\\+]|[!\\*\"\'\\(\\)]|(%[0-9A-Fa-f][0-9A-Fa-f]))*)*)|(([0-9])+\\.([0-9])+\\.([0-9])+\\.([0-9])+))(:([0-9])+)?(/([a-zA-Z]|[0-9]|[\\$\\-_\\.\\&\\+]|[!\\*\"\'\\(\\),]|(%[0-9A-Fa-f][0-9A-Fa-f]))*)*");
    1415
    1516    // Crap RegEx that matches everything dammit
    1617    //static final public Pattern URL_PATTERN = Pattern.compile("((.*?)://)?(([^:]*):([^@]*)@)?(([^/:]*)(:[^/]*))?([^\\?#]*/?)?(\\?([^?#]*))?(#(.*))?");
    1718
    18     //static final public Pattern URL_PATTERN = Pattern.compile("(h|ht|htt|http|http:|http:/|http://|http://)?[a-zA-Z0-9-]*(\.[a-zA-Z0-9-])*");
    19 
     19    // Crap RegEx that demands URL starts with www
    2020    //static final public Pattern URL_PATTERN = Pattern.compile("(h|ht|htt|http|http:|http:/|http://|http://)?[\\w]+(\\.[\\w]+)([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?");
    2121
     
    7272
    7373    public boolean validateURL() {
    74     return true;
    75 //      boolean result;
    76 //      String text = getText();
    77 //      Matcher m = URL_PATTERN.matcher(text);
    78 //      if(text.length() == 0 || m.matches()) {
    79 //          setBackground(background);
    80 //          setForeground(foreground);
    81 //          result = true;
    82 //      }
    83 //      else {
    84 //          setBackground(invalid_background);
    85 //          setForeground(invalid_foreground);
    86 //          result = false;
    87 //      }
    88 //      m = null;
    89 //      System.err.println("Validating: " + text + " -> " + (result ? "GOOD" : "BAD"));
    90 //      text = null;
    91 //      return result;
     74    boolean result;
     75    String text = getText();
     76    Matcher m = URL_PATTERN.matcher(text);
     77    if(text.length() == 0 || m.matches()) {
     78        setBackground(background);
     79        setForeground(foreground);
     80        result = true;
     81    }
     82    else {
     83        setBackground(invalid_background);
     84        setForeground(invalid_foreground);
     85        result = false;
     86    }
     87    m = null;
     88    Gatherer.println("Validating: " + text + " -> " + (result ? "GOOD" : "BAD"));
     89    text = null;
     90    return result;
    9291    }
    9392
Note: See TracChangeset for help on using the changeset viewer.