Permalink
Browse files

Support recursive option correctly on pxf:delete

  • Loading branch information...
ndw committed Jan 28, 2012
1 parent 687e5af commit 62b7b1e1d445432be07e57247a9ac8bacff397be
Showing with 16 additions and 3 deletions.
  1. +16 −3 src/com/xmlcalabash/extensions/fileutils/Delete.java
@@ -23,6 +23,7 @@
*/
public class Delete extends DefaultStep {
private static final QName _href = new QName("href");
+ private static final QName _recursive = new QName("recursive");
private WritablePipe result = null;
@@ -48,6 +49,8 @@ public void run() throws SaxonApiException {
throw XProcException.dynamicError(21);
}
+ boolean recursive = getOption(_recursive, false);
+
RuntimeValue href = getOption(_href);
URI uri = href.getBaseURI().resolve(href.getString());
File file;
@@ -68,13 +71,23 @@ public void run() throws SaxonApiException {
tree.addText(file.toURI().toASCIIString());
- if (!file.delete()) {
- throw new XProcException(step.getNode(), "Delete failed for: " + file.getAbsolutePath());
- }
+ performDelete(file, recursive);
tree.addEndElement();
tree.endDocument();
result.write(tree.getResult());
}
+
+ private void performDelete(File file, boolean recursive) {
+ if (recursive && file.isDirectory()) {
+ for (File f : file.listFiles()) {
+ performDelete(f, recursive);
+ }
+ }
+
+ if (!file.delete()) {
+ throw new XProcException(step.getNode(), "Delete failed for: " + file.getAbsolutePath());
+ }
+ }
}

0 comments on commit 62b7b1e

Please sign in to comment.