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: AwkMatcherOROAdapter.java,v $
37 *
38 * Author: Jose San Leandro Armend?riz
39 *
40 * Description: Jakarta ORO-specific regexp compiler adapter. This class makes
41 * possible the use of ORO compilers inside this API. A delegation
42 * is used because Perl5Compiler is a final class.
43 *
44 * Last modified by: $Author: chous $ at $Date: 2003/06/21 21:07:25 $
45 *
46 * File version: $Revision: 1.6 $
47 *
48 * Project version: $Name: $
49 * ("Name" means no concrete version has been checked out)
50 *
51 * $Id: AwkMatcherOROAdapter.java,v 1.6 2003/06/21 21:07:25 chous Exp $
52 *
53 */
54 package org.acmsl.regexpplugin.jakartaoro;
55
56 /*
57 * Importing project-specific classes.
58 */
59 import org.acmsl.regexpplugin.jakartaoro.PatternOROAdapter;
60 import org.acmsl.regexpplugin.Matcher;
61 import org.acmsl.regexpplugin.MatchResult;
62 import org.acmsl.regexpplugin.Pattern;
63
64 /*
65 * Importing some ACM classes.
66 */
67 import org.acmsl.version.Version;
68 import org.acmsl.version.VersionFactory;
69
70 /*
71 * Importing ORO classes.
72 */
73 import org.apache.oro.text.awk.AwkMatcher;
74
75 /***
76 * Jakarta ORO-specific regexp compiler adapter. This class makes possible the
77 * use of ORO compilers inside this API. A delegation is used because
78 * Perl5Compiler is a final class.
79 * @author <a href="mailto:jsanleandro@yahoo.es"
80 >Jose San Leandro Armend?riz</a>
81 * @version $Revision: 1.6 $
82 */
83 public class AwkMatcherOROAdapter
84 implements Matcher
85 {
86 /***
87 * Delegated instance.
88 */
89 private AwkMatcher m__Instance;
90
91 /***
92 * Constructs an AwkMatcherOROAdapter for given object.
93 * @param adaptee the instance to be adapted.
94 */
95 public AwkMatcherOROAdapter()
96 {
97 setAdaptee(new AwkMatcher());
98 }
99
100 /***
101 * Checks if given text contains specified pattern.
102 * @param text the text to analyze.
103 * @param pattern the regular expression to apply.
104 * @return true if the pattern is found.
105 */
106 public boolean contains(String text, Pattern pattern)
107 {
108 boolean result = false;
109
110 if ( (pattern != null)
111 && (pattern instanceof PatternOROAdapter))
112 {
113 System.out.println(((PatternOROAdapter) pattern).getDelegatedInstance());
114
115 result =
116 getDelegatedInstance().contains(
117 text,
118 ((PatternOROAdapter) pattern).getDelegatedInstance());
119 }
120
121 return result;
122 }
123
124 /***
125 * Retrieves the last match found due to a previous call to
126 * <i>contains</i> method.
127 * @return such match result.
128 */
129 public MatchResult getMatch()
130 {
131 MatchResult result = null;
132
133 if (getDelegatedInstance() != null)
134 {
135 result =
136 new MatchResultOROAdapter(getDelegatedInstance().getMatch());
137 }
138
139 return result;
140 }
141
142 /***
143 * Sets the adaptee.
144 * @param adaptee the instance to adapt.
145 */
146 protected void setAdaptee(AwkMatcher adaptee)
147 {
148 m__Instance = adaptee;
149 }
150
151 /***
152 * Retrieves an instance of AwkMatcher class.
153 * @return a the adapted matcher.
154 */
155 protected AwkMatcher getDelegatedInstance()
156 {
157 return m__Instance;
158 }
159
160 /***
161 * Concrete version object updated everytime it's checked-in in a CVS
162 * repository.
163 */
164 public static final Version VERSION =
165 VersionFactory.createVersion("$Revision: 1.6 $");
166
167 /***
168 * Retrieves the current version of this object.
169 * @return the version object with such information.
170 */
171 public Version getVersion()
172 {
173 return VERSION;
174 }
175
176 /***
177 * Retrieves the current version of this class.
178 * @return the object with class version information.
179 */
180 public static Version getClassVersion()
181 {
182 return VERSION;
183 }
184 }
This page was automatically generated by Maven