Changeset 6659
- Timestamp:
- 2004-01-29T14:40:35+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/URLField.java
r6631 r6659 6 6 import javax.swing.event.*; 7 7 import javax.swing.text.*; 8 import org.greenstone.gatherer.Gatherer; 8 9 9 10 public class URLField … … 11 12 implements DocumentListener { 12 13 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]))*)*"); 14 15 15 16 // Crap RegEx that matches everything dammit 16 17 //static final public Pattern URL_PATTERN = Pattern.compile("((.*?)://)?(([^:]*):([^@]*)@)?(([^/:]*)(:[^/]*))?([^\\?#]*/?)?(\\?([^?#]*))?(#(.*))?"); 17 18 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 20 20 //static final public Pattern URL_PATTERN = Pattern.compile("(h|ht|htt|http|http:|http:/|http://|http://)?[\\w]+(\\.[\\w]+)([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?"); 21 21 … … 72 72 73 73 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; 92 91 } 93 92
Note:
See TracChangeset
for help on using the changeset viewer.