1 29 30 package com.caucho.server.host; 31 32 import com.caucho.config.ConfigException; 33 import com.caucho.config.types.RawString; 34 import com.caucho.log.Log; 35 import com.caucho.server.deploy.DeployConfig; 36 import com.caucho.util.L10N; 37 38 import javax.annotation.PostConstruct; 39 import java.util.ArrayList ; 40 import java.util.logging.Logger ; 41 import java.util.regex.Pattern ; 42 43 46 public class HostConfig extends DeployConfig { 47 static final L10N L = new L10N(HostConfig.class); 48 static final Logger log = Log.open(HostConfig.class); 49 50 private ArrayList <String > _hostAliases = new ArrayList <String >(); 52 53 private ArrayList <Pattern > _hostAliasRegexps 54 = new ArrayList <Pattern >(); 55 56 private String _hostName; 57 58 private Pattern _regexp; 60 61 public HostConfig() 62 { 63 super.setId(null); 64 } 65 66 69 public void setHostName(RawString name) 70 throws ConfigException 71 { 72 _hostName = cleanHostName(name); 73 String hostName = name.getValue(); 74 75 if (hostName.indexOf("${") < 0) { 76 for (int i = 0; i < hostName.length(); i++) { 77 char ch = hostName.charAt(i); 78 79 if (ch == ' ' || ch == '\t' || ch == ',') { 80 throw new ConfigException(L.l("Host name `{0}' must not contain multiple names. Use <host-alias> to specify aliases for a host.", 81 hostName)); 82 } 83 } 84 } 85 86 _hostName = hostName; 87 } 88 89 92 public String getHostName() 93 { 94 return _hostName; 95 } 96 97 100 public void setId(RawString id) 101 throws ConfigException 102 { 103 super.setId(cleanHostName(id)); 104 } 105 106 109 private String cleanHostName(RawString name) 110 throws ConfigException 111 { 112 String hostName = name.getValue(); 113 114 if (hostName.indexOf("${") < 0) { 115 for (int i = 0; i < hostName.length(); i++) { 116 char ch = hostName.charAt(i); 117 118 if (ch == ' ' || ch == '\t' || ch == ',') { 119 throw new ConfigException(L.l("Host name `{0}' must not contain multiple names. Use <host-alias> to specify aliases for a host.", 120 hostName)); 121 } 122 } 123 } 124 125 return hostName; 126 } 127 128 131 public void addHostAlias(RawString rawName) 132 throws ConfigException 133 { 134 String name = rawName.getValue().trim(); 135 136 if (name.indexOf("${") < 0) { 137 for (int i = 0; i < name.length(); i++) { 138 char ch = name.charAt(i); 139 140 if (ch == ' ' || ch == '\t' || ch == ',') { 141 throw new ConfigException(L.l("<host-alias> `{0}' must not contain multiple names. Use multiple <host-alias> tags to specify aliases for a host.", 142 name)); 143 } 144 } 145 } 146 147 if (! _hostAliases.contains(name)) 148 _hostAliases.add(name); 149 } 150 151 154 public ArrayList <String > getHostAliases() 155 { 156 return _hostAliases; 157 } 158 159 162 public void addHostAliasRegexp(String name) 163 { 164 name = name.trim(); 165 166 Pattern pattern = Pattern.compile(name, Pattern.CASE_INSENSITIVE); 167 168 if (! _hostAliasRegexps.contains(pattern)) 169 _hostAliasRegexps.add(pattern); 170 } 171 172 175 public ArrayList <Pattern > getHostAliasRegexps() 176 { 177 return _hostAliasRegexps; 178 } 179 180 183 public void setRegexp(RawString regexp) 184 { 185 String value = regexp.getValue(); 186 187 if (! value.endsWith("$")) 188 value = value + "$"; 189 190 _regexp = Pattern.compile(value, Pattern.CASE_INSENSITIVE); 191 } 192 193 196 public Pattern getRegexp() 197 { 198 return _regexp; 199 } 200 201 204 public void setRootDir(RawString rootDir) 205 { 206 setRootDirectory(rootDir); 207 } 208 209 212 public void setLazyInit(boolean lazyInit) 213 throws ConfigException 214 { 215 if (lazyInit) 216 setStartupMode("lazy"); 217 else 218 setStartupMode("automatic"); 219 } 220 221 224 @PostConstruct 225 public void init() 226 { 227 if (_regexp != null && getId() == null) 228 log.config(L.l("<host regexp=\"{0}\"> should include a <host-name> tag.", 229 _regexp.pattern())); 230 } 231 } 232 | Popular Tags |