1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import java.io.File ; 23 import java.io.FileFilter ; 24 import java.io.IOException ; 25 26 import org.apache.avalon.excalibur.io.FileUtil; 27 import org.apache.lenya.cms.publication.Publication; 28 import org.apache.lenya.cms.publication.SiteTree; 29 import org.apache.lenya.cms.publication.SiteTreeNode; 30 import org.apache.tools.ant.BuildException; 31 32 36 public class DeletePoliciesTask extends TwoDocumentsOperationTask { 37 private String policiesDir; 38 39 42 public DeletePoliciesTask() { 43 super(); 44 } 45 46 49 public String getPoliciesDir() { 50 return policiesDir; 51 } 52 55 public void setPoliciesDir(String string) { 56 policiesDir = string; 57 } 58 59 65 public File [] getFiles(File directory) { 66 FileFilter filter = new FileFilter () { 67 68 public boolean accept(File file) { 69 return file.isFile(); 70 } 71 }; 72 if (directory.exists() && directory.isDirectory()) { 73 return directory.listFiles(filter); 74 } 75 return null; 76 } 77 78 82 public void deletePolicies(File srcDir) { 83 File [] authoringPolicies = this.getFiles(srcDir); 84 if (authoringPolicies == null) { 85 log("no policies file to delete"); 86 return; 87 } 88 for (int i = 0; i < authoringPolicies.length; i++) { 89 try { 90 FileUtil.forceDelete(authoringPolicies[i]); 91 } catch (IOException e) { 92 log("exception " +e); 94 } 95 96 } 97 if (srcDir.exists() && srcDir.isDirectory() && srcDir.listFiles().length == 0) { 98 try { 99 FileUtil.forceDelete(srcDir); 100 } catch (IOException e) { 101 log("exception " +e); 103 } 104 } 105 } 106 107 110 public void visitSiteTreeNode(SiteTreeNode node) { 111 String srcArea = this.getFirstarea(); 112 String destArea = this.getSecarea(); 113 114 String destDocumentid = node.getAbsoluteId(); 115 String srcDocumentid = 116 destDocumentid.replaceFirst( 117 getSecdocumentid(), 118 getFirstdocumentid()); 119 120 try { 121 if (srcArea.equals(Publication.AUTHORING_AREA)) { 122 if (destArea.equals(Publication.AUTHORING_AREA)) { 123 File srcDir = 124 new File ( 125 policiesDir, 126 this.getFirstarea() 127 + File.separator 128 + srcDocumentid); 129 log("delete :" + srcDir.getCanonicalPath()); 130 deletePolicies(srcDir); 131 File srcLiveDir = 132 new File ( 133 policiesDir, 134 Publication.LIVE_AREA 135 + File.separator 136 + srcDocumentid); 137 log("delete :" + srcLiveDir.getCanonicalPath()); 138 deletePolicies(srcLiveDir); 139 140 } else if ( 141 destArea.equals(Publication.ARCHIVE_AREA) 142 | destArea.equals(Publication.TRASH_AREA)) { 143 File srcDir = 144 new File ( 145 policiesDir, 146 this.getFirstarea() 147 + File.separator 148 + srcDocumentid); 149 log("delete :" + srcDir.getCanonicalPath()); 150 deletePolicies(srcDir); 151 152 File srcLiveDir = 153 new File ( 154 policiesDir, 155 Publication.LIVE_AREA 156 + File.separator 157 + srcDocumentid); 158 log("delete :" + srcLiveDir.getCanonicalPath()); 159 deletePolicies(srcLiveDir); 160 } 161 } else if ( 162 srcArea.equals(Publication.ARCHIVE_AREA) 163 | srcArea.equals(Publication.TRASH_AREA)) { 164 if (destArea.equals(Publication.AUTHORING_AREA)) { 165 File srcDir = 166 new File ( 167 policiesDir, 168 this.getFirstarea() 169 + File.separator 170 + this.getSecarea() 171 + File.separator 172 + srcDocumentid); 173 log("delete :" + srcDir.getCanonicalPath()); 174 deletePolicies(srcDir); 175 176 File srcLiveDir = 177 new File ( 178 policiesDir, 179 this.getFirstarea() 180 + File.separator 181 + Publication.LIVE_AREA 182 + File.separator 183 + srcDocumentid); 184 log("delete :" + srcLiveDir.getCanonicalPath()); 185 deletePolicies(srcLiveDir); 186 } 187 } 188 } catch (IOException e) { 189 throw new BuildException(e); 190 } 191 } 192 193 196 public void execute() throws BuildException { 197 try { 198 log("document-id for the source :" + this.getFirstdocumentid()); 199 log("area for the source :" + this.getFirstarea()); 200 log("document-id for the destination :" + this.getSecdocumentid()); 201 log("area for the destination :" + this.getSecarea()); 202 203 Publication publication = getPublication(); 204 SiteTree tree = publication.getTree(this.getSecarea()); 205 SiteTreeNode node = tree.getNode(this.getSecdocumentid()); 206 node.acceptReverseSubtree(this); 207 } catch (Exception e) { 208 throw new BuildException(e); 209 } 210 } 211 } 212 | Popular Tags |