View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  package org.apache.james.jspf.core;
21  
22  /**
23   * This constants are used by Terms to define their matching rules.
24   */
25  public interface SPFTermsRegexps {
26      
27  
28      final String ALPHA_PATTERN = "[a-zA-Z]";
29  
30      final String MACRO_LETTER_PATTERN_EXP = "[rctlsodipvhRCTLSODIPVH]";
31  
32      final String MACRO_LETTER_PATTERN = "[lsodipvhLSODIPVH]";
33  
34      final String TRANSFORMERS_REGEX = "\\d*[r]?";
35  
36      final String DELEMITER_REGEX = "[\\.\\-\\+,/_\\=]";
37  
38      final String MACRO_LETTERS_REGEX = MACRO_LETTER_PATTERN_EXP + TRANSFORMERS_REGEX + DELEMITER_REGEX + "*";
39  
40      final String MACRO_EXPAND_REGEX = "\\%(?:\\{"
41              + MACRO_LETTERS_REGEX + "\\}|\\%|\\_|\\-)";
42  
43      final String MACRO_LITERAL_REGEX = "[\\x21-\\x24\\x26-\\x7e]";
44  
45      /**
46       * This is used by the MacroExpander
47       */
48      final String MACRO_STRING_REGEX_TOKEN = MACRO_EXPAND_REGEX
49      + "|" + MACRO_LITERAL_REGEX + "{1}";
50  
51  
52      /**
53       * ABNF: macro-string = *( macro-expand / macro-literal )
54       */
55      final String MACRO_STRING_REGEX = "(?:" + MACRO_STRING_REGEX_TOKEN +")*";
56  
57      final String ALPHA_DIGIT_PATTERN = "[a-zA-Z0-9]";
58  
59      /**
60       * ABNF: toplabel = ( *alphanum ALPHA *alphanum ) / ( 1*alphanum "-" *(
61       * alphanum / "-" ) alphanum ) ; LDH rule plus additional TLD restrictions ;
62       * (see [RFC3696], Section 2)
63       */
64      final String TOP_LABEL_REGEX = "(?:"
65              + ALPHA_DIGIT_PATTERN + "*" + SPFTermsRegexps.ALPHA_PATTERN
66              + "{1}" + ALPHA_DIGIT_PATTERN + "*|(?:"
67              + ALPHA_DIGIT_PATTERN + "+" + "\\-" + "(?:"
68              + ALPHA_DIGIT_PATTERN + "|\\-)*"
69              + ALPHA_DIGIT_PATTERN + "))";
70  
71      /**
72       * ABNF: domain-end = ( "." toplabel [ "." ] ) / macro-expand
73       */
74      final String DOMAIN_END_REGEX = "(?:\\." + TOP_LABEL_REGEX
75              + "\\.?" + "|" + SPFTermsRegexps.MACRO_EXPAND_REGEX + ")";
76  
77      /**
78       * ABNF: domain-spec = macro-string domain-end
79       */
80      final String DOMAIN_SPEC_REGEX = "("
81              + SPFTermsRegexps.MACRO_STRING_REGEX + DOMAIN_END_REGEX + ")";
82  
83      /**
84       * Spring MACRO_STRING from DOMAIN_END (domain end starts with .)
85       */
86      final String DOMAIN_SPEC_REGEX_R = "("
87              + SPFTermsRegexps.MACRO_STRING_REGEX + ")(" + DOMAIN_END_REGEX + ")";
88  
89  
90  }