1 13 package info.magnolia.cms.beans.config; 14 15 import info.magnolia.cms.core.Path; 16 import info.magnolia.cms.core.SystemProperty; 17 import info.magnolia.cms.i18n.MessagesManager; 18 import info.magnolia.cms.license.LicenseFileExtractor; 19 import info.magnolia.cms.module.ModuleFactory; 20 import info.magnolia.cms.security.SecureURI; 21 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 import javax.jcr.RepositoryException; 26 import javax.servlet.ServletContext ; 27 28 import org.apache.commons.lang.StringUtils; 29 import org.apache.log4j.Logger; 30 31 32 37 public class ConfigLoader { 38 39 42 protected static Logger log = Logger.getLogger(ConfigLoader.class); 43 44 47 private static boolean configured; 48 49 52 private static boolean bootstrapping; 53 54 61 public ConfigLoader(ServletContext context, Map config) { 62 63 String rootDir = context.getRealPath(StringUtils.EMPTY); 64 65 if (log.isInfoEnabled()) { 66 log.info("Assuming paths relative to " + rootDir); } 68 SystemProperty.setProperty(SystemProperty.MAGNOLIA_APP_ROOTDIR, rootDir); 69 70 Iterator it = config.entrySet().iterator(); 71 while (it.hasNext()) { 72 Map.Entry param = (Map.Entry ) it.next(); 73 SystemProperty.setProperty((String ) param.getKey(), (String ) param.getValue()); 74 } 75 76 if (StringUtils.isEmpty(System.getProperty("java.security.auth.login.config"))) { System.setProperty("java.security.auth.login.config", Path .getAbsoluteFileSystemPath("WEB-INF/config/jaas.config")); } 80 else { 81 if (log.isInfoEnabled()) { 82 log.info("JAAS config file set by parent container or some other application"); log.info("Config in use " + System.getProperty("java.security.auth.login.config")); log 85 .info("Please make sure JAAS config has all necessary modules (refer config/jaas.config) configured"); } 87 } 88 89 this.load(context); 90 } 91 92 96 private void load(ServletContext context) { 97 LicenseFileExtractor license = LicenseFileExtractor.getInstance(); 99 license.init(); 100 printVersionInfo(license); 101 102 log.info("Init content repositories"); ContentRepository.init(); 104 105 boolean initialized = false; 107 108 try { 109 initialized = ContentRepository.checkIfInitialized(); 110 } 111 catch (RepositoryException re) { 112 log.fatal("Unable to initialize repositories. Magnolia can't start.", re); return; 114 } 115 116 if (initialized) { 117 log.info("Repositories are initialized (some content found). Loading configuration"); } 119 else { 120 log.warn("Repositories are not initialized (no content found)."); 122 String bootdir = SystemProperty.getProperty(SystemProperty.MAGNOLIA_BOOTSTRAP_ROOTDIR); 123 if (StringUtils.isEmpty(bootdir)) { 124 enterListeningMode(); 125 return; 126 } 127 128 bootstrapping = true; 129 130 Bootstrapper.bootstrapRepositories(Path.getAbsoluteFileSystemPath(bootdir)); 132 } 133 134 log.info("Init virtualMap"); VirtualMap.init(); 136 log.info("Init i18n"); MessagesManager.init(context); 138 log.info("Init secureURI"); SecureURI.init(); 140 141 try { 142 Server.init(); 143 ModuleFactory.init(); 144 ModuleLoader.init(); 145 Listener.init(); 146 Subscriber.init(); 147 Cache.init(); 148 MIMEMapping.init(); 149 setConfigured(true); 150 log.info("Configuration loaded!"); } 152 catch (ConfigurationException e) { 153 log.info("An error occurred during initialization, incomplete configuration found?"); enterListeningMode(); 155 return; 156 } 157 158 } 159 160 164 private void printVersionInfo(LicenseFileExtractor license) { 165 System.out.println("---------------------------------------------"); System.out.println("MAGNOLIA LICENSE"); System.out.println("---------------------------------------------"); System.out.println("Version number : " + license.get(LicenseFileExtractor.VERSION_NUMBER)); System.out.println("Build : " + license.get(LicenseFileExtractor.BUILD_NUMBER)); System.out.println("Provider : " + license.get(LicenseFileExtractor.PROVIDER) + " (" + license.get(LicenseFileExtractor.PRIVIDER_EMAIL) + ")"); } 174 175 179 public static boolean isConfigured() { 180 return ConfigLoader.configured; 181 } 182 183 188 public static boolean isBootstrapping() { 189 return bootstrapping; 190 } 191 192 196 protected static void setConfigured(boolean configured) { 197 ConfigLoader.configured = configured; 198 199 ConfigLoader.bootstrapping = false; 201 } 202 203 206 private void enterListeningMode() { 207 System.out.println("\n-----------------------------------------------------------------"); System.out.println("Server not configured, entering in listening mode for activation."); System.out.println("You can now activate content from an existing magnolia instance."); System.out.println("-----------------------------------------------------------------\n"); setConfigured(false); 212 } 213 214 } 215 | Popular Tags |