Package org.apache.oro.text.perl

Examples of org.apache.oro.text.perl.Perl5Util


     * @param user
     *                being validated
     * @return true if the user name is valid.
     */
    protected boolean isValidUser(String user) {
        Perl5Util userMatcher = new Perl5Util();
        return userMatcher.match(USER_PATTERN, user);
    }
View Full Code Here


     */
    protected boolean isValidSymbolicDomain(String domain) {
        String[] domainSegment = new String[10];
        boolean match = true;
        int i = 0;
        Perl5Util atomMatcher = new Perl5Util();
        while (match) {
            match = atomMatcher.match(ATOM_PATTERN, domain);
            if (match) {
                domainSegment[i] = atomMatcher.group(1);
                int l = domainSegment[i].length() + 1;
                domain = (l >= domain.length()) ? "" : domain.substring(l);

                i++;
            }
        }

        int len = i;

        // Make sure there's a host name preceding the domain.
        if (len < 2) {
            return false;
        }

        // TODO: the tld should be checked against some sort of configurable
        // list
        String tld = domainSegment[len - 1];
        if (tld.length() > 1) {
            Perl5Util matchTldPat = new Perl5Util();
            if (!matchTldPat.match(TLD_PATTERN, tld)) {
                return false;
            }
        } else {
            return false;
        }
View Full Code Here

     */
    protected String stripComments(String emailStr) {
        String input = emailStr;
        String result = emailStr;
        String commentPat = "s/^((?:[^\"\\\\]|\\\\.)*(?:\"(?:[^\"\\\\]|\\\\.)*\"(?:[^\"\\\\]|\111111\\\\.)*)*)\\((?:[^()\\\\]|\\\\.)*\\)/$1 /osx";
        Perl5Util commentMatcher = new Perl5Util();
        result = commentMatcher.substitute(commentPat, input);
        // This really needs to be =~ or Perl5Matcher comparison
        while (!result.equals(input)) {
            input = result;
            result = commentMatcher.substitute(commentPat, input);
        }
        return result;

    }
View Full Code Here

    public boolean isValid(String value) {
        if (value == null) {
            return false;
        }

        Perl5Util matchUrlPat = new Perl5Util();
        Perl5Util matchAsciiPat = new Perl5Util();

        if (!matchAsciiPat.match(LEGAL_ASCII_PATTERN, value)) {
            return false;
        }

        // Check the whole url address structure
        if (!matchUrlPat.match(URL_PATTERN, value)) {
View Full Code Here

    protected boolean isValidScheme(String scheme) {
        if (scheme == null) {
            return false;
        }

        Perl5Util schemeMatcher = new Perl5Util();
        if (!schemeMatcher.match(SCHEME_PATTERN, scheme)) {
            return false;
        }

        if (this.options.isOff(ALLOW_ALL_SCHEMES)) {
View Full Code Here

    protected boolean isValidAuthority(String authority) {
        if (authority == null) {
            return false;
        }

        Perl5Util authorityMatcher = new Perl5Util();
        Perl5Util matchIPV4Pat = new Perl5Util();

        if (!authorityMatcher.match(AUTHORITY_PATTERN, authority)) {
            return false;
        }

        boolean ipV4Address = false;
        boolean hostname = false;
        // check if authority is IP address or hostname
        String hostIP = authorityMatcher.group(PARSE_AUTHORITY_HOST_IP);
        ipV4Address = matchIPV4Pat.match(IP_V4_DOMAIN_PATTERN, hostIP);

        if (ipV4Address) {
            // this is an IP address so check components
            for (int i = 1; i <= 4; i++) {
                String ipSegment = matchIPV4Pat.group(i);
                if (ipSegment == null || ipSegment.length() <= 0) {
                    return false;
                }

                try {
                    if (Integer.parseInt(ipSegment) > 255) {
                        return false;
                    }
                } catch (NumberFormatException e) {
                    return false;
                }

            }
        } else {
            // Domain is hostname name
            Perl5Util domainMatcher = new Perl5Util();
            hostname = domainMatcher.match(DOMAIN_PATTERN, hostIP);
        }

        // rightmost hostname will never start with a digit.
        if (hostname) {
            // LOW-TECH FIX FOR VALIDATOR-202
            // TODO: Rewrite to use ArrayList and .add semantics: see
            // VALIDATOR-203
            char[] chars = hostIP.toCharArray();
            int size = 1;
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == '.') {
                    size++;
                }
            }
            String[] domainSegment = new String[size];
            boolean match = true;
            int segmentCount = 0;
            int segmentLength = 0;
            Perl5Util atomMatcher = new Perl5Util();

            while (match) {
                match = atomMatcher.match(ATOM_PATTERN, hostIP);
                if (match) {
                    domainSegment[segmentCount] = atomMatcher.group(1);
                    segmentLength = domainSegment[segmentCount].length() + 1;
                    hostIP = (segmentLength >= hostIP.length()) ? "" : hostIP
                            .substring(segmentLength);

                    segmentCount++;
                }
            }
            String topLevel = domainSegment[segmentCount - 1];
            if (topLevel.length() < 2 || topLevel.length() > 4) {
                return false;
            }

            // First letter of top level must be a alpha
            Perl5Util alphaMatcher = new Perl5Util();
            if (!alphaMatcher.match(ALPHA_PATTERN, topLevel.substring(0, 1))) {
                return false;
            }

            // Make sure there's a host name preceding the authority.
            if (segmentCount < 2) {
                return false;
            }
        }

        if (!hostname && !ipV4Address) {
            return false;
        }

        String port = authorityMatcher.group(PARSE_AUTHORITY_PORT);
        if (port != null) {
            Perl5Util portMatcher = new Perl5Util();
            if (!portMatcher.match(PORT_PATTERN, port)) {
                return false;
            }
        }

        String extra = authorityMatcher.group(PARSE_AUTHORITY_EXTRA);
View Full Code Here

    protected boolean isValidPath(String path) {
        if (path == null) {
            return false;
        }

        Perl5Util pathMatcher = new Perl5Util();

        if (!pathMatcher.match(PATH_PATTERN, path)) {
            return false;
        }

        int slash2Count = countToken("//", path);
        if (this.options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) {
View Full Code Here

    protected boolean isValidQuery(String query) {
        if (query == null) {
            return true;
        }

        Perl5Util queryMatcher = new Perl5Util();
        return queryMatcher.match(QUERY_PATTERN, query);
    }
View Full Code Here

  public static boolean isValidDate(String s, Locale locale) {
    return DateValidator.getInstance().isValid(s, locale);
  }

  public static boolean isValidPassword(String s) {
    return (s == null || s.length() < 8) ? false : (new Perl5Util()).match(PASSWORD_REGEXP, StringUtils.strip(s));
  }
View Full Code Here

        super.setUp();
        outputFactory = getOutputFactory();
        outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.FALSE);
        buffer = new StringWriter();
        writer = new StaxWriter(new QNameMap(), outputFactory.createXMLStreamWriter(buffer));
        perlUtil = new Perl5Util();

        testInput = new X();
        testInput.anInt = 9;
        testInput.aStr = "zzz";
        testInput.innerObj = new Y();
View Full Code Here

TOP

Related Classes of org.apache.oro.text.perl.Perl5Util

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.