Debian Codegraph @

src/main/java/net/sf/antcontrib/property/URLEncodeTask.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
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 package net.sf.antcontrib.property;
17
18 import java.io.File;
19 import java.net.URLEncoder;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.types.Reference;
24
25
26 /****************************************************************************
27 * Place class description here.
28 *
29 * @author <a href='mailto:[email protected]'>Matthew Inger</a>
30 * @author <additional author>
31 *
32 * @since
33 *
34 ****************************************************************************/
35
36
37 public class URLEncodeTask
38 extends AbstractPropertySetterTask
39 {
40 private String value;
41 private Reference ref;
42
43 public void setName(String name)
44 {
45 setProperty(name);
46 }
47
48
49 public void setValue(String value)
50 {
51 this.value = URLEncoder.encode(value);
52 }
53
54 public String getValue(Project p)
55 {
56 String val = value;
57
58 if (ref != null)
59 val = ref.getReferencedObject(p).toString();
60
61 return val;
62 }
63
64 public void setLocation(File location) {
65 setValue(location.getAbsolutePath());
66 }
67
68 public void setRefid(Reference ref) {
69 this.ref = ref;
70 }
71
72 public String toString() {
73 return value == null ? "" : value;
74 }
75
76 protected void validate()
77 {
78 super.validate();
79 if (value == null && ref == null)
80 {
81 throw new BuildException("You must specify value, location or "
82 + "refid with the name attribute",
83 getLocation());
84 }
85 }
86
87 public void execute()
88 {
89 validate();
90 String val = getValue(getProject());
91 setPropertyValue(val);
92 }
93
94 }