KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servlet > ApplyXSLTProperties


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * $Id: ApplyXSLTProperties.java,v 1.4 2004/02/17 19:13:22 minchau Exp $
18  */

19 package servlet;
20
21 import java.net.MalformedURLException JavaDoc;
22 import javax.servlet.*;
23 import javax.servlet.http.*;
24
25 /*****************************************************************************************************
26  *
27  * ApplyXSLTProperties contains operational parameters for ApplyXSLT based
28  * on program defaults and configuration.
29  * <p>This class is also used to return values for request-time parameters.</p>
30  *
31  * @author Spencer Shepard (sshepard@us.ibm.com)
32  * @author R. Adam King (rak@us.ibm.com)
33  * @author Tom Rowe (trowe@us.ibm.com)
34  *
35  *****************************************************************************************************/

36
37 public class ApplyXSLTProperties {
38
39     /**
40       * Program default for parameter "URL"
41       */

42     private final String JavaDoc DEFAULT_URL;
43
44     /**
45       * Program default for parameter "xslURL"
46       */

47     private final String JavaDoc DEFAULT_xslURL;
48     
49     /**
50       * Program default for parameter "debug"
51       */

52     private final boolean DEFAULT_debug;
53
54     /**
55       * Program default for parameter "noConflictWarnings"
56       */

57     private final boolean DEFAULT_noCW;
58     
59     /**
60       * Constructor to use program defaults.
61       */

62     public ApplyXSLTProperties()
63     {
64     DEFAULT_URL = null;
65     DEFAULT_xslURL = null;
66     DEFAULT_debug = false;
67     DEFAULT_noCW = false;
68     }
69
70     /**
71       * Constructor to use to override program defaults.
72       * @param config Servlet configuration
73       */

74     public ApplyXSLTProperties(ServletConfig config)
75     {
76     String JavaDoc xm = config.getInitParameter("URL"),
77            xu = config.getInitParameter("xslURL"),
78            db = config.getInitParameter("debug"),
79            cw = config.getInitParameter("noConflictWarnings");
80            
81     if (xm != null) DEFAULT_URL = xm;
82     else DEFAULT_URL = null;
83     if (xu != null) DEFAULT_xslURL = xu;
84     else DEFAULT_xslURL = null;
85     if (db != null) DEFAULT_debug = new Boolean JavaDoc(db).booleanValue();
86     else DEFAULT_debug = false;
87     if (cw != null) DEFAULT_noCW = new Boolean JavaDoc(cw).booleanValue();
88     else DEFAULT_noCW = false;
89     }
90    
91     /**
92       * Given a parameter name, returns the HTTP request's String value;
93       * if not present in request, returns default String value.
94       * @param request Request to check for default override
95       * @param param Name of the parameter
96       * @return String value of named parameter
97       */

98     public String JavaDoc getRequestParmString(HttpServletRequest request, String JavaDoc param)
99     {
100     if (request != null) {
101         String JavaDoc[] paramVals = request.getParameterValues(param);
102         if (paramVals != null)
103         return paramVals[0];
104     }
105     return null;
106     }
107
108     /**
109       * Returns the current setting for "URL".
110       * @param request Request to check for parameter value
111       * @return String value for "URL"
112       * @exception MalformedURLException Will not be thrown
113       */

114     public String JavaDoc getXMLurl(HttpServletRequest request)
115     throws MalformedURLException JavaDoc
116     {
117     String JavaDoc temp = getRequestParmString(request, "URL");
118     if (temp != null)
119         return temp;
120     return DEFAULT_URL;
121     }
122     
123     /**
124       * Returns the current setting for "xslURL".
125       * @param request Request to check for parameter value
126       * @return String value for "xslURL"
127       * @exception MalformedURLException Will not be thrown
128       */

129     public String JavaDoc getXSLurl(HttpServletRequest request)
130     throws MalformedURLException JavaDoc
131     {
132     String JavaDoc temp = getRequestParmString(request, "xslURL");
133     if (temp != null)
134         return temp;
135     return DEFAULT_xslURL;
136     }
137     
138     /**
139       * Returns the current setting for "debug".
140       * @param request Request to check for parameter value
141       * @return Boolean value for "debug"
142       */

143     public boolean isDebug(HttpServletRequest request)
144     {
145     String JavaDoc temp = getRequestParmString(request, "debug");
146     if (temp != null)
147         return new Boolean JavaDoc(temp).booleanValue();
148     return DEFAULT_debug;
149     }
150
151     /**
152       * Returns the current setting for "noConflictWarnings".
153       * @param request Request to check for parameter value
154       * @return Boolean value for "noConflictWarnings"
155       */

156     boolean isNoCW(HttpServletRequest request)
157     {
158     String JavaDoc temp = getRequestParmString(request, "noConflictWarnings");
159     if (temp != null)
160         return new Boolean JavaDoc(temp).booleanValue();
161     return DEFAULT_noCW;
162     }
163 }
164
Popular Tags