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.excalibur.io.FileUtil; 28 import org.apache.avalon.framework.parameters.Parameters; 29 import org.apache.lenya.cms.task.ExecutionException; 30 import org.apache.log4j.Category; 31 32 33 50 public class ResourceFilePublisher extends DefaultFilePublisher { 51 private static Category log = Category.getInstance(ResourceFilePublisher.class); 52 53 57 protected void publishResources(String publicationPath, String resourcesAuthoringPath, 58 String resourcesLivePath, String [] sources) throws PublishingException { 59 String absoluteResourceAuthoringPath = publicationPath + resourcesAuthoringPath; 60 String absoluteResourceLivePath = publicationPath + resourcesLivePath; 61 62 log.debug("Publishing resources from " + absoluteResourceAuthoringPath + " to " + 63 absoluteResourceLivePath); 64 65 for (int index = 0; index < sources.length; index++) { 66 File sourceDir = new File (absoluteResourceAuthoringPath + 67 FileUtil.getPath(sources[index])); 68 File destinationDir = new File (absoluteResourceLivePath + 69 FileUtil.getPath(sources[index])); 70 71 if (!sourceDir.isDirectory()) { 72 continue; 76 } 77 78 log.debug("Copying resources from " + sourceDir + " to " + destinationDir); 79 80 File [] resourceSources = sourceDir.listFiles(); 81 82 for (int j = 0; j < resourceSources.length; j++) { 83 if (resourceSources[j].isFile()) { 84 try { 85 FileUtil.copyFileToDirectory(resourceSources[j], destinationDir); 87 log.debug("COPY\nresource: " + resourceSources[j] + "\nto " + 88 destinationDir); 89 } catch (FileNotFoundException fnfe) { 90 throw new PublishingException("Resource not published: Source file (" + 91 resourceSources[j] + ") not found!", fnfe); 92 } catch (IllegalArgumentException iae) { 93 throw new PublishingException( 94 "Resource not published: Live resources path (" + destinationDir + 95 ") is not a directory "); 96 } catch (IOException ioe) { 97 throw new PublishingException("Resource not published: " + 98 resourceSources[j] + " " + destinationDir, ioe); 99 } 100 } 101 } 102 } 103 } 104 105 112 public void execute(String contextPath) throws ExecutionException { 113 try { 114 String publicationId = getParameters().getParameter(PARAMETER_PUBLICATION_ID); 115 116 Parameters taskParameters = new Parameters(); 117 118 ResourcePublishingEnvironment environment = new ResourcePublishingEnvironment(contextPath, 119 publicationId); 120 121 taskParameters.setParameter(PublishingEnvironment.PARAMETER_AUTHORING_PATH, 123 environment.getAuthoringPath()); 124 taskParameters.setParameter(PublishingEnvironment.PARAMETER_TREE_AUTHORING_PATH, 125 environment.getTreeAuthoringPath()); 126 taskParameters.setParameter(ResourcePublishingEnvironment.PARAMETER_RESOURCE_AUTHORING_PATH, 127 environment.getResourceAuthoringPath()); 128 taskParameters.setParameter(PublishingEnvironment.PARAMETER_LIVE_PATH, 129 environment.getLivePath()); 130 taskParameters.setParameter(PublishingEnvironment.PARAMETER_TREE_LIVE_PATH, 131 environment.getTreeLivePath()); 132 taskParameters.setParameter(ResourcePublishingEnvironment.PARAMETER_RESOURCE_LIVE_PATH, 133 environment.getResourceLivePath()); 134 135 taskParameters.setParameter(PublishingEnvironment.PARAMETER_REPLICATION_PATH, 136 environment.getReplicationDirectory()); 137 138 taskParameters.merge(getParameters()); 139 parameterize(taskParameters); 140 141 String sourcesString = getParameters().getParameter(PARAMETER_SOURCES); 142 StringTokenizer st = new StringTokenizer (sourcesString, ","); 143 String [] sources = new String [st.countTokens()]; 144 int i = 0; 145 146 while (st.hasMoreTokens()) { 147 sources[i++] = st.nextToken(); 148 } 149 150 publish(PublishingEnvironment.getPublicationPath(contextPath, publicationId), 151 getParameters().getParameter(PublishingEnvironment.PARAMETER_AUTHORING_PATH), 152 getParameters().getParameter(PublishingEnvironment.PARAMETER_TREE_AUTHORING_PATH), 153 getParameters().getParameter(ResourcePublishingEnvironment.PARAMETER_RESOURCE_AUTHORING_PATH), 154 getParameters().getParameter(PublishingEnvironment.PARAMETER_LIVE_PATH), 155 getParameters().getParameter(PublishingEnvironment.PARAMETER_TREE_LIVE_PATH), 156 getParameters().getParameter(ResourcePublishingEnvironment.PARAMETER_RESOURCE_LIVE_PATH), 157 getParameters().getParameter(PublishingEnvironment.PARAMETER_REPLICATION_PATH), 158 sources); 159 } catch (Exception e) { 160 throw new ExecutionException(e); 161 } 162 } 163 } 164 | Popular Tags |