Subversion Repositories eFlore/Applications.coel

Rev

Rev 728 | Rev 885 | 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.
744 jpm 21
	 * Nous protégeons les caractères spéciaux.
542 jp_milcent 22
	 *
23
	 * @link http://java.developpez.com/faq/java/?page=langage_chaine
744 jpm 24
	 * @param chaine
542 jp_milcent 25
	 * @return
26
	 */
744 jpm 27
	public static String quote(String chaine) {
28
		chaine.replace("\\", "\\\\");
29
 
30
		String[] caracteresSpeciaux = {".", "$", "[", "]", "(", ")", "{", "}", "^", "?", "*", "+", "-"};
31
		for (int i = 0; i < caracteresSpeciaux.length; i++) {
32
			chaine = chaine.replace(caracteresSpeciaux[i], "\\"+caracteresSpeciaux[i]);
542 jp_milcent 33
		}
744 jpm 34
		return chaine;
542 jp_milcent 35
	}
36
}