View Javadoc
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: MatcherRegexpAdapter.java,v $ 37 * 38 * Author: Jose San Leandro Armend?riz 39 * 40 * Description: Represents the result of match in a regexp parsing 41 * process using Jakarta Regexp package. 42 * 43 * Last modified by: $Author: dev $ at $Date: 2002/09/27 08:27:17 $ 44 * 45 * File version: $Revision: 1.5 $ 46 * 47 * Project version: $Name: $ 48 * ("Name" means no concrete version has been checked out) 49 * 50 * $Id: MatcherRegexpAdapter.java,v 1.5 2002/09/27 08:27:17 dev Exp $ 51 * 52 */ 53 package org.acmsl.regexpplugin.jakartaregexp; 54 55 /* 56 * Importing some project-specific classes. 57 */ 58 import org.acmsl.regexpplugin.Matcher; 59 import org.acmsl.regexpplugin.MatchResult; 60 import org.acmsl.regexpplugin.Pattern; 61 62 /* 63 * Importing some ACM classes. 64 */ 65 import org.acmsl.version.Version; 66 import org.acmsl.version.VersionFactory; 67 68 /* 69 * Importing some Jakarta Regexp classes. 70 */ 71 import org.apache.regexp.RE; 72 import org.apache.regexp.REProgram; 73 74 /*** 75 * Represents the result of match in a regexp parsing process using 76 * Jakarta Regexp package. 77 * @author <a href="mailto:jsanleandro@yahoo.es" 78 >Jose San Leandro Armend?riz</a> 79 * @version $Revision: 1.5 $ 80 */ 81 public class MatcherRegexpAdapter 82 implements Matcher 83 { 84 /*** 85 * Private RE reference. 86 */ 87 private RE m__RE; 88 89 /*** 90 * Constructs an empty REMatcherRegexpAdapter. 91 */ 92 public MatcherRegexpAdapter() {}; 93 94 /*** 95 * Sets the instance to adapt. 96 * @param adaptee the re object to adapt. 97 */ 98 protected void setAdaptee(RE adaptee) 99 { 100 m__RE = adaptee; 101 } 102 103 /*** 104 * Retrieves the adapted instance. 105 * @return the RE object. 106 */ 107 public RE getAdaptee() 108 { 109 return m__RE; 110 } 111 112 /*** 113 * Checks if given text contains specified pattern. 114 * @param text the text to analyze. 115 * @param pattern the regular expression to apply. 116 * @return true if the pattern is found. 117 */ 118 public boolean contains(String text, Pattern pattern) 119 { 120 boolean result = false; 121 122 if ( (pattern != null) 123 && (pattern instanceof PatternRegexpAdapter)) 124 { 125 PatternRegexpAdapter t_PatternAdapter = 126 (PatternRegexpAdapter) pattern; 127 128 setAdaptee(t_PatternAdapter.getRE()); 129 130 if (getAdaptee() != null) 131 { 132 result = getAdaptee().match(text); 133 } 134 } 135 136 return result; 137 } 138 139 /*** 140 * Retrieves the last match found due to a previous call to 141 * <i>contains</i> method. 142 * @return such match result. 143 */ 144 public MatchResult getMatch() 145 { 146 MatchResult result = null; 147 148 if (getAdaptee() != null) 149 { 150 result = new MatchResultRegexpAdapter(getAdaptee()); 151 } 152 153 return result; 154 } 155 156 /*** 157 * Concrete version object updated everytime it's checked-in in a CVS 158 * repository. 159 */ 160 public static final Version VERSION = 161 VersionFactory.createVersion("$Revision: 1.5 $"); 162 163 /*** 164 * Retrieves the current version of this object. 165 * @return the version object with such information. 166 */ 167 public Version getVersion() 168 { 169 return VERSION; 170 } 171 172 /*** 173 * Retrieves the current version of this class. 174 * @return the object with class version information. 175 */ 176 public static Version getClassVersion() 177 { 178 return VERSION; 179 } 180 }

This page was automatically generated by Maven