View Javadoc

1   /*
2    * SmartCrawler
3    *
4    * $Id: AbstractPattern.java,v 1.5 2005/08/05 15:55:53 vincool Exp $
5    * Copyright 2005 Davide Pozza
6    *
7    * This program is free software; you can redistribute it
8    * and/or modify it under the terms of the GNU General Public
9    * License as published by the Free Software Foundation;
10   * either version 2 of the License, or (at your option) any
11   * later version.
12   *
13   * This program is distributed in the hope that it will be
14   *  useful, but WITHOUT ANY WARRANTY; without even the implied
15   *  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16   *  PURPOSE. See the GNU General Public License for more
17   *  details.
18   *
19   * You should have received a copy of the GNU General Public
20   * License along with this program; if not, write to the Free
21   * Software Foundation, Inc., 59 Temple Place, Suite 330,
22   * Boston, MA 02111-1307 USA
23   *
24   */
25  
26  package org.smartcrawler.extractor.pattern;
27  
28  import java.util.regex.Pattern;
29  
30  /***
31   *
32   *
33   * @author <a href="mailto:pozzad@alice.it">Davide Pozza</a>
34   * @version <tt>$Revision: 1.5 $</tt>
35   */
36  public abstract class AbstractPattern {
37  
38      protected Pattern pattern;
39  
40      public AbstractPattern() {
41      }
42  
43      /***
44       *
45       * @return
46       */
47      public Pattern getPattern(){
48          if (pattern == null)
49              pattern = Pattern.compile(getStringPattern(),
50                      Pattern.MULTILINE |
51                      Pattern.CASE_INSENSITIVE |
52                      Pattern.DOTALL);
53          return pattern;
54      }
55      /***
56       *
57       * @return
58       */
59      //public abstract String getStringPattern();
60      protected abstract String getStringPattern();
61  
62      /***
63       *
64       * @return
65       */
66      //public abstract void setStringPattern(String stringPattern);
67      public abstract void setStringPattern(String stringPattern);
68  
69      /***
70       *
71       * @return
72       */
73      public int getGroupAsInt() {
74          try {
75          return Integer.parseInt(getGroup());
76          } catch(Exception e){
77              return -1;
78          }
79      }
80  
81      /***
82       *
83       * @return
84       */
85      public abstract String getGroup();
86      /***
87       *
88       * @param group
89       */
90      public abstract void setGroup(String group);
91  
92  }