1 17 18 19 20 package org.apache.lenya.cms.ant; 21 22 import java.io.File ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 26 import org.apache.lenya.cms.publishing.ExportException; 27 import org.apache.tools.ant.BuildException; 28 29 30 33 public class StaticHTMLExporter extends PublicationTask { 34 35 public StaticHTMLExporter() { 36 } 37 38 private String serverURL; 39 40 43 protected URL getServer() throws MalformedURLException { 44 return new URL (serverURL); 45 } 46 47 50 public void setServer(String serverURL) { 51 this.serverURL = serverURL; 52 } 53 54 private String path; 55 56 59 protected String getPath() { 60 return path; 61 } 62 63 66 public void setPath(String path) { 67 this.path = path; 68 } 69 70 private String uris; 71 72 75 protected String [] getUris() { 76 return uris.split(","); 77 } 78 79 82 public void setUris(String uris) { 83 this.uris = uris; 84 } 85 86 private String expression; 87 88 91 protected String getExpression() { 92 return expression; 93 } 94 95 98 public void setExpression(String expression) { 99 this.expression = expression; 100 } 101 102 private String replacement; 103 104 107 protected String getReplacement() { 108 return replacement; 109 } 110 111 114 public void setReplacement(String replacement) { 115 this.replacement = replacement; 116 } 117 118 127 public void export(URL serverURI, File publicationDirectory, String exportPath, String [] uris, 128 String substituteExpression, String substituteReplacement) 129 throws ExportException { 130 try { 131 File exportDirectory; 132 133 if (new File (exportPath).isAbsolute()) { 134 exportDirectory = new File (exportPath); 135 } else { 136 exportDirectory = new File (publicationDirectory, exportPath); 137 } 138 139 if (!exportDirectory.exists()) { 140 exportDirectory.mkdirs(); 141 } 142 143 org.apache.lenya.net.WGet wget = new org.apache.lenya.net.WGet(); 144 wget.setDirectoryPrefix(exportDirectory.getAbsolutePath()); 145 146 String fullServerURI = serverURI.toString(); 147 148 for (int i = 0; i < uris.length; i++) { 149 URL uri = new URL (fullServerURI + uris[i]); 150 wget.download(uri, substituteExpression, substituteReplacement); 151 log("Exported URI: " + uri); 152 } 153 } catch (Exception e) { 154 throw new ExportException(e); 155 } 156 } 157 158 161 public void execute() throws BuildException { 162 try { 163 log("Server URL: " + getServer()); 164 log("Publication Directory: " + getPublicationDirectory()); 165 log("Export directory: " + getPath()); 166 log("URIs: " + uris); 167 log("Substitute expression: " + getExpression()); 168 log("Substitute replacement: " + getReplacement()); 169 170 export(getServer(), getPublicationDirectory(), getPath(), getUris(), getExpression(), 171 getReplacement()); 172 } catch (Exception e) { 173 throw new BuildException(e); 174 } 175 } 176 } 177 | Popular Tags |