Remove abstract execute() method and add abstract getApplication().

Remove encoding instance variable and get it from application when needed.
This commit is contained in:
hns 2004-09-15 13:28:58 +00:00
parent 381e235e19
commit 6f3f82f40a
3 changed files with 34 additions and 27 deletions

View file

@ -20,6 +20,7 @@
package helma.servlet; package helma.servlet;
import helma.framework.*; import helma.framework.*;
import helma.framework.core.Application;
import helma.util.*; import helma.util.*;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
@ -47,9 +48,6 @@ public abstract class AbstractServletClient extends HttpServlet {
// cookie domain to use // cookie domain to use
String cookieDomain; String cookieDomain;
// default encoding for requests
String defaultEncoding = "ISO8859_1";
// allow caching of responses // allow caching of responses
boolean caching; boolean caching;
@ -57,9 +55,9 @@ public abstract class AbstractServletClient extends HttpServlet {
boolean debug; boolean debug;
/** /**
* Init this servlet.
* *
* * @param init the servlet configuration
* @param init ...
* *
* @throws ServletException ... * @throws ServletException ...
*/ */
@ -78,21 +76,20 @@ public abstract class AbstractServletClient extends HttpServlet {
cookieDomain = cookieDomain.toLowerCase(); cookieDomain = cookieDomain.toLowerCase();
} }
// get default encoding
String encoding = init.getInitParameter("charset");
if (encoding != null) {
defaultEncoding = encoding;
}
debug = ("true".equalsIgnoreCase(init.getInitParameter("debug"))); debug = ("true".equalsIgnoreCase(init.getInitParameter("debug")));
caching = !("false".equalsIgnoreCase(init.getInitParameter("caching"))); caching = !("false".equalsIgnoreCase(init.getInitParameter("caching")));
} }
abstract ResponseTrans execute(RequestTrans req) throws Exception; /**
* Abstract method to get the {@link helma.framework.core.Application Applicaton}
* instance the servlet is talking to.
*
* @return this servlet's application instance
*/
abstract Application getApplication();
/** /**
* * Handle a GET request.
* *
* @param request ... * @param request ...
* @param response ... * @param response ...
@ -106,7 +103,7 @@ public abstract class AbstractServletClient extends HttpServlet {
} }
/** /**
* * Handle a POST request.
* *
* @param request ... * @param request ...
* @param response ... * @param response ...
@ -128,8 +125,8 @@ public abstract class AbstractServletClient extends HttpServlet {
String encoding = request.getCharacterEncoding(); String encoding = request.getCharacterEncoding();
if (encoding == null) { if (encoding == null) {
// no encoding from request, use standard one // no encoding from request, use the application's charset
encoding = defaultEncoding; encoding = getApplication().getCharset();
} }
// read and set http parameters // read and set http parameters
@ -272,7 +269,7 @@ public abstract class AbstractServletClient extends HttpServlet {
// response.setHeader ("Server", "Helma/"+helma.main.Server.version); // response.setHeader ("Server", "Helma/"+helma.main.Server.version);
reqtrans.path = getPathInfo(request); reqtrans.path = getPathInfo(request);
ResponseTrans restrans = execute(reqtrans); ResponseTrans restrans = getApplication().execute(reqtrans);
// set cookies // set cookies
if (restrans.countCookies() > 0) { if (restrans.countCookies() > 0) {
@ -723,6 +720,8 @@ public abstract class AbstractServletClient extends HttpServlet {
int uriTokens = t.countTokens(); int uriTokens = t.countTokens();
StringBuffer pathbuffer = new StringBuffer(); StringBuffer pathbuffer = new StringBuffer();
String encoding = getApplication().getCharset();
for (int i = 0; i < uriTokens; i++) { for (int i = 0; i < uriTokens; i++) {
String token = t.nextToken(); String token = t.nextToken();
@ -734,7 +733,7 @@ public abstract class AbstractServletClient extends HttpServlet {
pathbuffer.append('/'); pathbuffer.append('/');
} }
pathbuffer.append(UrlEncoded.decode(token, defaultEncoding)); pathbuffer.append(UrlEncoded.decode(token, encoding));
} }
// append trailing "/" if it is contained in original URI // append trailing "/" if it is contained in original URI

View file

@ -52,13 +52,17 @@ public final class EmbeddedServletClient extends AbstractServletClient {
} }
} }
ResponseTrans execute(RequestTrans req) throws Exception { /**
* Returns the {@link helma.framework.core.Application Applicaton}
* instance the servlet is talking to.
*
* @return this servlet's application instance
*/
Application getApplication() {
if (app == null) { if (app == null) {
app = Server.getServer().getApplication(appName); app = Server.getServer().getApplication(appName);
// get the app's charset
defaultEncoding = app.getCharset();
} }
return app.execute(req); return app;
} }
} }

View file

@ -68,12 +68,18 @@ public final class StandaloneServletClient extends AbstractServletClient {
} }
} }
ResponseTrans execute(RequestTrans req) throws Exception { /**
* Returns the {@link helma.framework.core.Application Applicaton}
* instance the servlet is talking to.
*
* @return this servlet's application instance
*/
Application getApplication() {
if (app == null) { if (app == null) {
createApp(); createApp();
} }
return app.execute(req); return app;
} }
/** /**
@ -92,8 +98,6 @@ public final class StandaloneServletClient extends AbstractServletClient {
app = new Application(appName, appHome, dbHome); app = new Application(appName, appHome, dbHome);
app.init(); app.init();
app.start(); app.start();
// get the app's charset
defaultEncoding = app.getCharset();
} catch (Exception x) { } catch (Exception x) {
log("Error starting Application " + appName + ": " + x); log("Error starting Application " + appName + ": " + x);
x.printStackTrace(); x.printStackTrace();