1 17 18 19 20 package org.apache.lenya.cms.publishing; 21 22 import java.io.File ; 23 import java.io.FileNotFoundException ; 24 import java.io.IOException ; 25 import java.util.StringTokenizer ; 26 27 import org.apache.avalon.framework.parameters.Parameters; 28 import org.apache.lenya.cms.task.ExecutionException; 29 import org.apache.log4j.Category; 30 31 32 49 public class DefaultFilePublisher extends AbstractFilePublisher { 50 private static Category log = Category.getInstance(DefaultFilePublisher.class); 51 public static final String PARAMETER_SOURCES = "sources"; 52 53 69 public void publish(String publicationPath, String authoringPath, String treeAuthoringPath, 70 String resourcesAuthoringPath, String livePath, String treeLivePath, 71 String resourcesLivePath, String replicationPath, String [] sources) 72 throws PublishingException { 73 log.debug("PUBLICATION: " + publicationPath); 74 log.debug("CONFIGURATION:\nauthoring path=" + authoringPath + "\nlive path=" + livePath); 75 76 String absoluteAuthoringPath = publicationPath + authoringPath; 78 String absoluteTreeAuthoringPath = publicationPath + treeAuthoringPath; 79 String absoluteLivePath = publicationPath + livePath; 80 String absoluteTreeLivePath = publicationPath + treeLivePath; 81 String absoluteReplicationPath = publicationPath + replicationPath; 82 83 log.debug("DefaultFilePublisher.publish() has been called."); 84 85 for (int index = 0; index < sources.length; index++) { 86 File sourceFile = new File (absoluteAuthoringPath + sources[index]); 87 File destinationFile = new File (absoluteLivePath + sources[index]); 88 File destinationReplicationFile = new File (absoluteReplicationPath + sources[index]); 89 90 try { 91 copyFile(sourceFile, destinationFile); 92 log.debug("Document published: " + sourceFile + " " + destinationFile); 93 copyFile(sourceFile, destinationReplicationFile); 94 log.debug("Document ready for replication: " + sourceFile + " " + 95 destinationReplicationFile); 96 } catch (FileNotFoundException fnfe) { 97 throw new PublishingException("Document not published: Source file (" + sourceFile + 98 ") not found!", fnfe); 99 } catch (IOException ioe) { 100 throw new PublishingException("Document not published: " + sourceFile + " " + 101 destinationFile, ioe); 102 } 103 } 104 105 publishResources(publicationPath, resourcesAuthoringPath, resourcesLivePath, sources); 107 108 try { 110 copyFile(new File (absoluteTreeAuthoringPath), new File (absoluteTreeLivePath)); 111 log.debug("COPY\ntree source=" + absoluteTreeAuthoringPath + "\ntree destination=" + 112 absoluteTreeLivePath); 113 log.debug("Tree published"); 114 } catch (IOException ioe) { 115 throw new PublishingException("Tree not published: " + absoluteTreeAuthoringPath + " " + 116 absoluteTreeLivePath, ioe); 117 } 118 } 119 120 127 public void execute(String contextPath) throws ExecutionException { 128 log.debug(".execute(): Context Path: " + contextPath); 129 130 try { 131 String publicationId = getParameters().getParameter(PARAMETER_PUBLICATION_ID); 132 133 Parameters taskParameters = new Parameters(); 134 135 PublishingEnvironment environment = new PublishingEnvironment(contextPath, publicationId); 136 137 taskParameters.setParameter(PublishingEnvironment.PARAMETER_AUTHORING_PATH, 139 environment.getAuthoringPath()); 140 taskParameters.setParameter(PublishingEnvironment.PARAMETER_TREE_AUTHORING_PATH, 141 environment.getTreeAuthoringPath()); 142 taskParameters.setParameter(PublishingEnvironment.PARAMETER_LIVE_PATH, 143 environment.getLivePath()); 144 taskParameters.setParameter(PublishingEnvironment.PARAMETER_TREE_LIVE_PATH, 145 environment.getTreeLivePath()); 146 147 taskParameters.setParameter(PublishingEnvironment.PARAMETER_REPLICATION_PATH, 148 environment.getReplicationDirectory()); 149 150 taskParameters.merge(getParameters()); 151 parameterize(taskParameters); 152 153 String sourcesString = getParameters().getParameter(PARAMETER_SOURCES); 154 StringTokenizer st = new StringTokenizer (sourcesString, ","); 155 String [] sources = new String [st.countTokens()]; 156 int i = 0; 157 158 while (st.hasMoreTokens()) { 159 sources[i++] = st.nextToken(); 160 } 161 162 publish(PublishingEnvironment.getPublicationPath(contextPath, publicationId), 163 getParameters().getParameter(PublishingEnvironment.PARAMETER_AUTHORING_PATH), 164 getParameters().getParameter(PublishingEnvironment.PARAMETER_TREE_AUTHORING_PATH), 165 null, getParameters().getParameter(PublishingEnvironment.PARAMETER_LIVE_PATH), 166 getParameters().getParameter(PublishingEnvironment.PARAMETER_TREE_LIVE_PATH), null, 167 getParameters().getParameter(PublishingEnvironment.PARAMETER_REPLICATION_PATH), 168 sources); 169 } catch (Exception e) { 170 throw new ExecutionException(e); 171 } 172 } 173 174 187 protected void publishResources(String publicationPath, String resourcesAuthoringPath, 188 String resourcesLivePath, String [] sources) throws PublishingException { 189 } 190 } 191 | Popular Tags |