1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 25 import org.apache.avalon.excalibur.io.FileUtil; 26 import org.apache.lenya.cms.publication.Document; 27 import org.apache.lenya.cms.publication.DocumentBuildException; 28 import org.apache.lenya.cms.publication.DocumentBuilder; 29 import org.apache.lenya.cms.publication.Label; 30 import org.apache.lenya.cms.publication.Publication; 31 import org.apache.lenya.cms.publication.SiteTree; 32 import org.apache.lenya.cms.publication.SiteTreeNode; 33 import org.apache.tools.ant.BuildException; 34 35 39 public class DeleteContentTask extends TwoDocumentsOperationTask { 40 41 44 public DeleteContentTask() { 45 super(); 46 } 47 48 51 public void visitSiteTreeNode(SiteTreeNode node) { 52 Publication publication = getPublication(); 53 DocumentBuilder builder = publication.getDocumentBuilder(); 54 55 String destDocumentid = node.getAbsoluteId(); 56 String srcDocumentid = 57 destDocumentid.replaceFirst( 58 getSecdocumentid(), 59 getFirstdocumentid()); 60 61 Label[] labels = node.getLabels(); 62 for (int i = 0; i < labels.length; i++) { 63 String language = labels[i].getLanguage(); 64 String url = 65 builder.buildCanonicalUrl( 66 publication, 67 getFirstarea(), 68 srcDocumentid, 69 language); 70 Document doc; 71 try { 72 doc = builder.buildDocument(publication, url); 73 } catch (DocumentBuildException e) { 74 throw new BuildException(e); 75 } 76 File srcFile = doc.getFile(); 77 if (!srcFile.exists()) { 78 log("There are no file " + srcFile.getAbsolutePath()); 79 return; 80 } 81 File directory = srcFile.getParentFile(); 82 try { 83 FileUtil.forceDelete(srcFile); 84 } catch (IOException e) { 85 log("exception " + e); 87 } 88 if (directory.exists() 89 && directory.isDirectory() 90 && directory.listFiles().length == 0) { 91 try { 92 FileUtil.forceDelete(directory); 93 } catch (IOException e) { 94 log("exception " + e); 96 } 97 } 98 } 99 100 } 101 102 105 public void execute() throws BuildException { 106 try { 107 log("document-id for the source :" + this.getFirstdocumentid()); 108 log("area for the source :" + this.getFirstarea()); 109 log("document-id for the destination :" + this.getSecdocumentid()); 110 log("area for the destination :" + this.getSecarea()); 111 112 Publication publication = getPublication(); 113 SiteTree tree = publication.getTree(this.getSecarea()); 114 SiteTreeNode node = tree.getNode(this.getSecdocumentid()); 115 node.acceptReverseSubtree(this); 116 } catch (Exception e) { 117 throw new BuildException(e); 118 } 119 } 120 } 121 | Popular Tags |