1 17 18 19 20 package org.apache.lenya.cms.publishing; 21 22 import java.io.File ; 23 24 import org.apache.avalon.framework.configuration.Configurable; 25 import org.apache.avalon.framework.configuration.Configuration; 26 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; 27 import org.apache.log4j.Category; 28 29 30 public class PublishingEnvironment implements Configurable { 31 private static Category log = Category.getInstance(PublishingEnvironment.class); 32 public static final String CONFIGURATION_FILE = "config" + File.separator + "publishing" + 33 File.separator + "publisher.xconf"; 34 public static final String PUBLICATION_PREFIX = "lenya" + File.separator + "pubs" + 35 File.separator; 36 public static final String PUBLICATION_PATH = "publication-path"; 37 public static final String PARAMETER_AUTHORING_PATH = "authoring-path"; 38 public static final String PARAMETER_TREE_AUTHORING_PATH = "tree-authoring-path"; 39 public static final String PARAMETER_LIVE_PATH = "live-path"; 40 public static final String PARAMETER_TREE_LIVE_PATH = "tree-live-path"; 41 public static final String PARAMETER_REPLICATION_PATH = "replication-path"; 42 public static final String PARAMETER_EXPORT_PATH = "export-path"; 43 public static final String PARAMETER_SUBSTITUTE_REGEXP = "substitute-regexp"; 44 public static final String PARAMETER_SUBSTITUTE_REPLACEMENT = "substitute-replacement"; 45 private String publicationPath; 46 private String replicationDirectory; 47 private String authoringPath; 48 private String livePath; 49 private String treeAuthoringPath; 50 private String treeLivePath; 51 private String exportDirectory; 52 private String substituteExpression; 53 private String substituteReplacement; 54 55 61 public PublishingEnvironment(String contextPath, String publicationId) { 62 this(PublishingEnvironment.getPublicationPath(contextPath, publicationId)); 63 log.debug("Context Path and Publication Id: " + contextPath + "::" + publicationId); 64 } 65 66 71 public PublishingEnvironment(String publicationPath) { 72 setPublicationPath(publicationPath); 73 74 String configurationFilePath = publicationPath + CONFIGURATION_FILE; 75 76 File configurationFile = new File (configurationFilePath); 77 78 try { 79 DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); 80 Configuration configuration = builder.buildFromFile(configurationFile); 81 configure(configuration); 82 } catch (Exception e) { 83 log.info( 84 "Did not load publishing configuration from publisher.xconf (No such file or directory: " + configurationFile + "). " + 85 "That means you can't access all PublishingEnvironment parameters and you should only " + 86 "use the AntTask. But don't panic, this file has been DEPRECATED."); 87 } 88 } 89 90 97 public void configure(org.apache.avalon.framework.configuration.Configuration configuration) 98 throws org.apache.avalon.framework.configuration.ConfigurationException { 99 setAuthoringPath(configuration.getChild("authoring").getChild("documents").getAttribute("href")); 101 setTreeAuthoringPath(configuration.getChild("authoring").getChild("tree").getAttribute("href")); 102 103 setReplicationDirectory(configuration.getChild("replication").getChild("pending-documents") 105 .getAttribute("href")); 106 107 setLivePath(configuration.getChild("live").getChild("documents").getAttribute("href")); 109 setTreeLivePath(configuration.getChild("live").getChild("tree").getAttribute("href")); 110 111 setExportDirectory(configuration.getChild("export").getChild("destination").getAttribute("href")); 113 setSubstituteExpression(configuration.getChild("export").getChild("substitution") 114 .getAttribute("regexp")); 115 setSubstituteReplacementExpression(configuration.getChild("export").getChild("substitution") 116 .getAttribute("replacement")); 117 118 log.debug("CONFIGURATION:\nauthoring path=" + getAuthoringPath() + "\nlive path=" + 119 getLivePath()); 120 log.debug("CONFIGURATION:\ntree authoring path=" + getTreeAuthoringPath() + 121 "\ntree live path=" + getTreeLivePath()); 122 123 log.debug("CONFIGURATION:\nDirectory Prefix: HREF=" + getExportDirectory()); 124 log.debug("CONFIGURATION:\nPrefix Substitute: HREF=" + getSubstituteExpression()); 125 126 log.debug("CONFIGURATION:\nReplication Directory: HREF=" + getReplicationDirectory()); 127 } 128 129 134 public String getPublicationPath() { 135 return publicationPath; 136 } 137 138 141 public File getPublicationDirectory() { 142 return new File (getPublicationPath()); 143 } 144 145 protected void setPublicationPath(String path) { 146 publicationPath = path; 147 } 148 149 154 public String getAuthoringPath() { 155 return authoringPath; 156 } 157 158 protected void setAuthoringPath(String path) { 159 authoringPath = path; 160 } 161 162 167 public String getLivePath() { 168 return livePath; 169 } 170 171 protected void setLivePath(String path) { 172 livePath = path; 173 } 174 175 180 public String getTreeAuthoringPath() { 181 return treeAuthoringPath; 182 } 183 184 protected void setTreeAuthoringPath(String path) { 185 treeAuthoringPath = path; 186 } 187 188 193 public String getTreeLivePath() { 194 return treeLivePath; 195 } 196 197 protected void setTreeLivePath(String path) { 198 treeLivePath = path; 199 } 200 201 206 public String getReplicationDirectory() { 207 return replicationDirectory; 208 } 209 210 protected void setReplicationDirectory(String directory) { 211 replicationDirectory = directory; 212 } 213 214 219 public String getExportDirectory() { 220 return exportDirectory; 221 } 222 223 protected void setExportDirectory(String directory) { 224 exportDirectory = directory; 225 } 226 227 232 public String getSubstituteExpression() { 233 return substituteExpression; 234 } 235 236 protected void setSubstituteExpression(String substitute) { 237 substituteExpression = substitute; 238 } 239 240 243 protected void setSubstituteReplacementExpression(String replacement) { 244 substituteReplacement = replacement; 245 } 246 247 252 public String getSubstituteReplacement() { 253 return substituteReplacement; 254 } 255 256 264 public static String getPublicationPath(String servletContextPath, String publicationId) { 265 if (!servletContextPath.endsWith(File.separator)) { 266 servletContextPath += File.separator; 267 } 268 269 return servletContextPath + PUBLICATION_PREFIX + publicationId + File.separator; 270 } 271 } 272 | Popular Tags |