ovidiu 02/05/03 17:15:53
Modified: tools/src XConfToolTask.java
Log:
Added the ability to remove elements and add attributes to existing elements.
Revision Changes Path
1.5 +27 -1 xml-cocoon2/tools/src/XConfToolTask.java
Index: XConfToolTask.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/tools/src/XConfToolTask.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XConfToolTask.java 26 Mar 2002 12:43:03 -0000 1.4
+++ XConfToolTask.java 4 May 2002 00:15:53 -0000 1.5
@@ -38,7 +38,8 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Vadim Gritsenko</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
- * @version CVS $Revision: 1.4 $ $Date: 2002/03/26 12:43:03 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Ovidiu Predescu</a>
+ * @version CVS $Revision: 1.5 $ $Date: 2002/05/04 00:15:53 $
*/
public final class XConfToolTask extends Task {
@@ -160,6 +161,31 @@
System.out.println("Skipping: " + file);
return false;
} else {
+ // Test if component wants us to remove a list of nodes first
+ xpath = component.getDocumentElement().getAttribute("remove");
+
+ Node remove = null;
+ if (xpath != null && xpath.length() > 0) {
+ nodes = XPathAPI.selectNodeList(configuration, xpath);
+
+ for (int i = 0, length = nodes.getLength(); i < length; i++) {
+ Node node = nodes.item(i);
+ Node parent = node.getParentNode();
+ parent.removeChild(node);
+ }
+ }
+
+ // Test for an attribute that needs to be added to an element
+ String name =
component.getDocumentElement().getAttribute("add-attribute");
+ String value = component.getDocumentElement().getAttribute("value");
+ if (name != null && name.length() > 0) {
+ if (value == null)
+ throw new IOException("No attribute value specified for
'add-attribute' " + xpath);
+ if (root instanceof Element)
+ ((Element)root).setAttribute(name, value);
+ }
+
+
// Test if 'component' provides desired insertion point
xpath = component.getDocumentElement().getAttribute("insert-before");
Node before = null;
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]