1 64 65 package com.jcorporate.expresso.core.misc; 66 67 68 71 public class SystemMacros { 72 73 private static SystemMacros theInstance = new SystemMacros(); 74 private String webAppDir = ""; 75 private String contextPath = ""; 76 private String expressoDir = "expresso"; 77 private String serverPrefix = ""; 78 79 protected SystemMacros() { 80 } 81 82 public static synchronized SystemMacros getInstance() { 83 return theInstance; 84 } 85 86 public void setWebAppDir(String newDir) { 87 StringUtil.assertNotBlank(newDir, 88 "A blank or null directory is not allowed here"); 89 webAppDir = newDir.replace('\\', '/'); 90 91 if (!webAppDir.endsWith("/")) { 92 webAppDir = webAppDir + "/"; 93 } 94 } 95 96 public String getWebAppDir() { 97 if (webAppDir == null) { 98 return ""; 99 } 100 return webAppDir; 101 } 102 103 public void setContextPath(String newContextPath) { 104 if (newContextPath == null) { 106 throw new IllegalArgumentException ("Context path may not be null"); 107 } 108 109 contextPath = newContextPath; 110 } 111 112 public String getContextPath() { 113 return contextPath; 114 } 115 116 public void setExpressoDir(String expressoDir) { 117 this.expressoDir = expressoDir; 118 } 119 120 public String getExpressoDir() { 121 return expressoDir; 122 } 123 124 public void setServerPrefix(String serverPrefix) { 125 this.serverPrefix = serverPrefix; 126 } 127 128 public String getServerPrefix() { 129 return serverPrefix; 130 } 131 132 138 public String expandValue(String propValue) { 139 if (propValue == null) { 140 return null; 141 } 142 143 148 if (propValue.indexOf("%web-app%") >= 0) { 149 propValue = StringUtil.replace(propValue, "%web-app%", getWebAppDir()); 150 } 151 152 156 if (propValue.indexOf("%context%") >= 0) { 157 propValue = StringUtil.replace(propValue, "%context%", getContextPath()); 158 } 159 163 if (propValue.indexOf("%expresso-dir%") >= 0) { 164 propValue = StringUtil.replace(propValue, "%expresso-dir%", 165 getExpressoDir()); 166 } 167 if (propValue.indexOf("%server%") >= 0) { 168 propValue = StringUtil.replace(propValue, "%server%", getServerPrefix()); 169 } 170 171 return propValue; 172 173 } 174 175 } | Popular Tags |