tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1023361 - in /tomcat/trunk/java/org/apache: catalina/manager/HTMLManagerServlet.java catalina/manager/ManagerServlet.java tomcat/util/res/StringManager.java
Date Sat, 16 Oct 2010 19:31:37 GMT
Author: markt
Date: Sat Oct 16 19:31:37 2010
New Revision: 1023361

URL: http://svn.apache.org/viewvc?rev=1023361&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49426
Messages displayed to the user in the Manager (text and HTML) should be based on the Locale of the user, not the server

Modified:
    tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java
    tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java
    tomcat/trunk/java/org/apache/tomcat/util/res/StringManager.java

Modified: tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java?rev=1023361&r1=1023360&r2=1023361&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java Sat Oct 16 19:31:37 2010
@@ -55,6 +55,7 @@ import org.apache.catalina.util.RequestU
 import org.apache.catalina.util.ServerInfo;
 import org.apache.catalina.util.URLEncoder;
 import org.apache.tomcat.util.http.fileupload.ParameterParser;
+import org.apache.tomcat.util.res.StringManager;
 
 /**
 * Servlet that enables remote management of the web applications deployed
@@ -116,6 +117,8 @@ public final class HTMLManagerServlet ex
                       HttpServletResponse response)
         throws IOException, ServletException {
 
+        StringManager smClient = getStringManager(request);
+        
         // Identify the request parameters that we need
         // By obtaining the command from the pathInfo, per-command security can
         // be configured in web.xml
@@ -134,11 +137,11 @@ public final class HTMLManagerServlet ex
             // List always displayed - nothing to do here
         } else if (command.equals("/sessions")) {
             try {
-                doSessions(path, request, response);
+                doSessions(path, request, response, smClient);
                 return;
             } catch (Exception e) {
                 log("HTMLManagerServlet.sessions[" + path + "]", e);
-                message = sm.getString("managerServlet.exception",
+                message = smClient.getString("managerServlet.exception",
                         e.toString());
             }
         } else if (command.equals("/upload") || command.equals("/deploy") ||
@@ -146,13 +149,13 @@ public final class HTMLManagerServlet ex
                 command.equals("/expire") || command.equals("/start") ||
                 command.equals("/stop")) {
             message =
-                sm.getString("managerServlet.postCommand", command);
+                smClient.getString("managerServlet.postCommand", command);
         } else {
             message =
-                sm.getString("managerServlet.unknownCommand", command);
+                smClient.getString("managerServlet.unknownCommand", command);
         }
 
-        list(request, response, message);
+        list(request, response, message, smClient);
     }
 
     /**
@@ -169,6 +172,8 @@ public final class HTMLManagerServlet ex
                       HttpServletResponse response)
         throws IOException, ServletException {
 
+        StringManager smClient = getStringManager(request);
+
         // Identify the request parameters that we need
         // By obtaining the command from the pathInfo, per-command security can
         // be configured in web.xml
@@ -188,28 +193,29 @@ public final class HTMLManagerServlet ex
             // No command == list
             // List always displayed -> do nothing
         } else if (command.equals("/upload")) {
-            message = upload(request);
+            message = upload(request, smClient);
         } else if (command.equals("/deploy")) {
-            message = deployInternal(deployConfig, deployPath, deployWar);
+            message = deployInternal(deployConfig, deployPath, deployWar,
+                    smClient);
         } else if (command.equals("/reload")) {
-            message = reload(path);
+            message = reload(path, smClient);
         } else if (command.equals("/undeploy")) {
-            message = undeploy(path);
+            message = undeploy(path, smClient);
         } else if (command.equals("/expire")) {
-            message = expireSessions(path, request);
+            message = expireSessions(path, request, smClient);
         } else if (command.equals("/start")) {
-            message = start(path);
+            message = start(path, smClient);
         } else if (command.equals("/stop")) {
-            message = stop(path);
+            message = stop(path, smClient);
         } else if (command.equals("/findleaks")) {
-            message = findleaks();
+            message = findleaks(smClient);
         } else {
             // Try GET
             doGet(request,response);
             return;
         }
 
-        list(request, response, message);
+        list(request, response, message, smClient);
     }
 
     /**
@@ -242,7 +248,7 @@ public final class HTMLManagerServlet ex
         return buffer.toString();
     }
 
-    protected String upload(HttpServletRequest request)
+    protected String upload(HttpServletRequest request, StringManager smClient)
             throws IOException, ServletException {
         String message = "";
 
@@ -265,14 +271,14 @@ public final class HTMLManagerServlet ex
 
             while (true) {
                 if (warPart == null) {
-                    message =
-                        sm.getString("htmlManagerServlet.deployUploadNoFile");
+                    message = smClient.getString(
+                            "htmlManagerServlet.deployUploadNoFile");
                     break;
                 }
                 filename =
                     extractFilename(warPart.getHeader("Content-Disposition"));
                 if (!filename.toLowerCase(Locale.ENGLISH).endsWith(".war")) {
-                    message = sm.getString(
+                    message = smClient.getString(
                             "htmlManagerServlet.deployUploadNotWar", filename);
                     break;
                 }
@@ -291,7 +297,7 @@ public final class HTMLManagerServlet ex
                         filename.toLowerCase(Locale.ENGLISH).indexOf(".war"));
                 File file = new File(getAppBase(), filename);
                 if (file.exists()) {
-                    message = sm.getString(
+                    message = smClient.getString(
                             "htmlManagerServlet.deployUploadWarExists",
                             filename);
                     break;
@@ -304,7 +310,7 @@ public final class HTMLManagerServlet ex
                 }
 
                 if ((host.findChild(path) != null) && !isDeployed(path)) {
-                    message = sm.getString(
+                    message = smClient.getString(
                             "htmlManagerServlet.deployUploadInServerXml",
                             filename);
                     break;
@@ -323,7 +329,7 @@ public final class HTMLManagerServlet ex
                 break;
             }
         } catch(Exception e) {
-            message = sm.getString
+            message = smClient.getString
                 ("htmlManagerServlet.deployUploadFail", e.getMessage());
             log(message, e);
         } finally {
@@ -373,12 +379,13 @@ public final class HTMLManagerServlet ex
      * @param war URL of the web application archive to be deployed
      * @return message String
      */
