| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 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 |
} |