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.SiteTreeNode; 29 import org.apache.tools.ant.BuildException; 30 31 34 public class CopyPoliciesTask extends TwoDocumentsOperationTask { 35 private String policiesDir; 36 37 40 public CopyPoliciesTask() { 41 super(); 42 } 43 44 47 public String getPoliciesDir() { 48 return policiesDir; 49 } 50 53 public void setPoliciesDir(String string) { 54 policiesDir = string; 55 } 56 57 63 public File [] getFiles(File directory) { 64 FileFilter filter = new FileFilter () { 65 66 public boolean accept(File file) { 67 return file.isFile(); 68 } 69 }; 70 if (directory.exists() && directory.isDirectory()) { 71 return directory.listFiles(filter); 72 } 73 return null; 74 } 75 76 81 public void copyPolicies(File srcDir, File destDir) { 82 File [] authoringPolicies = this.getFiles(srcDir); 83 if (authoringPolicies == null) { 84 return; 85 } 86 for (int i = 0; i < authoringPolicies.length; i++) { 87 String srcPath; 88 try { 89 srcPath = authoringPolicies[i].getCanonicalPath(); 90 String policyPath = srcPath.substring(srcDir.getCanonicalPath().length()); 91 File destFile = new File (destDir, policyPath); 92 FileUtil.copyFile(authoringPolicies[i], destFile); 93 } catch (IOException e) { 94 throw new BuildException(e); 95 } 96 } 97 } 98 99 102 public void visitSiteTreeNode(SiteTreeNode node) { 103 String srcArea = this.getFirstarea(); 104 String destArea = this.getSecarea(); 105 106 String srcDocumentid = node.getAbsoluteId(); 107 String destDocumentid = 108 srcDocumentid.replaceFirst( 109 getFirstdocumentid(), 110 getSecdocumentid()); 111 112 if (srcArea.equals(Publication.AUTHORING_AREA)) { 113 if (destArea.equals(Publication.AUTHORING_AREA)) { 114 File srcDir = 115 new File ( 116 policiesDir, 117 this.getFirstarea() + File.separator + srcDocumentid); 118 File destDir = 119 new File ( 120 policiesDir, 121 this.getSecarea() + File.separator + destDocumentid); 122 copyPolicies(srcDir, destDir); 123 124 File srcLiveDir = 125 new File ( 126 policiesDir, 127 Publication.LIVE_AREA + File.separator + srcDocumentid); 128 File destLiveDir = 129 new File ( 130 policiesDir, 131 Publication.LIVE_AREA 132 + File.separator 133 + destDocumentid); 134 135 copyPolicies(srcLiveDir, destLiveDir); 136 137 } else if ( 138 destArea.equals(Publication.ARCHIVE_AREA) 139 | destArea.equals(Publication.TRASH_AREA)) { 140 File srcDir = 141 new File ( 142 policiesDir, 143 this.getFirstarea() + File.separator + srcDocumentid); 144 File destDir = 145 new File ( 146 policiesDir, 147 this.getSecarea() 148 + File.separator 149 + this.getFirstarea() 150 + File.separator 151 + destDocumentid); 152 copyPolicies(srcDir, destDir); 153 154 File srcLiveDir = 155 new File ( 156 policiesDir, 157 Publication.LIVE_AREA + File.separator + srcDocumentid); 158 File destLiveDir = 159 new File ( 160 policiesDir, 161 this.getSecarea() 162 + File.separator 163 + Publication.LIVE_AREA 164 + File.separator 165 + destDocumentid); 166 167 copyPolicies(srcLiveDir, destLiveDir); 168 169 } 170 } else if ( 171 srcArea.equals(Publication.ARCHIVE_AREA) 172 | srcArea.equals(Publication.TRASH_AREA)) { 173 if (destArea.equals(Publication.AUTHORING_AREA)) { 174 File srcDir = 175 new File ( 176 policiesDir, 177 this.getFirstarea() 178 + File.separator 179 + this.getSecarea() 180 + File.separator 181 + srcDocumentid); 182 File destDir = 183 new File ( 184 policiesDir, 185 this.getSecarea() + File.separator + destDocumentid); 186 copyPolicies(srcDir, destDir); 187 188 File srcLiveDir = 189 new File ( 190 policiesDir, 191 this.getFirstarea() 192 + File.separator 193 + Publication.LIVE_AREA 194 + File.separator 195 + srcDocumentid); 196 File destLiveDir = 197 new File ( 198 policiesDir, 199 Publication.LIVE_AREA 200 + File.separator 201 + destDocumentid); 202 203 copyPolicies(srcLiveDir, destLiveDir); 204 205 } 206 } 207 } 208 } 209 | Popular Tags |