Subversion Repositories eFlore/Applications.coel

Rev

Rev 888 | Rev 1111 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.util;

public class Pattern {
        
        public static final String url =  "^(?:(?:ht|f)tp(?:s?)\\:\\/\\/|~/|/)?"+ // Protocol
                "(?:\\w+:\\w+@)?"+ // Username:Password
                "(?:(?:[-\\w]+\\.)+"+ // Subdomains 
                "(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))"+ // TopLevel Domains
                "(?::[\\d]{1,5})?"+ // Port
                "(?:(?:(?:/(?:[-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|/)+|\\?|#)?"+ // Directories
                "(?:(?:\\?(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)(?:&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*"+ // Query
                "(?:#(?:[-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?$"; // Anchor
        
        public static final String email = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*"+ // Identité
                "@"+ // At
                "(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";// Domaine
        
        public static final String heureMinute = "^((([0-1][0-9])|(2[0-4])):(([0-5][0-9])|(60)))$";
        
        /**
         * Méthode similaire à la méthode : java.util.Pattern.quote().
         * java.util.Pattern n'est pas implémenté par GWT.
         * Nous protégeons les caractères spéciaux.
         * 
         * @link http://java.developpez.com/faq/java/?page=langage_chaine
         * @param chaine
         * @return
         */
        public static String quote(String chaine) {
                chaine.replace("\\", "\\\\");
                
                String[] caracteresSpeciaux = {".", "$", "[", "]", "(", ")", "{", "}", "^", "?", "*", "+", "-", "|"};
                for (int i = 0; i < caracteresSpeciaux.length; i++) {
                        chaine = chaine.replace(caracteresSpeciaux[i], "\\"+caracteresSpeciaux[i]);
                }
                return chaine;
        }
}