Configpublic class Config extends Object Class supporting access to configuration settings. |
Fields Summary |
---|
public static final String | FMT_LOCALEName of configuration setting for application- (as opposed to browser-)
based preferred locale | public static final String | FMT_FALLBACK_LOCALEName of configuration setting for fallback locale | public static final String | FMT_LOCALIZATION_CONTEXTName of configuration setting for i18n localization context | public static final String | FMT_TIME_ZONEName of localization setting for time zone | public static final String | SQL_DATA_SOURCEName of configuration setting for SQL data source | public static final String | SQL_MAX_ROWSName of configuration setting for maximum number of rows to be included
in SQL query result | private static final String | PAGE_SCOPE_SUFFIX | private static final String | REQUEST_SCOPE_SUFFIX | private static final String | SESSION_SCOPE_SUFFIX | private static final String | APPLICATION_SCOPE_SUFFIX |
Methods Summary |
---|
public static java.lang.Object | find(javax.servlet.jsp.PageContext pc, java.lang.String name)Finds the value associated with a specific configuration setting
identified by its context initialization parameter name.
For each of the JSP scopes (page, request, session, application),
get the value of the configuration variable identified by name
using method get(). Return as soon as a non-null value is
found. If no value is found, get the value of the context initialization
parameter identified by name.
Object ret = get(pc, name, PageContext.PAGE_SCOPE);
if (ret == null) {
ret = get(pc, name, PageContext.REQUEST_SCOPE);
if (ret == null) {
if (pc.getSession() != null) {
// check session only if a session is present
ret = get(pc, name, PageContext.SESSION_SCOPE);
}
if (ret == null) {
ret = get(pc, name, PageContext.APPLICATION_SCOPE);
if (ret == null) {
ret = pc.getServletContext().getInitParameter(name);
}
}
}
}
return ret;
| public static java.lang.Object | get(javax.servlet.jsp.PageContext pc, java.lang.String name, int scope)Looks up a configuration variable in the given scope.
The lookup of configuration variables is performed as if each scope
had its own name space, that is, the same configuration variable name
in one scope does not replace one stored in a different scope.
switch (scope) {
case PageContext.PAGE_SCOPE:
return pc.getAttribute(name + PAGE_SCOPE_SUFFIX, scope);
case PageContext.REQUEST_SCOPE:
return pc.getAttribute(name + REQUEST_SCOPE_SUFFIX, scope);
case PageContext.SESSION_SCOPE:
return get(pc.getSession(), name);
case PageContext.APPLICATION_SCOPE:
return pc.getAttribute(name + APPLICATION_SCOPE_SUFFIX, scope);
default:
throw new IllegalArgumentException("unknown scope");
}
| public static java.lang.Object | get(javax.servlet.ServletRequest request, java.lang.String name)Looks up a configuration variable in the "request" scope.
The lookup of configuration variables is performed as if each scope
had its own name space, that is, the same configuration variable name
in one scope does not replace one stored in a different scope.
return request.getAttribute(name + REQUEST_SCOPE_SUFFIX);
| public static java.lang.Object | get(javax.servlet.http.HttpSession session, java.lang.String name)Looks up a configuration variable in the "session" scope.
The lookup of configuration variables is performed as if each scope
had its own name space, that is, the same configuration variable name
in one scope does not replace one stored in a different scope.
Object ret = null;
if (session != null) {
try {
ret = session.getAttribute(name + SESSION_SCOPE_SUFFIX);
} catch (IllegalStateException ex) {} // when session is invalidated
}
return ret;
| public static java.lang.Object | get(javax.servlet.ServletContext context, java.lang.String name)Looks up a configuration variable in the "application" scope.
The lookup of configuration variables is performed as if each scope
had its own name space, that is, the same configuration variable name
in one scope does not replace one stored in a different scope.
return context.getAttribute(name + APPLICATION_SCOPE_SUFFIX);
| public static void | remove(javax.servlet.ServletRequest request, java.lang.String name)Removes a configuration variable from the "request" scope.
Removing a configuration variable is performed as if each scope had
its own namespace, that is, the same configuration variable name in one
scope does not impact one stored in a different scope.
request.removeAttribute(name + REQUEST_SCOPE_SUFFIX);
| public static void | remove(javax.servlet.http.HttpSession session, java.lang.String name)Removes a configuration variable from the "session" scope.
Removing a configuration variable is performed as if each scope had
its own namespace, that is, the same configuration variable name in one
scope does not impact one stored in a different scope.
session.removeAttribute(name + SESSION_SCOPE_SUFFIX);
| public static void | remove(javax.servlet.ServletContext context, java.lang.String name)Removes a configuration variable from the "application" scope.
Removing a configuration variable is performed as if each scope had
its own namespace, that is, the same configuration variable name in one
scope does not impact one stored in a different scope.
context.removeAttribute(name + APPLICATION_SCOPE_SUFFIX);
| public static void | remove(javax.servlet.jsp.PageContext pc, java.lang.String name, int scope)Removes a configuration variable from the given scope.
Removing a configuration variable is performed as if each scope had
its own namespace, that is, the same configuration variable name in one
scope does not impact one stored in a different scope.
switch (scope) {
case PageContext.PAGE_SCOPE:
pc.removeAttribute(name + PAGE_SCOPE_SUFFIX, scope);
break;
case PageContext.REQUEST_SCOPE:
pc.removeAttribute(name + REQUEST_SCOPE_SUFFIX, scope);
break;
case PageContext.SESSION_SCOPE:
pc.removeAttribute(name + SESSION_SCOPE_SUFFIX, scope);
break;
case PageContext.APPLICATION_SCOPE:
pc.removeAttribute(name + APPLICATION_SCOPE_SUFFIX, scope);
break;
default:
throw new IllegalArgumentException("unknown scope");
}
| public static void | set(javax.servlet.jsp.PageContext pc, java.lang.String name, java.lang.Object value, int scope)Sets the value of a configuration variable in the given scope.
Setting the value of a configuration variable is performed as if
each scope had its own namespace, that is, the same configuration
variable name in one scope does not replace one stored in a different
scope.
switch (scope) {
case PageContext.PAGE_SCOPE:
pc.setAttribute(name + PAGE_SCOPE_SUFFIX, value, scope);
break;
case PageContext.REQUEST_SCOPE:
pc.setAttribute(name + REQUEST_SCOPE_SUFFIX, value, scope);
break;
case PageContext.SESSION_SCOPE:
pc.setAttribute(name + SESSION_SCOPE_SUFFIX, value, scope);
break;
case PageContext.APPLICATION_SCOPE:
pc.setAttribute(name + APPLICATION_SCOPE_SUFFIX, value, scope);
break;
default:
throw new IllegalArgumentException("unknown scope");
}
| public static void | set(javax.servlet.ServletRequest request, java.lang.String name, java.lang.Object value)Sets the value of a configuration variable in the "request" scope.
Setting the value of a configuration variable is performed as if
each scope had its own namespace, that is, the same configuration
variable name in one scope does not replace one stored in a different
scope.
request.setAttribute(name + REQUEST_SCOPE_SUFFIX, value);
| public static void | set(javax.servlet.http.HttpSession session, java.lang.String name, java.lang.Object value)Sets the value of a configuration variable in the "session" scope.
Setting the value of a configuration variable is performed as if
each scope had its own namespace, that is, the same configuration
variable name in one scope does not replace one stored in a different
scope.
session.setAttribute(name + SESSION_SCOPE_SUFFIX, value);
| public static void | set(javax.servlet.ServletContext context, java.lang.String name, java.lang.Object value)Sets the value of a configuration variable in the "application" scope.
Setting the value of a configuration variable is performed as if
each scope had its own namespace, that is, the same configuration
variable name in one scope does not replace one stored in a different
scope.
context.setAttribute(name + APPLICATION_SCOPE_SUFFIX, value);
|
|