001: /*
002: * Copyright 1999-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: /*
017: * $Id: ApplyXSLTProperties.java,v 1.1 2006-06-27 14:42:52 sinisa Exp $
018: */
019: package servlet;
020:
021: import java.net.MalformedURLException;
022: import javax.servlet.*;
023: import javax.servlet.http.*;
024:
025: /*****************************************************************************************************
026: *
027: * ApplyXSLTProperties contains operational parameters for ApplyXSLT based
028: * on program defaults and configuration.
029: * <p>This class is also used to return values for request-time parameters.</p>
030: *
031: * @author Spencer Shepard (sshepard@us.ibm.com)
032: * @author R. Adam King (rak@us.ibm.com)
033: * @author Tom Rowe (trowe@us.ibm.com)
034: *
035: *****************************************************************************************************/
036:
037: public class ApplyXSLTProperties {
038:
039: /**
040: * Program default for parameter "URL"
041: */
042: private final String DEFAULT_URL;
043:
044: /**
045: * Program default for parameter "xslURL"
046: */
047: private final String DEFAULT_xslURL;
048:
049: /**
050: * Program default for parameter "debug"
051: */
052: private final boolean DEFAULT_debug;
053:
054: /**
055: * Program default for parameter "noConflictWarnings"
056: */
057: private final boolean DEFAULT_noCW;
058:
059: /**
060: * Constructor to use program defaults.
061: */
062: public ApplyXSLTProperties() {
063: DEFAULT_URL = null;
064: DEFAULT_xslURL = null;
065: DEFAULT_debug = false;
066: DEFAULT_noCW = false;
067: }
068:
069: /**
070: * Constructor to use to override program defaults.
071: * @param config Servlet configuration
072: */
073: public ApplyXSLTProperties(ServletConfig config) {
074: String xm = config.getInitParameter("URL"), xu = config
075: .getInitParameter("xslURL"), db = config
076: .getInitParameter("debug"), cw = config
077: .getInitParameter("noConflictWarnings");
078:
079: if (xm != null)
080: DEFAULT_URL = xm;
081: else
082: DEFAULT_URL = null;
083: if (xu != null)
084: DEFAULT_xslURL = xu;
085: else
086: DEFAULT_xslURL = null;
087: if (db != null)
088: DEFAULT_debug = new Boolean(db).booleanValue();
089: else
090: DEFAULT_debug = false;
091: if (cw != null)
092: DEFAULT_noCW = new Boolean(cw).booleanValue();
093: else
094: DEFAULT_noCW = false;
095: }
096:
097: /**
098: * Given a parameter name, returns the HTTP request's String value;
099: * if not present in request, returns default String value.
100: * @param request Request to check for default override
101: * @param param Name of the parameter
102: * @return String value of named parameter
103: */
104: public String getRequestParmString(HttpServletRequest request,
105: String param) {
106: if (request != null) {
107: String[] paramVals = request.getParameterValues(param);
108: if (paramVals != null)
109: return paramVals[0];
110: }
111: return null;
112: }
113:
114: /**
115: * Returns the current setting for "URL".
116: * @param request Request to check for parameter value
117: * @return String value for "URL"
118: * @exception MalformedURLException Will not be thrown
119: */
120: public String getXMLurl(HttpServletRequest request)
121: throws MalformedURLException {
122: String temp = getRequestParmString(request, "URL");
123: if (temp != null)
124: return temp;
125: return DEFAULT_URL;
126: }
127:
128: /**
129: * Returns the current setting for "xslURL".
130: * @param request Request to check for parameter value
131: * @return String value for "xslURL"
132: * @exception MalformedURLException Will not be thrown
133: */
134: public String getXSLurl(HttpServletRequest request)
135: throws MalformedURLException {
136: String temp = getRequestParmString(request, "xslURL");
137: if (temp != null)
138: return temp;
139: return DEFAULT_xslURL;
140: }
141:
142: /**
143: * Returns the current setting for "debug".
144: * @param request Request to check for parameter value
145: * @return Boolean value for "debug"
146: */
147: public boolean isDebug(HttpServletRequest request) {
148: String temp = getRequestParmString(request, "debug");
149: if (temp != null)
150: return new Boolean(temp).booleanValue();
151: return DEFAULT_debug;
152: }
153:
154: /**
155: * Returns the current setting for "noConflictWarnings".
156: * @param request Request to check for parameter value
157: * @return Boolean value for "noConflictWarnings"
158: */
159: boolean isNoCW(HttpServletRequest request) {
160: String temp = getRequestParmString(request,
161: "noConflictWarnings");
162: if (temp != null)
163: return new Boolean(temp).booleanValue();
164: return DEFAULT_noCW;
165: }
166: }
|