001: /*
002: * Copyright (c) 1998-2003 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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.servlet.jsp.jstl.core;
030:
031: import java.util.logging.*;
032:
033: import javax.servlet.ServletContext;
034: import javax.servlet.ServletRequest;
035: import javax.servlet.http.HttpSession;
036: import javax.servlet.jsp.PageContext;
037:
038: public class Config {
039: private static final Logger log = Logger.getLogger(Config.class
040: .getName());
041: /**
042: * The application's configured locale.
043: */
044: public static final String FMT_LOCALE = "javax.servlet.jsp.jstl.fmt.locale";
045:
046: /**
047: * The fallback locale if none is found.
048: */
049: public static final String FMT_FALLBACK_LOCALE = "javax.servlet.jsp.jstl.fmt.fallbackLocale";
050:
051: /**
052: * The current i18n localization context.
053: */
054: public static final String FMT_LOCALIZATION_CONTEXT = "javax.servlet.jsp.jstl.fmt.localizationContext";
055:
056: /**
057: * The current time zone.
058: */
059: public static final String FMT_TIME_ZONE = "javax.servlet.jsp.jstl.fmt.timeZone";
060:
061: /**
062: * The current Data Source.
063: */
064: public static final String SQL_DATA_SOURCE = "javax.servlet.jsp.jstl.sql.dataSource";
065:
066: /**
067: * The maximum rows to read from the database.
068: */
069: public static final String SQL_MAX_ROWS = "javax.servlet.jsp.jstl.sql.maxRows";
070:
071: public static Object find(PageContext pageContext, String name) {
072: Object object = pageContext.findAttribute(name);
073:
074: if (object != null)
075: return object;
076:
077: return pageContext.getServletContext().getInitParameter(name);
078: }
079:
080: /**
081: * Returns an attribute from the page context.
082: */
083: public static Object get(PageContext pageContext, String name,
084: int scope) {
085: return pageContext.getAttribute(name, scope);
086: }
087:
088: public static Object get(ServletRequest request, String name) {
089: return request.getAttribute(name);
090: }
091:
092: public static Object get(HttpSession session, String name) {
093: try {
094: if (session != null)
095: return session.getAttribute(name);
096: } catch (IllegalStateException e) {
097: log.log(Level.FINE, e.toString(), e);
098: }
099:
100: return null;
101: }
102:
103: public static Object get(ServletContext context, String name) {
104: return context.getAttribute(name);
105: }
106:
107: /**
108: * Returns an attribute from the page context.
109: */
110: public static void remove(PageContext pageContext, String name,
111: int scope) {
112: pageContext.removeAttribute(name, scope);
113: }
114:
115: public static void remove(ServletRequest request, String name) {
116: request.removeAttribute(name);
117: }
118:
119: public static void remove(HttpSession session, String name) {
120: session.removeAttribute(name);
121: }
122:
123: public static void remove(ServletContext context, String name) {
124: context.removeAttribute(name);
125: }
126:
127: public static void set(ServletRequest request, String name,
128: Object var) {
129: request.setAttribute(name, var);
130: }
131:
132: public static void set(HttpSession session, String name, Object var) {
133: try {
134: if (session != null)
135: session.setAttribute(name, var);
136: } catch (IllegalStateException e) {
137: log.log(Level.FINE, e.toString(), e);
138: }
139: }
140:
141: public static void set(ServletContext context, String name,
142: Object var) {
143: context.setAttribute(name, var);
144: }
145:
146: public static void set(PageContext pageContext, String name,
147: Object var, int scope) {
148: pageContext.setAttribute(name, var, scope);
149: }
150: }
|