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 StaticExportCopier extends DirectoryParser { 35 File destinationRoot; 36 private boolean checkDates; 37 private boolean mkDirs; 38 Writer writer; 39 40 43 public StaticExportCopier(File destinationRoot) { 44 super(); 45 this.destinationRoot = destinationRoot; 46 setRecursive(true); 47 } 48 49 52 public void setWriter(Writer writer) { 53 this.writer = writer; 54 } 55 56 59 public Writer getWriter() { 60 return writer; 61 } 62 63 protected boolean preProcessDirectory(File file, Path path) { 64 File destDir = path.getFile(destinationRoot); 65 66 if (mkDirs) { 67 destDir.mkdirs(); 68 } 69 70 return destDir.isDirectory(); 71 } 72 73 protected void processFile(File file, Path path) { 74 if (!(FileTypes.isPage(file.getName()) || 75 file.getName().equals(WebSite.CMS_ID_FILE) || 76 file.getName().equals(WebSite.ADMIN_ID_FILE))) { 77 File copy = path.getFile(destinationRoot); 78 79 if (!(checkDates && copy.exists() && 80 file.lastModified() <= copy.lastModified())) { 81 try { 82 Utils.copyFile(file, copy, true, false); 83 write(path + " file copied"); 84 } catch (IOException ex) { 85 ex.printStackTrace(); 86 } 87 } 88 } 89 } 90 91 void write(String message) { 92 if (writer != null) { 93 try { 94 writer.write(message); 95 writer.write('\n'); 96 writer.flush(); 97 } catch (IOException ex) {} 98 } 99 } 100 101 public boolean isCheckDates() { 102 return checkDates; 103 } 104 105 public void setCheckDates(boolean checkDates) { 106 this.checkDates = checkDates; 107 } 108 109 public boolean isMkDirs() { 110 return mkDirs; 111 } 112 113 public void setMkDirs(boolean mkDirs) { 114 this.mkDirs = mkDirs; 115 } 116 } 117 | Popular Tags |