Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/acmsl/regexpplugin/jdk14regexp/MatcherJDKAdapter.java


1   /*
2                   Java Regular Expressions Plugin API.
3   
4       Copyright (C) 2002  Jose San Leandro Armendáriz
5                           jsanleandro@yahoo.es
6                           chousz@yahoo.com
7   
8       This library is free software; you can redistribute it and/or
9       modify it under the terms of the GNU Lesser General Public
10      License as published by the Free Software Foundation; either
11      version 2.1 of the License, or (at your option) any later version.
12  
13      This library is distributed in the hope that it will be useful,
14      but WITHOUT ANY WARRANTY; without even the implied warranty of
15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16      Lesser General Public License for more details.
17  
18      You should have received a copy of the GNU Lesser General Public
19      License along with this library; if not, write to the Free Software
20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  
22      Thanks to ACM S.L. for distributing this library under the LGPL license.
23      Contact info: jsr000@terra.es
24      Postal Address: c/Playa de Lagoa, 1
25                      Urb. Valdecabañas
26                      Boadilla del monte
27                      28660 Madrid
28                      Spain
29  
30      This library uses some external APIs. So far I haven't released such
31      APIs as projects themselves, but you should be able
32      to download them from the web page where you got this source code.
33  
34   ******************************************************************************
35   *
36   * Filename: $RCSfile: MatcherJDKAdapter.java,v $
37   *
38   * Author: Jose San Leandro Armendáriz
39   *
40   * Description: JDK1.4-specific regexp matcher adapter. This class
41   *              makes possible the use of JDK1.4 matchers inside this
42   *              API.
43   *
44   * Last modified by: $Author: dev $ at $Date: 2002/09/27 08:58:38 $
45   *
46   * File version: $Revision: 1.4 $
47   *
48   * Project version: $Name:  $
49   *                  ("Name" means no concrete version has been checked out)
50   *
51   * $Id: MatcherJDKAdapter.java,v 1.4 2002/09/27 08:58:38 dev Exp $
52   *
53   */
54  package org.acmsl.regexpplugin.jdk14regexp;
55  
56  /*
57   * Importing project-specific classes.
58   */
59  import org.acmsl.regexpplugin.MatchResult;
60  import org.acmsl.regexpplugin.jdk14regexp.PatternJDKAdapter;
61  
62  /*
63   * Importing some ACM classes.
64   */
65  import org.acmsl.version.Version;
66  import org.acmsl.version.VersionFactory;
67  
68  /*
69   * Importing JDK1.4 regexp classes.
70   */
71  import java.util.regex.Matcher;
72  import java.util.regex.Pattern;
73  
74  /**
75   * JDK1.4-specific regexp matcher adapter. This class makes possible
76   * the use of JDK1.4 matchers inside this API.
77   * @author <a href="mailto:jsanleandro@yahoo.es"
78             >Jose San Leandro Armendáriz</a>
79   * @version $Revision: 1.4 $
80   */
81  public class MatcherJDKAdapter
82      implements  org.acmsl.regexpplugin.Matcher
83  {
84      /**
85       * Concrete engine implementation.
86       */
87      private Matcher m__Matcher;
88  
89      /**
90       * Constructs a MatcherJDKAdapter.
91       */
92      public MatcherJDKAdapter()  {};
93  
94      /**
95       * Checks if given text contains specified pattern.
96       * @param text the text to analyze.
97       * @param pattern the regular expression to apply.
98       * @return true if the pattern is found.
99       */
100     public boolean contains(
101         String text,
102         org.acmsl.regexpplugin.Pattern pattern)
103     {
104         boolean result = false;
105 
106         if  (   (pattern != null)
107              && (pattern instanceof PatternJDKAdapter))
108         {
109             Pattern t_Pattern =
110                 ((PatternJDKAdapter) pattern).getDelegatedInstance();
111 
112             setDelegatedInstance(t_Pattern.matcher(text));
113 
114             if  (getDelegatedInstance() != null)
115             {
116                 result = getDelegatedInstance().find();
117             }
118         }
119 
120         return result;
121     }
122 
123     /**
124      * Sets the matcher.
125      * @param matcher the new matcher.
126      */
127     protected void setDelegatedInstance(Matcher matcher)
128     {
129         m__Matcher = matcher;
130     }
131 
132     /**
133      * Retrieves an instance of Perl5Matcher class.
134      * @return a the adapted matcher.
135      */
136     protected Matcher getDelegatedInstance()
137     {
138         return m__Matcher;
139     }
140 
141     /**
142      * Retrieves the last match found due to a previous call to
143      * <i>contains</i> method.
144      * @return such match result.
145      */
146     public MatchResult getMatch()
147     {
148         return new MatchResultJDKAdapter(getDelegatedInstance());
149     }
150 
151     /*
152      * Concrete version object updated everytime it's checked-in in a CVS
153      * repository.
154      */
155     public static final Version VERSION =
156         VersionFactory.createVersion("$Revision: 1.4 $");
157 
158     /**
159      * Retrieves the current version of this object.
160      * @return the version object with such information.
161      */
162     public Version getVersion()
163     {
164         return VERSION;
165     }
166 
167     /**
168      * Retrieves the current version of this class.
169      * @return the object with class version information.
170      */
171     public static Version getClassVersion()
172     {
173         return VERSION;
174     }
175 }