KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > webapp > WebAppConfig


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.server.webapp;
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.server.util.CauchoSystem;
37 import com.caucho.util.L10N;
38
39 import java.util.logging.Logger JavaDoc;
40 import java.util.regex.Pattern JavaDoc;
41
42 /**
43  * The configuration for a web.app in the resin.conf
44  */

45 public class WebAppConfig extends DeployConfig {
46   static final L10N L = new L10N(WebAppConfig.class);
47   static final Logger JavaDoc log = Log.open(WebAppConfig.class);
48
49   // Any regexp
50
private Pattern JavaDoc _urlRegexp;
51
52   // The context path
53
private String JavaDoc _contextPath;
54
55   private WebAppConfig _prologue;
56
57   public WebAppConfig()
58   {
59   }
60
61   /**
62    * Gets the context path
63    */

64   public String JavaDoc getContextPath()
65   {
66     String JavaDoc cp = _contextPath;
67
68     if (cp == null)
69       cp = getId();
70
71     if (cp == null)
72       return null;
73
74     if (cp.endsWith("/"))
75       return cp.substring(0, cp.length() - 1);
76     else
77       return cp;
78   }
79
80   /**
81    * Sets the context path
82    */

83   public void setContextPath(String JavaDoc path)
84     throws ConfigException
85   {
86     if (! path.startsWith("/"))
87       throw new ConfigException(L.l("context-path '{0}' must start with '/'.",
88                     path));
89     
90     _contextPath = path;
91   }
92
93   /**
94    * Sets the url-regexp
95    */

96   public void setURLRegexp(String JavaDoc pattern)
97   {
98     if (! pattern.endsWith("$"))
99       pattern = pattern + "$";
100     if (! pattern.startsWith("^"))
101       pattern = "^" + pattern;
102
103     if (CauchoSystem.isCaseInsensitive())
104       _urlRegexp = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
105     else
106       _urlRegexp = Pattern.compile(pattern);
107   }
108
109   /**
110    * Gets the regexp.
111    */

112   public Pattern JavaDoc getURLRegexp()
113   {
114     return _urlRegexp;
115   }
116
117   /**
118    * Sets the app-dir.
119    */

120   public void setAppDir(RawString appDir)
121   {
122     setRootDirectory(appDir);
123   }
124
125   /**
126    * Gets the app-dir.
127    */

128   public String JavaDoc getAppDir()
129   {
130     return getRootDirectory();
131   }
132
133   /**
134    * Sets the app-dir.
135    */

136   public String JavaDoc getDocumentDirectory()
137   {
138     return getAppDir();
139   }
140
141   /**
142    * Sets the app-dir.
143    */

144   public void setDocumentDirectory(RawString dir)
145   {
146     setRootDirectory(dir);
147   }
148
149   /**
150    * Sets the startup-mode
151    */

152   public void setLazyInit(boolean isLazy)
153     throws ConfigException
154   {
155     log.config(L.l("lazy-init is deprecated. Use <startup-mode>lazy</startup-mode> instead."));
156
157     if (isLazy)
158       setStartupMode("lazy");
159     else
160       setStartupMode("automatic");
161   }
162
163   /**
164    * Sets the prologue.
165    */

166   public void setPrologue(WebAppConfig prologue)
167   {
168     _prologue = prologue;
169   }
170
171   /**
172    * Gets the prologue.
173    */

174   public DeployConfig getPrologue()
175   {
176     return _prologue;
177   }
178 }
179
Popular Tags