-    protected String deployInternal(String config, String path, String war) {
+    protected String deployInternal(String config, String path, String war,
+            StringManager smClient) {
 
         StringWriter stringWriter = new StringWriter();
         PrintWriter printWriter = new PrintWriter(stringWriter);
 
-        super.deploy(printWriter, config, path, war, false);
+        super.deploy(printWriter, config, path, war, false, smClient);
 
         return stringWriter.toString();
     }
@@ -393,7 +400,8 @@ public final class HTMLManagerServlet ex
      */
     public void list(HttpServletRequest request,
                      HttpServletResponse response,
-                     String message) throws IOException {
+                     String message,
+                     StringManager smClient) throws IOException {
 
         if (debug >= 1)
             log("list: Listing contexts for virtual host '" +
@@ -407,13 +415,13 @@ public final class HTMLManagerServlet ex
         // Body Header Section
         Object[] args = new Object[2];
         args[0] = request.getContextPath();
-        args[1] = sm.getString("htmlManagerServlet.title");
+        args[1] = smClient.getString("htmlManagerServlet.title");
         writer.print(MessageFormat.format
                      (Constants.BODY_HEADER_SECTION, args));
 
         // Message Section
         args = new Object[3];
-        args[0] = sm.getString("htmlManagerServlet.messageLabel");
+        args[0] = smClient.getString("htmlManagerServlet.messageLabel");
         if (message == null || message.length() == 0) {
             args[1] = "OK";
         } else {
@@ -423,30 +431,30 @@ public final class HTMLManagerServlet ex
 
         // Manager Section
         args = new Object[9];
-        args[0] = sm.getString("htmlManagerServlet.manager");
+        args[0] = smClient.getString("htmlManagerServlet.manager");
         args[1] = response.encodeURL(request.getContextPath() + "/html/list");
-        args[2] = sm.getString("htmlManagerServlet.list");
+        args[2] = smClient.getString("htmlManagerServlet.list");
         args[3] = response.encodeURL
             (request.getContextPath() + "/" +
-             sm.getString("htmlManagerServlet.helpHtmlManagerFile"));
-        args[4] = sm.getString("htmlManagerServlet.helpHtmlManager");
+             smClient.getString("htmlManagerServlet.helpHtmlManagerFile"));
+        args[4] = smClient.getString("htmlManagerServlet.helpHtmlManager");
         args[5] = response.encodeURL
             (request.getContextPath() + "/" +
-             sm.getString("htmlManagerServlet.helpManagerFile"));
-        args[6] = sm.getString("htmlManagerServlet.helpManager");
+             smClient.getString("htmlManagerServlet.helpManagerFile"));
+        args[6] = smClient.getString("htmlManagerServlet.helpManager");
         args[7] = response.encodeURL
             (request.getContextPath() + "/status");
-        args[8] = sm.getString("statusServlet.title");
+        args[8] = smClient.getString("statusServlet.title");
         writer.print(MessageFormat.format(Constants.MANAGER_SECTION, args));
 
         // Apps Header Section
         args = new Object[6];
-        args[0] = sm.getString("htmlManagerServlet.appsTitle");
-        args[1] = sm.getString("htmlManagerServlet.appsPath");
-        args[2] = sm.getString("htmlManagerServlet.appsName");
-        args[3] = sm.getString("htmlManagerServlet.appsAvailable");
-        args[4] = sm.getString("htmlManagerServlet.appsSessions");
-        args[5] = sm.getString("htmlManagerServlet.appsTasks");
+        args[0] = smClient.getString("htmlManagerServlet.appsTitle");
+        args[1] = smClient.getString("htmlManagerServlet.appsPath");
+        args[2] = smClient.getString("htmlManagerServlet.appsName");
+        args[3] = smClient.getString("htmlManagerServlet.appsAvailable");
+        args[4] = smClient.getString("htmlManagerServlet.appsSessions");
+        args[5] = smClient.getString("htmlManagerServlet.appsTasks");
         writer.print(MessageFormat.format(APPS_HEADER_SECTION, args));
 
         // Apps Row Section
@@ -464,11 +472,11 @@ public final class HTMLManagerServlet ex
             sortedContextPathsMap.put(displayPath, contextPaths[i]);
         }
  
-        String appsStart = sm.getString("htmlManagerServlet.appsStart");
-        String appsStop = sm.getString("htmlManagerServlet.appsStop");
-        String appsReload = sm.getString("htmlManagerServlet.appsReload");
-        String appsUndeploy = sm.getString("htmlManagerServlet.appsUndeploy");
-        String appsExpire = sm.getString("htmlManagerServlet.appsExpire");
+        String appsStart = smClient.getString("htmlManagerServlet.appsStart");
+        String appsStop = smClient.getString("htmlManagerServlet.appsStop");
+        String appsReload = smClient.getString("htmlManagerServlet.appsReload");
+        String appsUndeploy = smClient.getString("htmlManagerServlet.appsUndeploy");
+        String appsExpire = smClient.getString("htmlManagerServlet.appsExpire");
 
         Iterator<Map.Entry<String,String>> iterator =
             sortedContextPathsMap.entrySet().iterator();
@@ -549,14 +557,16 @@ public final class HTMLManagerServlet ex
                     (request.getContextPath() +
                      "/html/expire?path=" + URL_ENCODER.encode(displayPath));
                 args[9] = appsExpire;
-                args[10] = sm.getString("htmlManagerServlet.expire.explain");
+                args[10] = smClient.getString(
+                        "htmlManagerServlet.expire.explain");
                 if (manager == null) {
-                    args[11] = sm.getString("htmlManagerServlet.noManager");
+                    args[11] = smClient.getString(
+                            "htmlManagerServlet.noManager");
                 } else {
                     args[11] = new Integer(
                             ctxt.getManager().getMaxInactiveInterval()/60);
                 }
-                args[12] = sm.getString("htmlManagerServlet.expire.unit");
+                args[12] = smClient.getString("htmlManagerServlet.expire.unit");
                 args[13] = highlightColor;
                 
                 if (ctxt.getPath().equals(this.context.getPath())) {
@@ -581,41 +591,41 @@ public final class HTMLManagerServlet ex
 
         // Deploy Section
         args = new Object[7];
-        args[0] = sm.getString("htmlManagerServlet.deployTitle");
-        args[1] = sm.getString("htmlManagerServlet.deployServer");
+        args[0] = smClient.getString("htmlManagerServlet.deployTitle");
+        args[1] = smClient.getString("htmlManagerServlet.deployServer");
         args[2] = response.encodeURL(request.getContextPath() + "/html/deploy");
-        args[3] = sm.getString("htmlManagerServlet.deployPath");
-        args[4] = sm.getString("htmlManagerServlet.deployConfig");
-        args[5] = sm.getString("htmlManagerServlet.deployWar");
-        args[6] = sm.getString("htmlManagerServlet.deployButton");
+        args[3] = smClient.getString("htmlManagerServlet.deployPath");
+        args[4] = smClient.getString("htmlManagerServlet.deployConfig");
+        args[5] = smClient.getString("htmlManagerServlet.deployWar");
+        args[6] = smClient.getString("htmlManagerServlet.deployButton");
         writer.print(MessageFormat.format(DEPLOY_SECTION, args));
 
         args = new Object[4];
-        args[0] = sm.getString("htmlManagerServlet.deployUpload");
+        args[0] = smClient.getString("htmlManagerServlet.deployUpload");
         args[1] = response.encodeURL(request.getContextPath() + "/html/upload");
-        args[2] = sm.getString("htmlManagerServlet.deployUploadFile");
-        args[3] = sm.getString("htmlManagerServlet.deployButton");
+        args[2] = smClient.getString("htmlManagerServlet.deployUploadFile");
+        args[3] = smClient.getString("htmlManagerServlet.deployButton");
         writer.print(MessageFormat.format(UPLOAD_SECTION, args));
 
         // Diagnostics section
         args = new Object[5];
-        args[0] = sm.getString("htmlManagerServlet.diagnosticsTitle");
-        args[1] = sm.getString("htmlManagerServlet.diagnosticsLeak");
+        args[0] = smClient.getString("htmlManagerServlet.diagnosticsTitle");
+        args[1] = smClient.getString("htmlManagerServlet.diagnosticsLeak");
         args[2] = response.encodeURL(
                 request.getContextPath() + "/html/findleaks");
-        args[3] = sm.getString("htmlManagerServlet.diagnosticsLeakWarning");
-        args[4] = sm.getString("htmlManagerServlet.diagnosticsLeakButton");
+        args[3] = smClient.getString("htmlManagerServlet.diagnosticsLeakWarning");
+        args[4] = smClient.getString("htmlManagerServlet.diagnosticsLeakButton");
         writer.print(MessageFormat.format(DIAGNOSTICS_SECTION, args));
 
         // Server Header Section
         args = new Object[7];
-        args[0] = sm.getString("htmlManagerServlet.serverTitle");
-        args[1] = sm.getString("htmlManagerServlet.serverVersion");
-        args[2] = sm.getString("htmlManagerServlet.serverJVMVersion");
-        args[3] = sm.getString("htmlManagerServlet.serverJVMVendor");
-        args[4] = sm.getString("htmlManagerServlet.serverOSName");
-        args[5] = sm.getString("htmlManagerServlet.serverOSVersion");
-        args[6] = sm.getString("htmlManagerServlet.serverOSArch");
+        args[0] = smClient.getString("htmlManagerServlet.serverTitle");
+        args[1] = smClient.getString("htmlManagerServlet.serverVersion");
+        args[2] = smClient.getString("htmlManagerServlet.serverJVMVersion");
+        args[3] = smClient.getString("htmlManagerServlet.serverJVMVendor");
+        args[4] = smClient.getString("htmlManagerServlet.serverOSName");
+        args[5] = smClient.getString("htmlManagerServlet.serverOSVersion");
+        args[6] = smClient.getString("htmlManagerServlet.serverOSArch");
         writer.print(MessageFormat.format
                      (Constants.SERVER_HEADER_SECTION, args));
 
@@ -645,12 +655,12 @@ public final class HTMLManagerServlet ex
      * @param path Context path of the application to be restarted
      * @return message String
      */
-    protected String reload(String path) {
+    protected String reload(String path, StringManager smClient) {
 
         StringWriter stringWriter = new StringWriter();
         PrintWriter printWriter = new PrintWriter(stringWriter);
 
-        super.reload(printWriter, path);
+        super.reload(printWriter, path, smClient);
 
         return stringWriter.toString();
     }
@@ -663,12 +673,12 @@ public final class HTMLManagerServlet ex
      * @param path Context path of the application to be undeployed
      * @return message String
      */
-    protected String undeploy(String path) {
+    protected String undeploy(String path, StringManager smClient) {
 
         StringWriter stringWriter = new StringWriter();
         PrintWriter printWriter = new PrintWriter(stringWriter);
 
-        super.undeploy(printWriter, path);
+        super.undeploy(printWriter, path, smClient);
 
         return stringWriter.toString();
     }
@@ -682,12 +692,12 @@ public final class HTMLManagerServlet ex
      * @param idle Expire all sessions with idle time &ge; idle for this context
      * @return message String
      */
-    public String sessions(String path, int idle) {
+    public String sessions(String path, int idle, StringManager smClient) {
 
         StringWriter stringWriter = new StringWriter();
         PrintWriter printWriter = new PrintWriter(stringWriter);
 
-        super.sessions(printWriter, path, idle);
+        super.sessions(printWriter, path, idle, smClient);
 
         return stringWriter.toString();
     }
@@ -700,9 +710,9 @@ public final class HTMLManagerServlet ex
      * @param path Context path of the application to list session information
      * @return message String
      */
-    public String sessions(String path) {
+    public String sessions(String path, StringManager smClient) {
 
-        return sessions(path, -1);
+        return sessions(path, -1, smClient);
     }
 
     /**
@@ -713,12 +723,12 @@ public final class HTMLManagerServlet ex
      * @param path Context path of the application to be started
      * @return message String
      */
-    public String start(String path) {
+    public String start(String path, StringManager smClient) {
 
         StringWriter stringWriter = new StringWriter();
         PrintWriter printWriter = new PrintWriter(stringWriter);
 
-        super.start(printWriter, path);
+        super.start(printWriter, path, smClient);
 
         return stringWriter.toString();
     }
@@ -731,12 +741,12 @@ public final class HTMLManagerServlet ex
      * @param path Context path of the application to be stopped
      * @return message String
      */
-    protected String stop(String path) {
+    protected String stop(String path, StringManager smClient) {
 
         StringWriter stringWriter = new StringWriter();
         PrintWriter printWriter = new PrintWriter(stringWriter);
 
-        super.stop(printWriter, path);
+        super.stop(printWriter, path, smClient);
 
         return stringWriter.toString();
     }
@@ -748,20 +758,20 @@ public final class HTMLManagerServlet ex
      *
      * @return message String
      */
-    protected String findleaks() {
+    protected String findleaks(StringManager smClient) {
 
         StringBuilder msg = new StringBuilder();
 
         StringWriter stringWriter = new StringWriter();
         PrintWriter printWriter = new PrintWriter(stringWriter);
 
-        super.findleaks(printWriter);
+        super.findleaks(printWriter, smClient);
 
         if (stringWriter.getBuffer().length() > 0) {
-            msg.append(sm.getString("htmlManagerServlet.findleaksList"));
+            msg.append(smClient.getString("htmlManagerServlet.findleaksList"));
             msg.append(stringWriter.toString());
         } else {
-            msg.append(sm.getString("htmlManagerServlet.findleaksNone"));
+            msg.append(smClient.getString("htmlManagerServlet.findleaksNone"));
         }
         
         return msg.toString();
@@ -798,7 +808,8 @@ public final class HTMLManagerServlet ex
      * @param path
      * @param req
      */
-    protected String expireSessions(String path, HttpServletRequest req) {
+    protected String expireSessions(String path, HttpServletRequest req,
+            StringManager smClient) {
         int idle = -1;
         String idleParam = req.getParameter("idle");
         if (idleParam != null) {
@@ -808,7 +819,7 @@ public final class HTMLManagerServlet ex
                 log("Could not parse idle parameter to an int: " + idleParam);
             }
         }
-        return sessions(path, idle);
+        return sessions(path, idle, smClient);
     }
 
     /**
@@ -818,7 +829,9 @@ public final class HTMLManagerServlet ex
      * @throws ServletException
      * @throws IOException 
      */
-    protected void doSessions(String path, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+    protected void doSessions(String path, HttpServletRequest req,
+            HttpServletResponse resp, StringManager smClient)
+            throws ServletException, IOException {
         req.setAttribute("path", path);
         String action = req.getParameter("action");
         if (debug >= 1) {
@@ -826,36 +839,38 @@ public final class HTMLManagerServlet ex
         }
         if ("sessionDetail".equals(action)) {
             String sessionId = req.getParameter("sessionId");
-            displaySessionDetailPage(req, resp, path, sessionId);
+            displaySessionDetailPage(req, resp, path, sessionId, smClient);
             return;
         } else if ("invalidateSessions".equals(action)) {
             String[] sessionIds = req.getParameterValues("sessionIds");
-            int i = invalidateSessions(path, sessionIds);
+            int i = invalidateSessions(path, sessionIds, smClient);
             req.setAttribute(APPLICATION_MESSAGE, "" + i + " sessions invalidated.");
         } else if ("removeSessionAttribute".equals(action)) {
             String sessionId = req.getParameter("sessionId");
             String name = req.getParameter("attributeName");
-            boolean removed = removeSessionAttribute(path, sessionId, name);
+            boolean removed =
+                removeSessionAttribute(path, sessionId, name, smClient);
             String outMessage = removed ? "Session attribute '" + name + "' removed." : "Session did not contain any attribute named '" + name + "'";
             req.setAttribute(APPLICATION_MESSAGE, outMessage);
             resp.sendRedirect(resp.encodeRedirectURL(req.getRequestURL().append("?path=").append(path).append("&action=sessionDetail&sessionId=").append(sessionId).toString()));
             return;
         } // else
-        displaySessionsListPage(path, req, resp);
+        displaySessionsListPage(path, req, resp, smClient);
     }
 
-    protected List<Session> getSessionsForPath(String path) {
+    protected List<Session> getSessionsForPath(String path,
+            StringManager smClient) {
         if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
-            throw new IllegalArgumentException(sm.getString("managerServlet.invalidPath",
-                                        RequestUtil.filter(path)));
+            throw new IllegalArgumentException(smClient.getString(
+                    "managerServlet.invalidPath", RequestUtil.filter(path)));
         }
         String searchPath = path;
         if( path.equals("/") )
             searchPath = "";
         Context ctxt = (Context) host.findChild(searchPath);
         if (null == ctxt) {
-            throw new IllegalArgumentException(sm.getString("managerServlet.noContext",
-                                        RequestUtil.filter(path)));
+            throw new IllegalArgumentException(smClient.getString(
+                    "managerServlet.noContext", RequestUtil.filter(path)));
         }
         Manager manager = ctxt.getManager();
         List<Session> sessions = new ArrayList<Session>();
@@ -875,18 +890,19 @@ public final class HTMLManagerServlet ex
         }
         return sessions;
     }
-    protected Session getSessionForPathAndId(String path, String id) throws IOException {
+    protected Session getSessionForPathAndId(String path, String id,
+            StringManager smClient) throws IOException {
         if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
-            throw new IllegalArgumentException(sm.getString("managerServlet.invalidPath",
-                                        RequestUtil.filter(path)));
+            throw new IllegalArgumentException(smClient.getString(
+                    "managerServlet.invalidPath", RequestUtil.filter(path)));
         }
         String searchPath = path;
         if( path.equals("/") )
             searchPath = "";
         Context ctxt = (Context) host.findChild(searchPath);
         if (null == ctxt) {
-            throw new IllegalArgumentException(sm.getString("managerServlet.noContext",
-                                        RequestUtil.filter(path)));
+            throw new IllegalArgumentException(smClient.getString(
+                    "managerServlet.noContext", RequestUtil.filter(path)));
         }
         Session session = ctxt.getManager().findSession(id);
         return session;
@@ -899,8 +915,10 @@ public final class HTMLManagerServlet ex
      * @throws ServletException
      * @throws IOException
      */
-    protected void displaySessionsListPage(String path, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
-        List<Session> sessions = getSessionsForPath(path);
+    protected void displaySessionsListPage(String path, HttpServletRequest req,
+            HttpServletResponse resp, StringManager smClient)
+            throws ServletException, IOException {
+        List<Session> sessions = getSessionsForPath(path, smClient);
         String sortBy = req.getParameter("sort");
         String orderBy = null;
         if (null != sortBy && !"".equals(sortBy.trim())) {
@@ -943,8 +961,10 @@ public final class HTMLManagerServlet ex
      * @throws ServletException
      * @throws IOException
      */
-    protected void displaySessionDetailPage(HttpServletRequest req, HttpServletResponse resp, String path, String sessionId) throws ServletException, IOException {
-        Session session = getSessionForPathAndId(path, sessionId);
+    protected void displaySessionDetailPage(HttpServletRequest req,
+            HttpServletResponse resp, String path, String sessionId,
+            StringManager smClient) throws ServletException, IOException {
+        Session session = getSessionForPathAndId(path, sessionId, smClient);
         //strong>NOTE</strong> - This header will be overridden
         // automatically if a <code>RequestDispatcher.forward()</code> call is
         // ultimately invoked.
@@ -961,14 +981,15 @@ public final class HTMLManagerServlet ex
      * @return number of invalidated sessions
      * @throws IOException 
      */
-    public int invalidateSessions(String path, String[] sessionIds) throws IOException {
+    public int invalidateSessions(String path, String[] sessionIds,
+            StringManager smClient) throws IOException {
         if (null == sessionIds) {
             return 0;
         }
         int nbAffectedSessions = 0;
         for (int i = 0; i < sessionIds.length; ++i) {
             String sessionId = sessionIds[i];
-            HttpSession session = getSessionForPathAndId(path, sessionId).getSession();
+            HttpSession session = getSessionForPathAndId(path, sessionId, smClient).getSession();
             if (null == session) {
                 // Shouldn't happen, but let's play nice...
                 if (debug >= 1) {
@@ -998,8 +1019,9 @@ public final class HTMLManagerServlet ex
      * @return true if there was an attribute removed, false otherwise
      * @throws IOException 
      */
-    public boolean removeSessionAttribute(String path, String sessionId, String attributeName) throws IOException {
-        HttpSession session = getSessionForPathAndId(path, sessionId).getSession();
+    public boolean removeSessionAttribute(String path, String sessionId,
+            String attributeName, StringManager smClient) throws IOException {
+        HttpSession session = getSessionForPathAndId(path, sessionId, smClient).getSession();
         if (null == session) {
             // Shouldn't happen, but let's play nice...
             if (debug >= 1) {
@@ -1025,8 +1047,9 @@ public final class HTMLManagerServlet ex
      * @return old value for maxInactiveInterval
      * @throws IOException 
      */
-    public int setSessionMaxInactiveInterval(String path, String sessionId, int maxInactiveInterval) throws IOException {
-        HttpSession session = getSessionForPathAndId(path, sessionId).getSession();
+    public int setSessionMaxInactiveInterval(String path, String sessionId,
+            int maxInactiveInterval, StringManager smClient) throws IOException {
+        HttpSession session = getSessionForPathAndId(path, sessionId, smClient).getSession();
         if (null == session) {
             // Shouldn't happen, but let's play nice...
             if (debug >= 1) {

Modified: tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java?rev=1023361&r1=1023360&r2=1023361&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java Sat Oct 16 19:31:37 2010
@@ -25,7 +25,9 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.Enumeration;
 import java.util.Iterator;
+import java.util.Locale;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -316,6 +318,8 @@ public class ManagerServlet
                       HttpServletResponse response)
         throws IOException, ServletException {
 
+        StringManager smClient = getStringManager(request);
+
         // Identify the request parameters that we need
         String command = request.getPathInfo();
         if (command == null)
@@ -337,40 +341,40 @@ public class ManagerServlet
 
         // Process the requested command (note - "/deploy" is not listed here)
         if (command == null) {
-            writer.println(sm.getString("managerServlet.noCommand"));
+            writer.println(smClient.getString("managerServlet.noCommand"));
         } else if (command.equals("/deploy")) {
             if (war != null || config != null) {
-                deploy(writer, config, path, war, update);
+                deploy(writer, config, path, war, update, smClient);
             } else {
-                deploy(writer, path, tag);
+                deploy(writer, path, tag, smClient);
             }
         } else if (command.equals("/list")) {
-            list(writer);
+            list(writer, smClient);
         } else if (command.equals("/reload")) {
-            reload(writer, path);
+            reload(writer, path, smClient);
         } else if (command.equals("/resources")) {
-            resources(writer, type);
+            resources(writer, type, smClient);
         } else if (command.equals("/roles")) {
-            roles(writer);
+            roles(writer, smClient);
         } else if (command.equals("/save")) {
-            save(writer, path);
+            save(writer, path, smClient);
         } else if (command.equals("/serverinfo")) {
-            serverinfo(writer);
+            serverinfo(writer, smClient);
         } else if (command.equals("/sessions")) {
-            expireSessions(writer, path, request);
+            expireSessions(writer, path, request, smClient);
         } else if (command.equals("/expire")) {
-            expireSessions(writer, path, request);
+            expireSessions(writer, path, request, smClient);
         } else if (command.equals("/start")) {
-            start(writer, path);
+            start(writer, path, smClient);
         } else if (command.equals("/stop")) {
-            stop(writer, path);
+            stop(writer, path, smClient);
         } else if (command.equals("/undeploy")) {
-            undeploy(writer, path);
+            undeploy(writer, path, smClient);
         } else if (command.equals("/findleaks")) {
-            findleaks(writer);
+            findleaks(writer, smClient);
         } else {
-            writer.println(sm.getString("managerServlet.unknownCommand",
-                                        command));
+            writer.println(smClient.getString("managerServlet.unknownCommand",
+                    command));
         }
 
         // Finish up the response
@@ -394,6 +398,8 @@ public class ManagerServlet
                       HttpServletResponse response)
         throws IOException, ServletException {
 
+        StringManager smClient = getStringManager(request);
+
         // Identify the request parameters that we need
         String command = request.getPathInfo();
         if (command == null)
@@ -412,12 +418,12 @@ public class ManagerServlet
 
         // Process the requested command
         if (command == null) {
-            writer.println(sm.getString("managerServlet.noCommand"));
+            writer.println(smClient.getString("managerServlet.noCommand"));
         } else if (command.equals("/deploy")) {
-            deploy(writer, path, tag, update, request);
+            deploy(writer, path, tag, update, request, smClient);
         } else {
-            writer.println(sm.getString("managerServlet.unknownCommand",
-                                        command));
+            writer.println(smClient.getString("managerServlet.unknownCommand",
+                    command));
         }
 
         // Finish up the response
@@ -435,8 +441,8 @@ public class ManagerServlet
 
         // Ensure that our ContainerServlet properties have been set
         if ((wrapper == null) || (context == null))
-            throw new UnavailableException
-                (sm.getString("managerServlet.noWrapper"));
+            throw new UnavailableException(
+                    sm.getString("managerServlet.noWrapper"));
 
         // Set our properties from the initialization parameters
         String value = null;
@@ -503,10 +509,10 @@ public class ManagerServlet
     /**
      * Find potential memory leaks caused by web application reload.
      */
-    protected void findleaks(PrintWriter writer) {
+    protected void findleaks(PrintWriter writer, StringManager smClient) {
         
         if (!(host instanceof StandardHost)) {
-            writer.println(sm.getString("managerServlet.findleaksFail"));
+            writer.println(smClient.getString("managerServlet.findleaksFail"));
             return;
         }
         
@@ -527,23 +533,25 @@ public class ManagerServlet
      * 
      * @param path Optional context path to save
      */
-    protected synchronized void save(PrintWriter writer, String path) {
+    protected synchronized void save(PrintWriter writer, String path,
+            StringManager smClient) {
 
         Server server = ((Engine)host.getParent()).getService().getServer();
 
         if (!(server instanceof StandardServer)) {
-            writer.println(sm.getString("managerServlet.saveFail", server));
+            writer.println(smClient.getString("managerServlet.saveFail",
+                    server));
             return;
         }
 
         if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
             try {
                 ((StandardServer) server).storeConfig();
-                writer.println(sm.getString("managerServlet.saved"));
+                writer.println(smClient.getString("managerServlet.saved"));
             } catch (Exception e) {
                 log("managerServlet.storeConfig", e);
-                writer.println(sm.getString("managerServlet.exception",
-                                            e.toString()));
+                writer.println(smClient.getString("managerServlet.exception",
+                        e.toString()));
                 return;
             }
         } else {
@@ -553,17 +561,18 @@ public class ManagerServlet
             }
             Context context = (Context) host.findChild(contextPath);
             if (context == null) {
-                writer.println(sm.getString("managerServlet.noContext", path));
+                writer.println(smClient.getString("managerServlet.noContext",
+                        path));
                 return;
             }
             try {
                 ((StandardServer) server).storeContext(context);
-                writer.println(sm.getString("managerServlet.savedContext", 
-                               path));
+                writer.println(smClient.getString("managerServlet.savedContext",
+                        path));
             } catch (Exception e) {
                 log("managerServlet.save[" + path + "]", e);
-                writer.println(sm.getString("managerServlet.exception",
-                                            e.toString()));
+                writer.println(smClient.getString("managerServlet.exception",
+                        e.toString()));
                 return;
             }
         }
@@ -582,7 +591,8 @@ public class ManagerServlet
      */
     protected synchronized void deploy
         (PrintWriter writer, String path,
-         String tag, boolean update, HttpServletRequest request) {
+         String tag, boolean update, HttpServletRequest request,
+         StringManager smClient) {
 
         if (debug >= 1) {
             log("deploy: Deploying web application at '" + path + "'");
@@ -590,7 +600,8 @@ public class ManagerServlet
 
         // Validate the requested context path
         if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
-            writer.println(sm.getString("managerServlet.invalidPath", path));
+            writer.println(smClient.getString(
+                    "managerServlet.invalidPath", path));
             return;
         }
         String displayPath = path;
@@ -602,14 +613,13 @@ public class ManagerServlet
         Context context = (Context) host.findChild(path);
         if (update) {
             if (context != null) {
-                undeploy(writer, displayPath);
+                undeploy(writer, displayPath, smClient);
             }
             context = (Context) host.findChild(path);
         }
         if (context != null) {
-            writer.println
-                (sm.getString("managerServlet.alreadyContext",
-                              displayPath));
+            writer.println(smClient.getString("managerServlet.alreadyContext",
+                    displayPath));
             return;
         }
 
@@ -649,17 +659,19 @@ public class ManagerServlet
             }
         } catch (Exception e) {
             log("managerServlet.check[" + displayPath + "]", e);
-            writer.println(sm.getString("managerServlet.exception",
-                                        e.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    e.toString()));
             return;
         }
         
         context = (Context) host.findChild(path);
         if (context != null && context.getConfigured()) {
-            writer.println(sm.getString("managerServlet.deployed", displayPath));
+            writer.println(smClient.getString(
+                    "managerServlet.deployed", displayPath));
         } else {
             // Something failed
-            writer.println(sm.getString("managerServlet.deployFailed", displayPath));
+            writer.println(smClient.getString(
+                    "managerServlet.deployFailed", displayPath));
         }
         
     }
@@ -673,11 +685,13 @@ public class ManagerServlet
      * @param tag Revision tag to deploy from
      * @param path Context path of the application to be installed
      */
-    protected void deploy(PrintWriter writer, String path, String tag) {
+    protected void deploy(PrintWriter writer, String path, String tag,
+            StringManager smClient) {
 
         // Validate the requested context path
         if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
-            writer.println(sm.getString("managerServlet.invalidPath", path));
+            writer.println(smClient.getString(
+                    "managerServlet.invalidPath", path));
             return;
         }
         String displayPath = path;
@@ -696,7 +710,7 @@ public class ManagerServlet
         // Check if app already exists, or undeploy it if updating
         Context context = (Context) host.findChild(path);
         if (context != null) {
-            undeploy(writer, displayPath);
+            undeploy(writer, displayPath, smClient);
         }
 
         // Copy WAR to appBase
@@ -713,17 +727,19 @@ public class ManagerServlet
             }
         } catch (Exception e) {
             log("managerServlet.check[" + displayPath + "]", e);
-            writer.println(sm.getString("managerServlet.exception",
-                                        e.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    e.toString()));
             return;
         }
         
         context = (Context) host.findChild(path);
         if (context != null && context.getConfigured()) {
-            writer.println(sm.getString("managerServlet.deployed", displayPath));
+            writer.println(smClient.getString("managerServlet.deployed",
+                    displayPath));
         } else {
             // Something failed
-            writer.println(sm.getString("managerServlet.deployFailed", displayPath));
+            writer.println(smClient.getString("managerServlet.deployFailed",
+                    displayPath));
         }
         
     }
@@ -740,7 +756,7 @@ public class ManagerServlet
      * @param update true to override any existing webapp on the path
      */
     protected void deploy(PrintWriter writer, String config,
-            String path, String war, boolean update) {
+            String path, String war, boolean update,  StringManager smClient) {
         
         if (config != null && config.length() == 0) {
             config = null;
@@ -769,8 +785,8 @@ public class ManagerServlet
         }
         
         if (path == null || path.length() == 0 || !path.startsWith("/")) {
-            writer.println(sm.getString("managerServlet.invalidPath",
-                                        RequestUtil.filter(path)));
+            writer.println(smClient.getString("managerServlet.invalidPath",
+                    RequestUtil.filter(path)));
             return;
         }
         String displayPath = path;
@@ -782,13 +798,12 @@ public class ManagerServlet
         Context context = (Context) host.findChild(path);
         if (update) {
             if (context != null) {
-                undeploy(writer, displayPath);
+                undeploy(writer, displayPath, smClient);
             }
             context = (Context) host.findChild(path);
         }
         if (context != null) {
-            writer.println
-            (sm.getString("managerServlet.alreadyContext",
+            writer.println(smClient.getString("managerServlet.alreadyContext",
                     displayPath));
             return;
         }
@@ -826,17 +841,20 @@ public class ManagerServlet
             }
             context = (Context) host.findChild(path);
             if (context != null && context.getConfigured() && context.getAvailable()) {
-                writer.println(sm.getString("managerServlet.deployed", displayPath));
+                writer.println(smClient.getString(
+                        "managerServlet.deployed", displayPath));
             } else if (context!=null && !context.getAvailable()) {
-                writer.println(sm.getString("managerServlet.deployedButNotStarted", displayPath));
+                writer.println(smClient.getString(
+                        "managerServlet.deployedButNotStarted", displayPath));
             } else {
                 // Something failed
-                writer.println(sm.getString("managerServlet.deployFailed", displayPath));
+                writer.println(smClient.getString(
+                        "managerServlet.deployFailed", displayPath));
             }
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             log("ManagerServlet.install[" + displayPath + "]", t);
-            writer.println(sm.getString("managerServlet.exception",
+            writer.println(smClient.getString("managerServlet.exception",
                     t.toString()));
         }
         
@@ -848,13 +866,13 @@ public class ManagerServlet
      *
      * @param writer Writer to render to
      */
-    protected void list(PrintWriter writer) {
+    protected void list(PrintWriter writer, StringManager smClient) {
 
         if (debug >= 1)
             log("list: Listing contexts for virtual host '" +
                 host.getName() + "'");
 
-        writer.println(sm.getString("managerServlet.listed",
+        writer.println(smClient.getString("managerServlet.listed",
                                     host.getName()));
         Container[] contexts = host.findChildren();
         for (int i = 0; i < contexts.length; i++) {
@@ -864,17 +882,17 @@ public class ManagerServlet
                 if( displayPath.equals("") )
                     displayPath = "/";
                 if (context.getAvailable()) {
-                    writer.println(sm.getString("managerServlet.listitem",
-                                                displayPath,
-                                                "running",
-                                      "" + context.getManager().findSessions().length,
-                                                context.getDocBase()));
+                    writer.println(smClient.getString("managerServlet.listitem",
+                            displayPath,
+                            "running",
+                            "" + context.getManager().findSessions().length,
+                            context.getDocBase()));
                 } else {
-                    writer.println(sm.getString("managerServlet.listitem",
-                                                displayPath,
-                                                "stopped",
-                                                "0",
-                                                context.getDocBase()));
+                    writer.println(smClient.getString("managerServlet.listitem",
+                            displayPath,
+                            "stopped",
+                            "0",
+                            context.getDocBase()));
                 }
             }
         }
@@ -887,14 +905,15 @@ public class ManagerServlet
      * @param writer Writer to render to
      * @param path Context path of the application to be restarted
      */
-    protected void reload(PrintWriter writer, String path) {
+    protected void reload(PrintWriter writer, String path,
+            StringManager smClient) {
 
         if (debug >= 1)
             log("restart: Reloading web application at '" + path + "'");
 
         if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
-            writer.println(sm.getString("managerServlet.invalidPath",
-                                        RequestUtil.filter(path)));
+            writer.println(smClient.getString("managerServlet.invalidPath",
+                    RequestUtil.filter(path)));
             return;
         }
         String displayPath = path;
@@ -904,24 +923,23 @@ public class ManagerServlet
         try {
             Context context = (Context) host.findChild(path);
             if (context == null) {
-                writer.println(sm.getString
-                               ("managerServlet.noContext",
-                                   RequestUtil.filter(displayPath)));
+                writer.println(smClient.getString("managerServlet.noContext",
+                        RequestUtil.filter(displayPath)));
                 return;
             }
             // It isn't possible for the manager to reload itself
             if (context.getPath().equals(this.context.getPath())) {
-                writer.println(sm.getString("managerServlet.noSelf"));
+                writer.println(smClient.getString("managerServlet.noSelf"));
                 return;
             }
             context.reload();
             writer.println
-                (sm.getString("managerServlet.reloaded", displayPath));
+                (smClient.getString("managerServlet.reloaded", displayPath));
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             log("ManagerServlet.reload[" + displayPath + "]", t);
-            writer.println(sm.getString("managerServlet.exception",
-                                        t.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    t.toString()));
         }
 
     }
@@ -933,7 +951,8 @@ public class ManagerServlet
      * @param type Fully qualified class name of the resource type of interest,
      *  or <code>null</code> to list resources of all types
      */
-    protected void resources(PrintWriter writer, String type) {
+    protected void resources(PrintWriter writer, String type,
+            StringManager smClient) {
 
         if (debug >= 1) {
             if (type != null) {
@@ -945,16 +964,16 @@ public class ManagerServlet
 
         // Is the global JNDI resources context available?
         if (global == null) {
-            writer.println(sm.getString("managerServlet.noGlobal"));
+            writer.println(smClient.getString("managerServlet.noGlobal"));
             return;
         }
 
         // Enumerate the global JNDI resources of the requested type
         if (type != null) {
-            writer.println(sm.getString("managerServlet.resourcesType",
-                                        type));
+            writer.println(smClient.getString("managerServlet.resourcesType",
+                    type));
         } else {
-            writer.println(sm.getString("managerServlet.resourcesAll"));
+            writer.println(smClient.getString("managerServlet.resourcesAll"));
         }
 
         Class<?> clazz = null;
@@ -965,12 +984,12 @@ public class ManagerServlet
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             log("ManagerServlet.resources[" + type + "]", t);
-            writer.println(sm.getString("managerServlet.exception",
-                                        t.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    t.toString()));
             return;
         }
 
-        printResources(writer, "", global, type, clazz);
+        printResources(writer, "", global, type, clazz, smClient);
 
     }
 
@@ -980,7 +999,8 @@ public class ManagerServlet
      */
     protected void printResources(PrintWriter writer, String prefix,
                                   javax.naming.Context namingContext,
-                                  String type, Class<?> clazz) {
+                                  String type, Class<?> clazz,
+                                  StringManager smClient) {
 
         try {
             NamingEnumeration<Binding> items = namingContext.listBindings("");
@@ -989,7 +1009,8 @@ public class ManagerServlet
                 if (item.getObject() instanceof javax.naming.Context) {
                     printResources
                         (writer, prefix + item.getName() + "/",
-                         (javax.naming.Context) item.getObject(), type, clazz);
+                         (javax.naming.Context) item.getObject(), type, clazz,
+                         smClient);
                 } else {
                     if ((clazz != null) &&
                         (!(clazz.isInstance(item.getObject())))) {
@@ -1005,8 +1026,8 @@ public class ManagerServlet
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             log("ManagerServlet.resources[" + type + "]", t);
-            writer.println(sm.getString("managerServlet.exception",
-                                        t.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    t.toString()));
         }
 
     }
@@ -1021,7 +1042,7 @@ public class ManagerServlet
      *
      * @param writer Writer to render to
      */
-    protected void roles(PrintWriter writer) {
+    protected void roles(PrintWriter writer,  StringManager smClient) {
 
         if (debug >= 1) {
             log("roles:  List security roles from user database");
@@ -1033,17 +1054,19 @@ public class ManagerServlet
             InitialContext ic = new InitialContext();
             database = (UserDatabase) ic.lookup("java:comp/env/users");
         } catch (NamingException e) {
-            writer.println(sm.getString("managerServlet.userDatabaseError"));
+            writer.println(smClient.getString(
+                    "managerServlet.userDatabaseError"));
             log("java:comp/env/users", e);
             return;
         }
         if (database == null) {
-            writer.println(sm.getString("managerServlet.userDatabaseMissing"));
+            writer.println(smClient.getString(
+                    "managerServlet.userDatabaseMissing"));
             return;
         }
 
         // Enumerate the available roles
-        writer.println(sm.getString("managerServlet.rolesList"));
+        writer.println(smClient.getString("managerServlet.rolesList"));
         Iterator<Role> roles = database.getRoles();
         if (roles != null) {
             while (roles.hasNext()) {
@@ -1065,7 +1088,7 @@ public class ManagerServlet
      * Writes System OS and JVM properties.
      * @param writer Writer to render to
      */
-    protected void serverinfo(PrintWriter writer) {
+    protected void serverinfo(PrintWriter writer,  StringManager smClient) {
         if (debug >= 1)
             log("serverinfo");
         try {
@@ -1087,8 +1110,8 @@ public class ManagerServlet
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             getServletContext().log("ManagerServlet.serverinfo",t);
-            writer.println(sm.getString("managerServlet.exception",
-                                        t.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    t.toString()));
         }
     }
 
@@ -1101,7 +1124,8 @@ public class ManagerServlet
      * @param path Context path of the application to list session information for
      * @param idle Expire all sessions with idle time &gt; idle for this context
      */
-    protected void sessions(PrintWriter writer, String path, int idle) {
+    protected void sessions(PrintWriter writer, String path, int idle,
+            StringManager smClient) {
 
         if (debug >= 1) {
             log("sessions: Session information for web application at '" + path + "'");
@@ -1110,8 +1134,8 @@ public class ManagerServlet
         }
 
         if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
-            writer.println(sm.getString("managerServlet.invalidPath",
-                                        RequestUtil.filter(path)));
+            writer.println(smClient.getString("managerServlet.invalidPath",
+                    RequestUtil.filter(path)));
             return;
         }
         String displayPath = path;
@@ -1120,13 +1144,13 @@ public class ManagerServlet
         try {
             Context context = (Context) host.findChild(path);
             if (context == null) {
-                writer.println(sm.getString("managerServlet.noContext",
-                                            RequestUtil.filter(displayPath)));
+                writer.println(smClient.getString("managerServlet.noContext",
+                        RequestUtil.filter(displayPath)));
                 return;
             }
             Manager manager = context.getManager() ;
             if(manager == null) {
-                writer.println(sm.getString("managerServlet.noManager",
+                writer.println(smClient.getString("managerServlet.noManager",
                         RequestUtil.filter(displayPath)));
                 return;               
             }
@@ -1141,9 +1165,11 @@ public class ManagerServlet
             if ( histoInterval * maxCount < maxInactiveInterval ) 
                 maxCount++;
 
-            writer.println(sm.getString("managerServlet.sessions", displayPath));
-            writer.println(sm.getString("managerServlet.sessiondefaultmax",
-                                "" + maxInactiveInterval));
+            writer.println(smClient.getString("managerServlet.sessions",
+                    displayPath));
+            writer.println(smClient.getString(
+                    "managerServlet.sessiondefaultmax",
+                    "" + maxInactiveInterval));
             Session [] sessions = manager.findSessions();
             int [] timeout = new int[maxCount];
             int notimeout = 0;
@@ -1164,29 +1190,34 @@ public class ManagerServlet
                     timeout[time]++;
             }
             if (timeout[0] > 0)
-                writer.println(sm.getString("managerServlet.sessiontimeout",
-                                            "<" + histoInterval, "" + timeout[0]));
+                writer.println(smClient.getString(
+                        "managerServlet.sessiontimeout",
+                        "<" + histoInterval, "" + timeout[0]));
             for (int i = 1; i < maxCount-1; i++) {
                 if (timeout[i] > 0)
-                    writer.println(sm.getString("managerServlet.sessiontimeout",
-                                     "" + (i)*histoInterval + " - <" + (i+1)*histoInterval,
-                                                "" + timeout[i]));
+                    writer.println(smClient.getString(
+                            "managerServlet.sessiontimeout",
+                            "" + (i)*histoInterval + " - <" + (i+1)*histoInterval,
+                            "" + timeout[i]));
             }
             if (timeout[maxCount-1] > 0)
-                writer.println(sm.getString("managerServlet.sessiontimeout",
-                                            ">=" + maxCount*histoInterval,
-                                            "" + timeout[maxCount-1]));
+                writer.println(smClient.getString(
+                        "managerServlet.sessiontimeout",
+                        ">=" + maxCount*histoInterval,
+                        "" + timeout[maxCount-1]));
             if (notimeout > 0)
-                writer.println(sm.getString("managerServlet.sessiontimeout.unlimited",
-                                            "" + notimeout));
+                writer.println(smClient.getString(
+                        "managerServlet.sessiontimeout.unlimited",
+                        "" + notimeout));
             if (idle >= 0)
-                writer.println(sm.getString("managerServlet.sessiontimeout.expired",
-                                            "" + idle,"" + expired));
+                writer.println(smClient.getString(
+                        "managerServlet.sessiontimeout.expired",
+                        "" + idle,"" + expired));
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             log("ManagerServlet.sessions[" + displayPath + "]", t);
-            writer.println(sm.getString("managerServlet.exception",
-                                        t.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    t.toString()));
         }
 
     }
@@ -1200,8 +1231,9 @@ public class ManagerServlet
      * @param writer Writer to render to
      * @param path Context path of the application to list session information for
      */
-    protected void sessions(PrintWriter writer, String path) {
-        sessions(writer, path, -1);
+    protected void sessions(PrintWriter writer, String path,
+            StringManager smClient) {
+        sessions(writer, path, -1, smClient);
     }
 
 
@@ -1212,7 +1244,8 @@ public class ManagerServlet
      * @param path
      * @param req
      */
-    protected void expireSessions(PrintWriter writer, String path, HttpServletRequest req) {
+    protected void expireSessions(PrintWriter writer, String path,
+            HttpServletRequest req, StringManager smClient) {
         int idle = -1;
         String idleParam = req.getParameter("idle");
         if (idleParam != null) {
@@ -1222,7 +1255,7 @@ public class ManagerServlet
                 log("Could not parse idle parameter to an int: " + idleParam);
             }
         }
-        sessions(writer, path, idle);
+        sessions(writer, path, idle, smClient);
     }
 
     /**
@@ -1231,14 +1264,15 @@ public class ManagerServlet
      * @param writer Writer to render to
      * @param path Context path of the application to be started
      */
-    protected void start(PrintWriter writer, String path) {
+    protected void start(PrintWriter writer, String path,
+            StringManager smClient) {
 
         if (debug >= 1)
             log("start: Starting web application at '" + path + "'");
 
         if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
-            writer.println(sm.getString("managerServlet.invalidPath",
-                                        RequestUtil.filter(path)));
+            writer.println(smClient.getString("managerServlet.invalidPath",
+                    RequestUtil.filter(path)));
             return;
         }
         String displayPath = path;
@@ -1248,25 +1282,25 @@ public class ManagerServlet
         try {
             Context context = (Context) host.findChild(path);
             if (context == null) {
-                writer.println(sm.getString("managerServlet.noContext", 
-                                            RequestUtil.filter(displayPath)));
+                writer.println(smClient.getString("managerServlet.noContext", 
+                        RequestUtil.filter(displayPath)));
                 return;
             }
             context.start();
             if (context.getAvailable())
-                writer.println
-                    (sm.getString("managerServlet.started", displayPath));
+                writer.println(smClient.getString("managerServlet.started",
+                        displayPath));
             else
-                writer.println
-                    (sm.getString("managerServlet.startFailed", displayPath));
+                writer.println(smClient.getString("managerServlet.startFailed",
+                        displayPath));
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
-            getServletContext().log
-                (sm.getString("managerServlet.startFailed", displayPath), t);
-            writer.println
-                (sm.getString("managerServlet.startFailed", displayPath));
-            writer.println(sm.getString("managerServlet.exception",
-                                        t.toString()));
+            getServletContext().log(sm.getString("managerServlet.startFailed",
+                    displayPath), t);
+            writer.println(smClient.getString("managerServlet.startFailed",
+                    displayPath));
+            writer.println(smClient.getString("managerServlet.exception",
+                    t.toString()));
         }
 
     }
@@ -1278,14 +1312,15 @@ public class ManagerServlet
      * @param writer Writer to render to
      * @param path Context path of the application to be stopped
      */
-    protected void stop(PrintWriter writer, String path) {
+    protected void stop(PrintWriter writer, String path,
+            StringManager smClient) {
 
         if (debug >= 1)
             log("stop: Stopping web application at '" + path + "'");
 
         if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
-            writer.println(sm.getString("managerServlet.invalidPath",
-                                        RequestUtil.filter(path)));
+            writer.println(smClient.getString("managerServlet.invalidPath",
+                    RequestUtil.filter(path)));
             return;
         }
         String displayPath = path;
@@ -1295,22 +1330,23 @@ public class ManagerServlet
         try {
             Context context = (Context) host.findChild(path);
             if (context == null) {
-                writer.println(sm.getString("managerServlet.noContext", 
-                                            RequestUtil.filter(displayPath)));
+                writer.println(smClient.getString("managerServlet.noContext",
+                        RequestUtil.filter(displayPath)));
                 return;
             }
             // It isn't possible for the manager to stop itself
             if (context.getPath().equals(this.context.getPath())) {
-                writer.println(sm.getString("managerServlet.noSelf"));
+                writer.println(smClient.getString("managerServlet.noSelf"));
                 return;
             }
             context.stop();
-            writer.println(sm.getString("managerServlet.stopped", displayPath));
+            writer.println(smClient.getString(
+                    "managerServlet.stopped", displayPath));
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             log("ManagerServlet.stop[" + displayPath + "]", t);
-            writer.println(sm.getString("managerServlet.exception",
-                                        t.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    t.toString()));
         }
 
     }
@@ -1322,14 +1358,15 @@ public class ManagerServlet
      * @param writer Writer to render to
      * @param path Context path of the application to be removed
      */
-    protected void undeploy(PrintWriter writer, String path) {
+    protected void undeploy(PrintWriter writer, String path,
+            StringManager smClient) {
 
         if (debug >= 1)
             log("undeploy: Undeploying web application at '" + path + "'");
 
         if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
-            writer.println(sm.getString("managerServlet.invalidPath",
-                                        RequestUtil.filter(path)));
+            writer.println(smClient.getString("managerServlet.invalidPath",
+                    RequestUtil.filter(path)));
             return;
         }
         String displayPath = path;
@@ -1341,13 +1378,13 @@ public class ManagerServlet
             // Validate the Context of the specified application
             Context context = (Context) host.findChild(path);
             if (context == null) {
-                writer.println(sm.getString("managerServlet.noContext",
-                                            RequestUtil.filter(displayPath)));
+                writer.println(smClient.getString("managerServlet.noContext",
+                        RequestUtil.filter(displayPath)));
                 return;
             }
 
             if (!isDeployed(path)) {
-                writer.println(sm.getString("managerServlet.notDeployed",
+                writer.println(smClient.getString("managerServlet.notDeployed",
                         RequestUtil.filter(displayPath)));
                 return;
             }
@@ -1380,13 +1417,13 @@ public class ManagerServlet
                     removeServiced(path.replace('#','/'));
                 }
             }
-            writer.println(sm.getString("managerServlet.undeployed",
-                                        displayPath));
+            writer.println(smClient.getString("managerServlet.undeployed",
+                    displayPath));
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             log("ManagerServlet.undeploy[" + displayPath + "]", t);
-            writer.println(sm.getString("managerServlet.exception",
-                                        t.toString()));
+            writer.println(smClient.getString("managerServlet.exception",
+                    t.toString()));
         }
 
     }
@@ -1588,6 +1625,21 @@ public class ManagerServlet
     }
 
 
+    protected StringManager getStringManager(HttpServletRequest req) {
+        Enumeration<Locale> requestedLocales = req.getLocales();
+        while (requestedLocales.hasMoreElements()) {
+            Locale locale = requestedLocales.nextElement();
+            StringManager result = StringManager.getManager(Constants.Package,
+                    locale);
+            if (result.getLocale().equals(locale)) {
+                return result;
+            }
+        }
+        // Return the default
+        return sm;
+    }
+
+
     /**
      * Copy the specified file or directory to the destination.
      *

Modified: tomcat/trunk/java/org/apache/tomcat/util/res/StringManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/res/StringManager.java?rev=1023361&r1=1023360&r2=1023361&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/res/StringManager.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/res/StringManager.java Sat Oct 16 19:31:37 2010
@@ -20,6 +20,7 @@ package org.apache.tomcat.util.res;
 import java.text.MessageFormat;
 import java.util.Hashtable;
 import java.util.Locale;
+import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
@@ -66,11 +67,11 @@ public class StringManager {
      *
      * @param packageName Name of package to create StringManager for.
      */
-    private StringManager(String packageName) {
+    private StringManager(String packageName, Locale locale) {
         String bundleName = packageName + ".LocalStrings";
         ResourceBundle bnd = null;
         try {
-            bnd = ResourceBundle.getBundle(bundleName, Locale.getDefault());
+            bnd = ResourceBundle.getBundle(bundleName, locale);
         } catch( MissingResourceException ex ) {
             // Try from the current loader (that's the case for trusted apps)
             // Should only be required if using a TC5 style classloader structure
@@ -78,8 +79,7 @@ public class StringManager {
             ClassLoader cl = Thread.currentThread().getContextClassLoader();
             if( cl != null ) {
                 try {
-                    bnd = ResourceBundle.getBundle(
-                            bundleName, Locale.getDefault(), cl);
+                    bnd = ResourceBundle.getBundle(bundleName, locale, cl);
                 } catch(MissingResourceException ex2) {
                     // Ignore
                 }
@@ -88,9 +88,9 @@ public class StringManager {
         bundle = bnd;
         // Get the actual locale, which may be different from the requested one
         if (bundle != null) {
-            locale = bundle.getLocale();
+            this.locale = bundle.getLocale();
         } else {
-            locale = null;
+            this.locale = null;
         }
     }
 
@@ -119,7 +119,8 @@ public class StringManager {
             }
         } catch(MissingResourceException mre) {
             //bad: shouldn't mask an exception the following way:
-            //   str = "[cannot find message associated with key '" + key + "' due to " + mre + "]";
+            //   str = "[cannot find message associated with key '" + key +
+            //         "' due to " + mre + "]";
             //     because it hides the fact that the String was missing
             //     from the calling code.
             //good: could just throw the exception (or wrap it in another)
@@ -152,12 +153,19 @@ public class StringManager {
         return mf.format(args, new StringBuffer(), null).toString();
     }
 
+    /**
+     * Identify the Locale this StringManager is associated with
+     */
+    public Locale getLocale() {
+        return locale;
+    }
+
     // --------------------------------------------------------------
     // STATIC SUPPORT METHODS
     // --------------------------------------------------------------
 
-    private static final Hashtable<String, StringManager> managers =
-        new Hashtable<String, StringManager>();
+    private static final Map<String, Map<Locale,StringManager>> managers =
+        new Hashtable<String, Map<Locale,StringManager>>();
 
     /**
      * Get the StringManager for a particular package. If a manager for
@@ -166,13 +174,33 @@ public class StringManager {
      *
      * @param packageName The package name
      */
-    public synchronized static final StringManager getManager(String packageName) {
-        StringManager mgr = managers.get(packageName);
+    public synchronized static final StringManager getManager(
+            String packageName) {
+        return getManager(packageName, Locale.getDefault());
+    }
+
+    /**
+     * Get the StringManager for a particular package and Locale. If a manager
+     * for a package/Locale combination already exists, it will be reused, else
+     * a new StringManager will be created and returned.
+     *
+     * @param packageName The package name
+     * @param locale      The Locale
+     */
+    public synchronized static final StringManager getManager(
+            String packageName, Locale locale) {
+
+        Map<Locale,StringManager> map = managers.get(packageName);
+        if (map == null) {
+            map = new Hashtable<Locale, StringManager>();
+            managers.put(packageName, map);
+        }
+        
+        StringManager mgr = map.get(locale);
         if (mgr == null) {
-            mgr = new StringManager(packageName);
-            managers.put(packageName, mgr);
+            mgr = new StringManager(packageName, locale);
+            map.put(locale, mgr);
         }
         return mgr;
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message