[EMAIL PROTECTED] wrote:
Christoper's code required a little work, but here's a method that works, should you choose to add it to the Project class.Ok, that comes from a guy who works more on DOM-Nodes than me (=nothing) :-)
Should we add that to Project class? (If we are allowed to do that)
I now have a Cocoon xpatch task that is successfully replacing properties, which will be extremely helpful to us I think.
Regards, Upayavira
private void replaceProperties(Node n) throws DOMException {
NamedNodeMap attrs = n.getAttributes();
if (attrs!=null) {
for (int i = 0; i< attrs.getLength(); i++) {
Node attr = attrs.item(i);
attr.setNodeValue(getProject().replaceProperties(attr.getNodeValue())); }
}
switch (n.getNodeType()) {
case Node.ATTRIBUTE_NODE:
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE: {
n.setNodeValue(getProject().replaceProperties(n.getNodeValue()));
break;
}
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.ELEMENT_NODE: {
Node child = n.getFirstChild();
while (child != null) {
replaceProperties(child);
child = child.getNextSibling();
}
break;
}
default: {
// ignore all other node types
}
}
}
Jan
-----Original Message----- From: Upayavira [mailto:[EMAIL PROTECTED] Sent: Monday, November 17, 2003 1:02 PM To: Ant Developers List Subject: Re: Property resolution in a task
Christopher Lenz wrote:
It should be much more efficient (and probably simpler) to just traverse the DOM and replace properties in-place:
Splendid! This job gets easier by the moment!
Thanks for that.
Regards, Upayavira
public void replaceProperties(Node n) throws DOMException {n.setValue(getProject().replaceProperties(n.getNodeValue()));
switch (n.getNodeType()) {
case Node.ATTR_NODE:
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE: {
properties asbreak; } case Node.DOCUMENT_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.ELEMENT_NODE: { Node child = n.getFirstChild(); while (child != null) { replaceProperties(child); child = child.getNextSibling(); } break; } default: { // ignore all other node types } } }
[disclaimer: this is all untested code]
-chris
[EMAIL PROTECTED] wrote:
Is there an Ant way to 'spider' a DOM node, replacing
---------------------------------------------------------------------it goes?
I donīt know such a thing. But you can do: - write the DOM to a String - use Project.replace() on that String - parse the String - replace the DOM with new one
Jan
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]