1 22 23 package org.meshcms.extra; 24 25 import java.io.*; 26 import org.meshcms.core.*; 27 import org.meshcms.util.*; 28 29 34 public class StaticExportCleaner extends DirectoryParser { 35 File contextRoot; 36 Writer writer; 37 private Path protectedPath; 38 39 42 public StaticExportCleaner(File contextRoot) { 43 super(); 44 this.contextRoot = contextRoot; 45 setRecursive(true); 46 } 47 48 51 public void setWriter(Writer writer) { 52 this.writer = writer; 53 } 54 55 58 public Writer getWriter() { 59 return writer; 60 } 61 62 protected boolean preProcess() { 63 return contextRoot != null && contextRoot.exists(); 64 } 65 66 protected boolean preProcessDirectory(File file, Path path) { 67 return !path.equals(protectedPath); 68 } 69 70 protected void postProcessDirectory(File file, Path path) { 71 if (file.delete()) { 72 write("empty " + path + " directory deleted"); 73 } 74 } 75 76 protected void processFile(File file, Path path) { 77 if (!path.getFile(contextRoot).exists() || 78 file.getName().equals(WebSite.CMS_ID_FILE) || 79 file.getName().equals(WebSite.ADMIN_ID_FILE)) { 80 if (file.delete()) { 81 write(path + " file deleted"); 82 } 83 } 84 } 85 86 void write(String message) { 87 if (writer != null) { 88 try { 89 writer.write(message); 90 writer.write('\n'); 91 writer.flush(); 92 } catch (IOException ex) {} 93 } 94 } 95 96 public Path getProtectedPath() { 97 return protectedPath; 98 } 99 100 public void setProtectedPath(Path protectedPath) { 101 this.protectedPath = protectedPath; 102 } 103 } 104 | Popular Tags |