From 6f3f82f40a28bdfeef24af5713a534fa2d6ced51 Mon Sep 17 00:00:00 2001 From: hns Date: Wed, 15 Sep 2004 13:28:58 +0000 Subject: [PATCH] Remove abstract execute() method and add abstract getApplication(). Remove encoding instance variable and get it from application when needed. --- src/helma/servlet/AbstractServletClient.java | 37 +++++++++---------- src/helma/servlet/EmbeddedServletClient.java | 12 ++++-- .../servlet/StandaloneServletClient.java | 12 ++++-- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/helma/servlet/AbstractServletClient.java b/src/helma/servlet/AbstractServletClient.java index 61fe414a..d2cd1aab 100644 --- a/src/helma/servlet/AbstractServletClient.java +++ b/src/helma/servlet/AbstractServletClient.java @@ -20,6 +20,7 @@ package helma.servlet; import helma.framework.*; +import helma.framework.core.Application; import helma.util.*; import java.io.*; import java.util.*; @@ -47,9 +48,6 @@ public abstract class AbstractServletClient extends HttpServlet { // cookie domain to use String cookieDomain; - // default encoding for requests - String defaultEncoding = "ISO8859_1"; - // allow caching of responses boolean caching; @@ -57,9 +55,9 @@ public abstract class AbstractServletClient extends HttpServlet { boolean debug; /** + * Init this servlet. * - * - * @param init ... + * @param init the servlet configuration * * @throws ServletException ... */ @@ -78,21 +76,20 @@ public abstract class AbstractServletClient extends HttpServlet { cookieDomain = cookieDomain.toLowerCase(); } - // get default encoding - String encoding = init.getInitParameter("charset"); - - if (encoding != null) { - defaultEncoding = encoding; - } - debug = ("true".equalsIgnoreCase(init.getInitParameter("debug"))); 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 response ... @@ -106,7 +103,7 @@ public abstract class AbstractServletClient extends HttpServlet { } /** - * + * Handle a POST request. * * @param request ... * @param response ... @@ -128,8 +125,8 @@ public abstract class AbstractServletClient extends HttpServlet { String encoding = request.getCharacterEncoding(); if (encoding == null) { - // no encoding from request, use standard one - encoding = defaultEncoding; + // no encoding from request, use the application's charset + encoding = getApplication().getCharset(); } // read and set http parameters @@ -272,7 +269,7 @@ public abstract class AbstractServletClient extends HttpServlet { // response.setHeader ("Server", "Helma/"+helma.main.Server.version); reqtrans.path = getPathInfo(request); - ResponseTrans restrans = execute(reqtrans); + ResponseTrans restrans = getApplication().execute(reqtrans); // set cookies if (restrans.countCookies() > 0) { @@ -723,6 +720,8 @@ public abstract class AbstractServletClient extends HttpServlet { int uriTokens = t.countTokens(); StringBuffer pathbuffer = new StringBuffer(); + String encoding = getApplication().getCharset(); + for (int i = 0; i < uriTokens; i++) { String token = t.nextToken(); @@ -734,7 +733,7 @@ public abstract class AbstractServletClient extends HttpServlet { pathbuffer.append('/'); } - pathbuffer.append(UrlEncoded.decode(token, defaultEncoding)); + pathbuffer.append(UrlEncoded.decode(token, encoding)); } // append trailing "/" if it is contained in original URI diff --git a/src/helma/servlet/EmbeddedServletClient.java b/src/helma/servlet/EmbeddedServletClient.java index 98e53b1e..03fbfed7 100644 --- a/src/helma/servlet/EmbeddedServletClient.java +++ b/src/helma/servlet/EmbeddedServletClient.java @@ -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) { app = Server.getServer().getApplication(appName); - // get the app's charset - defaultEncoding = app.getCharset(); } - return app.execute(req); + return app; } } diff --git a/src/helma/servlet/StandaloneServletClient.java b/src/helma/servlet/StandaloneServletClient.java index 9d3a28cc..0540719c 100644 --- a/src/helma/servlet/StandaloneServletClient.java +++ b/src/helma/servlet/StandaloneServletClient.java @@ -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) { createApp(); } - return app.execute(req); + return app; } /** @@ -92,8 +98,6 @@ public final class StandaloneServletClient extends AbstractServletClient { app = new Application(appName, appHome, dbHome); app.init(); app.start(); - // get the app's charset - defaultEncoding = app.getCharset(); } catch (Exception x) { log("Error starting Application " + appName + ": " + x); x.printStackTrace();