Author: markt Date: Thu Aug 15 14:25:30 2013 New Revision: 1514291 URL: http://svn.apache.org/r1514291 Log: Refactor to reduce code duplication
Modified: tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.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=1514291&r1=1514290&r2=1514291&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/manager/HTMLManagerServlet.java Thu Aug 15 14:25:30 2013 @@ -118,7 +118,8 @@ public final class HTMLManagerServlet ex HttpServletResponse response) throws IOException, ServletException { - StringManager smClient = getStringManager(request); + StringManager smClient = StringManager.getManager( + Constants.Package, request.getLocales()); // Identify the request parameters that we need // By obtaining the command from the pathInfo, per-command security can @@ -179,7 +180,8 @@ public final class HTMLManagerServlet ex HttpServletResponse response) throws IOException, ServletException { - StringManager smClient = getStringManager(request); + StringManager smClient = StringManager.getManager( + Constants.Package, request.getLocales()); // Identify the request parameters that we need // By obtaining the command from the pathInfo, per-command security can 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=1514291&r1=1514290&r2=1514291&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/manager/ManagerServlet.java Thu Aug 15 14:25:30 2013 @@ -306,7 +306,8 @@ public class ManagerServlet extends Http HttpServletResponse response) throws IOException, ServletException { - StringManager smClient = getStringManager(request); + StringManager smClient = StringManager.getManager( + Constants.Package, request.getLocales()); // Identify the request parameters that we need String command = request.getPathInfo(); @@ -399,7 +400,8 @@ public class ManagerServlet extends Http HttpServletResponse response) throws IOException, ServletException { - StringManager smClient = getStringManager(request); + StringManager smClient = StringManager.getManager( + Constants.Package, request.getLocales()); // Identify the request parameters that we need String command = request.getPathInfo(); @@ -1558,21 +1560,6 @@ public class ManagerServlet extends Http } - 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; - } - - protected static boolean validateContextName(ContextName cn, PrintWriter writer, StringManager sm) { Modified: tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java?rev=1514291&r1=1514290&r2=1514291&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/manager/host/HTMLHostManagerServlet.java Thu Aug 15 14:25:30 2013 @@ -80,7 +80,8 @@ public final class HTMLHostManagerServle HttpServletResponse response) throws IOException, ServletException { - StringManager smClient = getStringManager(request); + StringManager smClient = StringManager.getManager( + Constants.Package, request.getLocales()); // Identify the request parameters that we need String command = request.getPathInfo(); @@ -120,7 +121,8 @@ public final class HTMLHostManagerServle public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - StringManager smClient = getStringManager(request); + StringManager smClient = StringManager.getManager( + Constants.Package, request.getLocales()); // Identify the request parameters that we need String command = request.getPathInfo(); Modified: tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java?rev=1514291&r1=1514290&r2=1514291&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java (original) +++ tomcat/trunk/java/org/apache/catalina/manager/host/HostManagerServlet.java Thu Aug 15 14:25:30 2013 @@ -22,8 +22,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; -import java.util.Enumeration; -import java.util.Locale; import java.util.StringTokenizer; import javax.servlet.ServletException; @@ -196,7 +194,8 @@ public class HostManagerServlet HttpServletResponse response) throws IOException, ServletException { - StringManager smClient = getStringManager(request); + StringManager smClient = StringManager.getManager( + Constants.Package, request.getLocales()); // Identify the request parameters that we need String command = request.getPathInfo(); @@ -690,19 +689,4 @@ public class HostManagerServlet } return configBase; } - - - 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; - } } Modified: tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java?rev=1514291&r1=1514290&r2=1514291&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/Diagnostics.java Thu Aug 15 14:25:30 2013 @@ -388,27 +388,6 @@ public class Diagnostics { } /** - * Retrieve the StringManager for a list of Locales. - * The first StringManager found will be returned. - * - * @param requestedLocales the list of locales - * @return the found StringManager or the default - * StringManager - */ - private static StringManager getStringManager( - Enumeration<Locale> requestedLocales) { - while (requestedLocales.hasMoreElements()) { - Locale locale = requestedLocales.nextElement(); - StringManager result = StringManager.getManager(PACKAGE, locale); - if (result.getLocale().equals(locale)) { - return result; - } - } - // Return the default - return sm; - } - - /** * Retrieves a formatted JVM thread dump. * The default StringManager will be used. * @@ -427,7 +406,8 @@ public class Diagnostics { * @return the formatted JVM thread dump */ public static String getThreadDump(Enumeration<Locale> requestedLocales) { - return getThreadDump(getStringManager(requestedLocales)); + return getThreadDump( + StringManager.getManager(PACKAGE, requestedLocales)); } /** @@ -501,7 +481,7 @@ public class Diagnostics { * @return the formatted JVM information text */ public static String getVMInfo(Enumeration<Locale> requestedLocales) { - return getVMInfo(getStringManager(requestedLocales)); + return getVMInfo(StringManager.getManager(PACKAGE, requestedLocales)); } /** 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=1514291&r1=1514290&r2=1514291&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/res/StringManager.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/res/StringManager.java Thu Aug 15 14:25:30 2013 @@ -18,6 +18,7 @@ package org.apache.tomcat.util.res; import java.text.MessageFormat; +import java.util.Enumeration; import java.util.Hashtable; import java.util.Locale; import java.util.Map; @@ -203,4 +204,27 @@ public class StringManager { } return mgr; } + + /** + * Retrieve the StringManager for a list of Locales. The first StringManager + * found will be returned. + * + * @param requestedLocales the list of Locales + * + * @return the found StringManager or the default StringManager + */ + public static StringManager getManager(String packageName, + Enumeration<Locale> requestedLocales) { + while (requestedLocales.hasMoreElements()) { + Locale locale = requestedLocales.nextElement(); + StringManager result = getManager(packageName, locale); + if (result.getLocale().equals(locale)) { + return result; + } + } + // Return the default + return getManager(packageName); + } + + } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org