Subversion Repositories eFlore/Applications.coel

Rev

Rev 542 | Rev 744 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
542 jp_milcent 1
package org.tela_botanica.client.util;
2
 
3
public class Pattern {
728 jp_milcent 4
 
5
	public static final String url =  "^(?:(?:ht|f)tp(?:s?)\\:\\/\\/|~/|/)?"+ // Protocol
6
		"(?:\\w+:\\w+@)?"+ // Username:Password
7
		"(?:(?:[-\\w]+\\.)+"+ // Subdomains
8
		"(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))"+ // TopLevel Domains
9
		"(?::[\\d]{1,5})?"+ // Port
10
		"(?:(?:(?:/(?:[-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|/)+|\\?|#)?"+ // Directories
11
		"(?:(?:\\?(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)(?:&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*"+ // Query
12
		"(?:#(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?$"; // Anchor
13
 
14
	public static final String email = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*"+ // Identité
15
		"@"+ // At
16
		"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";// Domaine
17
 
542 jp_milcent 18
	/**
19
	 * Méthode similaire à la méthode : java.util.Pattern.quote().
20
	 * java.util.Pattern n'est pas implémenté par GWT.
21
	 *
22
	 * @link http://java.developpez.com/faq/java/?page=langage_chaine
23
	 * @param s
24
	 * @return
25
	 */
26
	public static String quote(String s) {
27
		int slashEIndex = s.indexOf("\\E");
28
		if (slashEIndex == -1)
29
			return "\\Q" + s + "\\E";
30
 
31
		StringBuffer sb = new StringBuffer(s.length() * 2);
32
		sb.append("\\Q");
33
		slashEIndex = 0;
34
		int current = 0;
35
		while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
36
			sb.append(s.substring(current, slashEIndex));
37
			current = slashEIndex + 2;
38
			sb.append("\\E\\\\E\\Q");
39
		}
40
		sb.append(s.substring(current, s.length()));
41
		sb.append("\\E");
42
		return sb.toString();
43
	}
44
}