1 | /*
|
---|
2 | * Copyright 2001-2002,2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.types;
|
---|
18 |
|
---|
19 |
|
---|
20 | import java.util.Stack;
|
---|
21 | import org.apache.tools.ant.BuildException;
|
---|
22 | import org.apache.tools.ant.Project;
|
---|
23 |
|
---|
24 | /***
|
---|
25 | * A regular expression substitution datatype. It is an expression
|
---|
26 | * that is meant to replace a regular expression.
|
---|
27 | *
|
---|
28 | * <pre>
|
---|
29 | * <substitition [ [id="id"] expression="expression" | refid="id" ]
|
---|
30 | * />
|
---|
31 | * </pre>
|
---|
32 | *
|
---|
33 | * @see org.apache.oro.text.regex.Perl5Substitution
|
---|
34 | */
|
---|
35 | public class Substitution extends DataType {
|
---|
36 | /** The name of this data type */
|
---|
37 | public static final String DATA_TYPE_NAME = "substitition";
|
---|
38 |
|
---|
39 | private String expression;
|
---|
40 |
|
---|
41 | public Substitution() {
|
---|
42 | this.expression = null;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public void setExpression(String expression) {
|
---|
46 | this.expression = expression;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /***
|
---|
50 | * Gets the pattern string for this RegularExpression in the
|
---|
51 | * given project.
|
---|
52 | */
|
---|
53 | public String getExpression(Project p) {
|
---|
54 | if (isReference()) {
|
---|
55 | return getRef(p).getExpression(p);
|
---|
56 | }
|
---|
57 |
|
---|
58 | return expression;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /***
|
---|
62 | * Get the RegularExpression this reference refers to in
|
---|
63 | * the given project. Check for circular references too
|
---|
64 | */
|
---|
65 | public Substitution getRef(Project p) {
|
---|
66 | if (!isChecked()) {
|
---|
67 | Stack stk = new Stack();
|
---|
68 | stk.push(this);
|
---|
69 | dieOnCircularReference(stk, p);
|
---|
70 | }
|
---|
71 |
|
---|
72 |
|
---|
73 | Object o = getRefid().getReferencedObject(p);
|
---|
74 | if (!(o instanceof Substitution)) {
|
---|
75 | String msg = getRefid().getRefId() + " doesn\'t denote a substitution";
|
---|
76 | throw new BuildException(msg);
|
---|
77 | } else {
|
---|
78 | return (Substitution) o;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|