1 17 18 19 20 package org.apache.lenya.cms.publishing; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.util.StringTokenizer ; 25 26 import org.apache.avalon.framework.parameters.Parameters; 27 import org.apache.lenya.cms.task.ExecutionException; 28 import org.apache.log4j.Category; 29 30 31 42 public class StaticHTMLExporter extends AbstractExporter { 43 private static Category log = Category.getInstance(StaticHTMLExporter.class); 44 public static final String PARAMETER_URIS = "uris"; 45 46 58 public void export(URL serverURI, int serverPort, String publicationPath, String exportPath, 59 String [] uris, String substituteExpression, String substituteReplacement) 60 throws ExportException { 61 try { 62 String exportDirectory = publicationPath + exportPath; 63 64 if (new File (exportPath).isAbsolute()) { 65 exportDirectory = exportPath; 66 } 67 68 log.info(".export(): Export directory: " + exportDirectory + " (" + publicationPath + 69 " , " + exportPath + ")"); 70 71 org.apache.lenya.net.WGet wget = new org.apache.lenya.net.WGet(); 72 wget.setDirectoryPrefix(exportDirectory); 73 74 String fullServerURI = serverURI + ":" + serverPort; 75 76 for (int i = 0; i < uris.length; i++) { 77 URL uri = new URL (fullServerURI + uris[i]); 78 log.info(".export(): Export static HTML: " + uri); 79 80 wget.download(uri, substituteExpression, substituteReplacement); 81 } 82 } catch (Exception e) { 83 throw new ExportException(e); 84 } 85 } 86 87 92 public void execute(String contextPath) throws ExecutionException { 93 try { 94 String publicationId = getParameters().getParameter(PARAMETER_PUBLICATION_ID); 95 96 Parameters taskParameters = new Parameters(); 97 98 PublishingEnvironment environment = new PublishingEnvironment(contextPath, publicationId); 99 100 taskParameters.setParameter(PublishingEnvironment.PARAMETER_EXPORT_PATH, 102 environment.getExportDirectory()); 103 taskParameters.setParameter(PublishingEnvironment.PARAMETER_SUBSTITUTE_REGEXP, 104 environment.getSubstituteExpression()); 105 taskParameters.setParameter(PublishingEnvironment.PARAMETER_SUBSTITUTE_REPLACEMENT, 106 environment.getSubstituteReplacement()); 107 108 taskParameters.merge(getParameters()); 109 parameterize(taskParameters); 110 111 String publicationPath = PublishingEnvironment.getPublicationPath(contextPath, 112 publicationId); 113 114 int serverPort = getParameters().getParameterAsInteger(PARAMETER_SERVER_PORT); 115 log.debug(".execute(): Server Port: " + serverPort); 116 117 String serverURI = getParameters().getParameter(PARAMETER_SERVER_URI); 118 119 String urisString = getParameters().getParameter(PARAMETER_URIS); 120 StringTokenizer st = new StringTokenizer (urisString, ","); 121 String [] uris = new String [st.countTokens()]; 122 int i = 0; 123 124 while (st.hasMoreTokens()) { 125 uris[i++] = st.nextToken(); 126 } 127 128 export(new URL (serverURI), serverPort, publicationPath, 129 getParameters().getParameter(PublishingEnvironment.PARAMETER_EXPORT_PATH), uris, 130 getParameters().getParameter(PublishingEnvironment.PARAMETER_SUBSTITUTE_REGEXP), 131 getParameters().getParameter(PublishingEnvironment.PARAMETER_SUBSTITUTE_REPLACEMENT)); 132 } catch (Exception e) { 133 throw new ExecutionException(e); 134 } 135 } 136 } 137 | Popular Tags |