1 17 18 19 20 package org.apache.lenya.cms.rc; 21 22 import java.io.File ; 23 import java.util.HashMap ; 24 import java.util.Map ; 25 26 import org.apache.avalon.framework.configuration.Configurable; 27 import org.apache.avalon.framework.configuration.Configuration; 28 import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; 29 import org.apache.log4j.Category; 30 31 public class RCEnvironment implements Configurable { 32 private static Category log = Category.getInstance(RCEnvironment.class); 33 public static final String CONFIGURATION_FILE = "lenya" + File.separator + "config" + 34 File.separator + "rc" + File.separator + "revision-controller.xconf"; 35 public static final String RCML_DIRECTORY = "rcml-directory"; 36 public static final String BACKUP_DIRECTORY = "backup-directory"; 37 private String rcmlDirectory; 38 private String backupDirectory; 39 40 private static Map instances = new HashMap (); 41 42 47 public static RCEnvironment getInstance(String contextPath) { 48 RCEnvironment instance = (RCEnvironment) instances.get(contextPath); 49 if (instance == null) { 50 instance = new RCEnvironment(contextPath); 51 instances.put(contextPath, instance); 52 } 53 return instance; 54 } 55 56 61 public RCEnvironment(String contextPath) { 62 log.debug("context path:" + contextPath); 63 64 String configurationFilePath = contextPath + "/" + CONFIGURATION_FILE; 65 log.debug("configuration file path:" + configurationFilePath); 66 67 File configurationFile = new File (configurationFilePath); 68 69 try { 70 DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); 71 Configuration configuration = builder.buildFromFile(configurationFile); 72 configure(configuration); 73 } catch (Exception e) { 74 log.error("Cannot load revision controller configuration! ", e); 75 } 76 } 77 78 85 public void configure(org.apache.avalon.framework.configuration.Configuration configuration) 86 throws org.apache.avalon.framework.configuration.ConfigurationException { 87 setRCMLDirectory(configuration.getChild("rcmlDirectory").getAttribute("href")); 89 setBackupDirectory(configuration.getChild("backupDirectory").getAttribute("href")); 90 91 log.debug("CONFIGURATION:\nRCML Directory: HREF=" + getRCMLDirectory()); 92 log.debug("CONFIGURATION:\nBackup Directory: HREF=" + getBackupDirectory()); 93 } 94 95 100 public String getRCMLDirectory() { 101 return rcmlDirectory; 102 } 103 104 109 protected void setRCMLDirectory(String rcmlDir) { 110 rcmlDirectory = rcmlDir; 111 } 112 113 118 public String getBackupDirectory() { 119 return backupDirectory; 120 } 121 122 127 protected void setBackupDirectory(String backupDir) { 128 backupDirectory = backupDir; 129 } 130 } 131 | Popular Tags |