git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275308 13f79535-47bb-0310-9956-ffa450edef68master
@@ -38,17 +38,6 @@ | |||||
</td> | </td> | ||||
<td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
</tr> | </tr> | ||||
<tr> | |||||
<td valign="top">attributestyle</td> | |||||
<td valign="top"> | |||||
<em>Temporary</em> | |||||
this attribute specifies if the attribute is in ant style | |||||
(i.e. ${attributeName}) or xpath style (i.e @attributeName). | |||||
Valid values are "ant" and "xpath". The default value | |||||
is "ant". | |||||
</td> | |||||
<td valign="top" align="center">No</td> | |||||
</tr> | |||||
</table> | </table> | ||||
<h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
<h4>attribute</h4> | <h4>attribute</h4> | ||||
@@ -63,11 +52,6 @@ | |||||
task using the ant property notation - ${attribute name}. | task using the ant property notation - ${attribute name}. | ||||
Note that is not an actual ant property. | Note that is not an actual ant property. | ||||
</p> | </p> | ||||
<p> | |||||
If the attribute style is set to "xpath", the attribute is | |||||
specified in the body of the template task by prefixing the | |||||
name with a "@". | |||||
</p> | |||||
<h3>Parameters</h3> | <h3>Parameters</h3> | ||||
<table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
<tr> | <tr> | ||||
@@ -140,23 +124,6 @@ | |||||
</testing> | </testing> | ||||
</pre> | </pre> | ||||
</blockquote> | </blockquote> | ||||
<p> | |||||
The following fragment sets the attribute style to "xpath" | |||||
for the macro definition <testing> and calls the | |||||
macro. The fragment should output "attribute is this is a test". | |||||
</p> | |||||
<blockquote> | |||||
<pre> | |||||
<macrodef name="testing" attributestyle="xpath"> | |||||
<attribute name="abc"/> | |||||
<sequential> | |||||
<echo>attribute is @abc</echo> | |||||
</sequential> | |||||
</macrodef> | |||||
<testing abc="this is a test"/> | |||||
</pre> | |||||
</blockquote> | |||||
<p> | <p> | ||||
The following fragment defines a task called <call-cc> which | The following fragment defines a task called <call-cc> which | ||||
take the attributes "target", "link" and "target.dir" and the | take the attributes "target", "link" and "target.dir" and the | ||||
@@ -45,14 +45,4 @@ | |||||
</nested> | </nested> | ||||
</target> | </target> | ||||
<target name="xpathstyle"> | |||||
<macrodef name="testing" attributestyle="xpath"> | |||||
<attribute name="abc"/> | |||||
<sequential> | |||||
<echo>attribute is @abc@abc</echo> | |||||
</sequential> | |||||
</macrodef> | |||||
<testing abc="this is a test"/> | |||||
</target> | |||||
</project> | </project> |
@@ -81,7 +81,6 @@ public class MacroDef extends AntlibDefinition implements TaskContainer { | |||||
private String name; | private String name; | ||||
private List attributes = new ArrayList(); | private List attributes = new ArrayList(); | ||||
private Map elements = new HashMap(); | private Map elements = new HashMap(); | ||||
private int attributeStyle = AttributeStyle.ANT; | |||||
/** | /** | ||||
* Name of the definition | * Name of the definition | ||||
@@ -91,46 +90,6 @@ public class MacroDef extends AntlibDefinition implements TaskContainer { | |||||
this.name = name; | this.name = name; | ||||
} | } | ||||
/** | |||||
* Enumerated type for attributeStyle attribute | |||||
* | |||||
* @see EnumeratedAttribute | |||||
*/ | |||||
public static class AttributeStyle extends EnumeratedAttribute { | |||||
/** Enumerated values */ | |||||
public static final int ANT = 0, XPATH = 1; | |||||
/** | |||||
* get the values | |||||
* @return an array of the allowed values for this attribute. | |||||
*/ | |||||
public String[] getValues() { | |||||
return new String[] {"ant", "xpath"}; | |||||
} | |||||
} | |||||
/** | |||||
* <em>Experimental</em> | |||||
* I am uncertain at the moment how to encode attributes | |||||
* using ant style ${attribute} or xpath style @attribute. | |||||
* The first may get mixed up with ant properties and | |||||
* the second may get mixed up with xpath. | |||||
* The default at the moment is ant s | |||||
* | |||||
* @param style an <code>AttributeStyle</code> value | |||||
*/ | |||||
public void setAttributeStyle(AttributeStyle style) { | |||||
attributeStyle = style.getIndex(); | |||||
} | |||||
/** | |||||
* <em>Experimental</em> | |||||
* @return the attribute style | |||||
*/ | |||||
public int getAttributeStyle() { | |||||
return attributeStyle; | |||||
} | |||||
/** | /** | ||||
* Set the class loader. | * Set the class loader. | ||||
* Not used | * Not used | ||||
@@ -435,9 +394,6 @@ public class MacroDef extends AntlibDefinition implements TaskContainer { | |||||
} | } | ||||
} | } | ||||
if (attributeStyle != other.attributeStyle) { | |||||
return false; | |||||
} | |||||
if (!nestedTask.similar(other.nestedTask)) { | if (!nestedTask.similar(other.nestedTask)) { | ||||
return false; | return false; | ||||
} | } | ||||
@@ -146,7 +146,7 @@ public class MacroInstance extends Task implements DynamicConfigurator { | |||||
} | } | ||||
} | } | ||||
private String macroSubsAnt(String s, Map macroMapping) { | |||||
private String macroSubs(String s, Map macroMapping) { | |||||
StringBuffer ret = new StringBuffer(); | StringBuffer ret = new StringBuffer(); | ||||
StringBuffer macroName = new StringBuffer(); | StringBuffer macroName = new StringBuffer(); | ||||
boolean inMacro = false; | boolean inMacro = false; | ||||
@@ -179,59 +179,6 @@ public class MacroInstance extends Task implements DynamicConfigurator { | |||||
return ret.toString(); | return ret.toString(); | ||||
} | } | ||||
private String macroSubsXPath(String s, Map macroMapping) { | |||||
StringBuffer ret = new StringBuffer(); | |||||
StringBuffer macroName = new StringBuffer(); | |||||
boolean inMacro = false; | |||||
for (int i = 0; i < s.length(); ++i) { | |||||
char c = s.charAt(i); | |||||
if (!inMacro) { | |||||
if (c == '@') { | |||||
inMacro = true; | |||||
} else { | |||||
ret.append(c); | |||||
} | |||||
} else { | |||||
if (MacroDef.isValidNameCharacter(c)) { | |||||
macroName.append(c); | |||||
} else { | |||||
inMacro = false; | |||||
String name = macroName.toString(); | |||||
String value = (String) macroMapping.get(name); | |||||
if (value == null) { | |||||
ret.append("@" + name); | |||||
} else { | |||||
ret.append(value); | |||||
} | |||||
if (c == '@') { | |||||
inMacro = true; | |||||
} else { | |||||
ret.append(c); | |||||
} | |||||
macroName = new StringBuffer(); | |||||
} | |||||
} | |||||
} | |||||
if (inMacro) { | |||||
String name = macroName.toString(); | |||||
String value = (String) macroMapping.get(name); | |||||
if (value == null) { | |||||
ret.append("@" + name); | |||||
} else { | |||||
ret.append(value); | |||||
} | |||||
} | |||||
return ret.toString(); | |||||
} | |||||
private String macroSubs(String s, Map macroMapping) { | |||||
if (macroDef.getAttributeStyle() == MacroDef.AttributeStyle.ANT) { | |||||
return macroSubsAnt(s, macroMapping); | |||||
} else { | |||||
return macroSubsXPath(s, macroMapping); | |||||
} | |||||
} | |||||
private UnknownElement copy(UnknownElement ue) { | private UnknownElement copy(UnknownElement ue) { | ||||
UnknownElement ret = new UnknownElement(ue.getTag()); | UnknownElement ret = new UnknownElement(ue.getTag()); | ||||
ret.setNamespace(ue.getNamespace()); | ret.setNamespace(ue.getNamespace()); | ||||
@@ -86,8 +86,5 @@ public class MacroDefTest extends BuildFileTest { | |||||
expectLog("nested", "A nested element"); | expectLog("nested", "A nested element"); | ||||
} | } | ||||
public void testXPathStyle() { | |||||
expectLog("xpathstyle", "attribute is this is a testthis is a test"); | |||||
} | |||||
} | } | ||||