KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > oro > text > regex > Substitution


1 package org.apache.oro.text.regex;
2
3 /* ====================================================================
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 2000 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Apache" and "Apache Software Foundation", "Jakarta-Oro"
29  * must not be used to endorse or promote products derived from this
30  * software without prior written permission. For written
31  * permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache"
34  * or "Jakarta-Oro", nor may "Apache" or "Jakarta-Oro" appear in their
35  * name, without prior written permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation. For more
53  * information on the Apache Software Foundation, please see
54  * <http://www.apache.org/>.
55  *
56  * Portions of this software are based upon software originally written
57  * by Daniel F. Savarese. We appreciate his contributions.
58  */

59
60 /**
61  * The Substitution interface provides a means for you to control how
62  * a substitution is performed when using the
63  * {@link Util#substitute Util.substitute} method. Two standard
64  * implementations are provided,
65  * {@link StringSubstitution} and {@link Perl5Substitution}. To
66  * achieve custom control over the behavior of substitutions, you can
67  * create your own implementations. A common use for customization is
68  * to make a substitution a function of a match.
69
70  @author <a HREF="dfs@savarese.org">Daniel F. Savarese</a>
71  @version $Id: Substitution.java,v 1.1.1.1 2000/07/23 23:08:54 jon Exp $
72
73  * @see Util
74  * @see Util#substitute
75  * @see StringSubstitution
76  * @see Perl5Substitution
77  */

78 public interface Substitution {
79
80   /**
81    * Appends the substitution to a buffer containing the original input
82    * with substitutions applied for the pattern matches found so far.
83    * For maximum flexibility, the original input as well as the
84    * PatternMatcher and Pattern used to find the match are included as
85    * arguments. However, you will almost never find a need to use those
86    * arguments when creating your own Substitution implementations.
87    * <p>
88    * For performance reasons, rather than provide a getSubstitution method
89    * that returns a String used by Util.substitute, we have opted to pass
90    * a StringBuffer argument from Util.substitute to which the Substitution
91    * must append data. The contract that an appendSubstitution
92    * implementation must abide by is that the appendBuffer may only be
93    * appended to. appendSubstitution() may not alter the appendBuffer in
94    * any way other than appending to it.
95    * <p>
96    * This method is invoked by Util.substitute every time it finds a match.
97    * After finding a match, Util.substitute appends to the appendBuffer
98    * all of the original input occuring between the end of the last match
99    * and the beginning of the current match. Then it invokes
100    * appendSubstitution(), passing the appendBuffer, current match, and
101    * other information as arguments. The substitutionCount keeps track
102    * of how many substitutions have been performed so far by an invocation
103    * of Util.substitute. Its value starts at 1 when the first substitution
104    * is found and appendSubstitution is invoked for the first time. It
105    * will NEVER be zero or a negative value.
106    * <p>
107    * @param appendBuffer The buffer containing the new string resulting
108    * from performing substitutions on the original input.
109    * @param match The current match causing a substitution to be made.
110    * @param substitutionCount The number of substitutions that have been
111    * performed so far by Util.substitute.
112    * @param originalInput The original input upon which the substitutions are
113    * being performed.
114    * @param matcher The PatternMatcher used to find the current match.
115    * @param pattern The Pattern used to find the current match.
116    */

117   public void appendSubstitution(StringBuffer JavaDoc appendBuffer, MatchResult match,
118                  int substitutionCount, String JavaDoc originalInput,
119                  PatternMatcher matcher, Pattern pattern);
120 }
121
Popular Tags