View Javadoc

1   package fr.in2p3.jsaga.engine.session;
2   
3   import java.util.regex.Pattern;
4   
5   /* ***************************************************
6    * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
7    * ***             http://cc.in2p3.fr/             ***
8    * ***************************************************
9    * File:   BaseUrlPattern
10   * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
11   * ***************************************************
12   * Description:                                      */
13  
14  /**
15   *
16   */
17  public class BaseUrlPattern {
18      private BaseUrlItem[] m_items;
19  
20      public BaseUrlPattern(BaseUrlItem... items) {
21          m_items = items;
22      }
23  
24      public BaseUrlItem[] getItems() {
25          return m_items;
26      }
27  
28      public String toString() {
29          StringBuffer buffer = new StringBuffer();
30          for (BaseUrlItem item : m_items) {
31              buffer.append(item.toString());
32          }
33          return buffer.toString();
34      }
35  
36      // accessible to friends for testing purpose
37      Pattern toRegExp() {
38          StringBuffer buffer = new StringBuffer();
39          String nextRegExp = "";
40          for (BaseUrlItem item : m_items) {
41              buffer.append(item.toRegExp());
42              nextRegExp = item.getNextRegExp();
43          }
44          buffer.append(nextRegExp);
45          return Pattern.compile(buffer.toString());
46      }
47  
48      public boolean matches(String url) {
49          Pattern regexp = this.toRegExp();
50          return regexp.matcher(url).matches();
51      }
52  
53      public boolean conflictsWith(BaseUrlPattern ref) {
54          for (int i=0; i<m_items.length && i<ref.getItems().length; i++) {
55              if (! m_items[i].conflictsWith(ref.getItems()[i])) {
56                  return false;
57              }
58          }
59          return true;
60      }
61  }