001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.webapp;
031:
032: import com.caucho.config.ConfigException;
033: import com.caucho.config.types.RawString;
034: import com.caucho.log.Log;
035: import com.caucho.server.deploy.DeployConfig;
036: import com.caucho.server.util.CauchoSystem;
037: import com.caucho.util.L10N;
038:
039: import java.util.logging.Logger;
040: import java.util.regex.Pattern;
041:
042: /**
043: * The configuration for a web-app in the resin.conf
044: */
045: public class WebAppConfig extends DeployConfig {
046: private static final L10N L = new L10N(WebAppConfig.class);
047: private static final Logger log = Logger
048: .getLogger(WebAppConfig.class.getName());
049:
050: // Any regexp
051: private Pattern _urlRegexp;
052:
053: // The context path
054: private String _contextPath;
055:
056: private WebAppConfig _prologue;
057:
058: public WebAppConfig() {
059: }
060:
061: /**
062: * Gets the context path
063: */
064: public String getContextPath() {
065: String cp = _contextPath;
066:
067: if (cp == null)
068: cp = getId();
069:
070: if (cp == null)
071: return null;
072:
073: if (cp.endsWith("/"))
074: return cp.substring(0, cp.length() - 1);
075: else
076: return cp;
077: }
078:
079: /**
080: * Sets the context path
081: */
082: public void setContextPath(String path) throws ConfigException {
083: if (!path.startsWith("/"))
084: throw new ConfigException(L.l(
085: "context-path '{0}' must start with '/'.", path));
086:
087: _contextPath = path;
088: }
089:
090: /**
091: * Sets the url-regexp
092: */
093: public void setURLRegexp(String pattern) {
094: if (!pattern.endsWith("$"))
095: pattern = pattern + "$";
096: if (!pattern.startsWith("^"))
097: pattern = "^" + pattern;
098:
099: if (CauchoSystem.isCaseInsensitive())
100: _urlRegexp = Pattern.compile(pattern,
101: Pattern.CASE_INSENSITIVE);
102: else
103: _urlRegexp = Pattern.compile(pattern);
104: }
105:
106: /**
107: * Gets the regexp.
108: */
109: public Pattern getURLRegexp() {
110: return _urlRegexp;
111: }
112:
113: /**
114: * Sets the app-dir.
115: */
116: public void setAppDir(RawString appDir) {
117: setRootDirectory(appDir);
118: }
119:
120: /**
121: * Gets the app-dir.
122: */
123: public String getAppDir() {
124: return getRootDirectory();
125: }
126:
127: /**
128: * Sets the app-dir.
129: */
130: public String getDocumentDirectory() {
131: return getAppDir();
132: }
133:
134: /**
135: * Sets the app-dir.
136: */
137: public void setDocumentDirectory(RawString dir) {
138: setRootDirectory(dir);
139: }
140:
141: /**
142: * Sets the startup-mode
143: */
144: public void setLazyInit(boolean isLazy) throws ConfigException {
145: log
146: .config(L
147: .l("lazy-init is deprecated. Use <startup-mode>lazy</startup-mode> instead."));
148:
149: if (isLazy)
150: setStartupMode("lazy");
151: else
152: setStartupMode("automatic");
153: }
154:
155: /**
156: * Sets the prologue.
157: */
158: public void setPrologue(WebAppConfig prologue) {
159: _prologue = prologue;
160: }
161:
162: /**
163: * Gets the prologue.
164: */
165: public DeployConfig getPrologue() {
166: return _prologue;
167: }
168: }
|