01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.tools.ant.types;
19:
20: import org.apache.tools.ant.Project;
21:
22: /***
23: * A regular expression substitution datatype. It is an expression
24: * that is meant to replace a regular expression.
25: *
26: * <pre>
27: * <substitition [ [id="id"] expression="expression" | refid="id" ]
28: * />
29: * </pre>
30: *
31: * @see org.apache.oro.text.regex.Perl5Substitution
32: */
33: public class Substitution extends DataType {
34: /** The name of this data type */
35: public static final String DATA_TYPE_NAME = "substitition";
36:
37: private String expression;
38:
39: /** Constructor for Substitution. */
40: public Substitution() {
41: this .expression = null;
42: }
43:
44: /**
45: * Set the pattern string for this regular expression substitution.
46: * @param expression the regular expression to use
47: */
48: public void setExpression(String expression) {
49: this .expression = expression;
50: }
51:
52: /***
53: * Gets the pattern string for this RegularExpression in the
54: * given project.
55: * @param p the project to look for the regular expression if this object is
56: * a reference
57: * @return the pattern string
58: */
59: public String getExpression(Project p) {
60: if (isReference()) {
61: return getRef(p).getExpression(p);
62: }
63:
64: return expression;
65: }
66:
67: /***
68: * Get the RegularExpression this reference refers to in
69: * the given project. Check for circular references too.
70: * @param p the project to look for the regular expression reference
71: * @return the resolved reference
72: */
73: public Substitution getRef(Project p) {
74: return (Substitution) getCheckedRef(p);
75: }
76: }
|