db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r332444 - in /db/derby/code/trunk/java/drda/org/apache/derby: drda/NetServlet.java loc/drda/servlet_en.properties
Date Fri, 11 Nov 2005 04:22:46 GMT
Author: kmarsden
Date: Thu Nov 10 20:22:43 2005
New Revision: 332444

URL: http://svn.apache.org/viewcvs?rev=332444&view=rev
Log:
DERBY-117 Improvements to the Servlet

- improved use of tracingDirectory:
  * init-parameter is now used (it was documented but not used before)
  * current value is shown when the user try to change it
- improved function that handles the request locale (for instance, mozilla uses a - instead
of _ to separate the country from language)
- shows on the screen which port the server is running on
  * added a new SRV_POrtNumber message key for such info

Note: I did not commit the translated messages as I could not get them to patch.

Contributed by Filipe Leme 


Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/drda/NetServlet.java
    db/derby/code/trunk/java/drda/org/apache/derby/loc/drda/servlet_en.properties

Modified: db/derby/code/trunk/java/drda/org/apache/derby/drda/NetServlet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/drda/org/apache/derby/drda/NetServlet.java?rev=332444&r1=332443&r2=332444&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/drda/NetServlet.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/drda/NetServlet.java Thu Nov 10 20:22:43
2005
@@ -23,12 +23,10 @@
 import java.io.*;
 import java.util.*;
 
-import java.sql.*;
 import java.net.*;
 
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
-import java.security.PrivilegedActionException;
 
 import javax.servlet.*;
 import javax.servlet.http.*;
@@ -60,7 +58,7 @@
 	private boolean logStatus= false;	/* Logging off */
 	private boolean traceStatus = false;	/* Tracing off */
 	private String[] knownLang = {"en","es","de_DE", "fr", "it", "ja_JP",
-			"ko_KR", "zh_CN", "zh_TW"};
+			"ko_KR", "pt_BR", "zh_CN", "zh_TW"};
 	private String locale;
 
 	private final static int NOT_GIVEN = -2;
@@ -71,7 +69,7 @@
 
 	// for doPri block
 	private Runnable service;
-
+	
 	/**
 		Initialize the servlet.
 		Configuration parameters:
@@ -84,7 +82,7 @@
 	public void init(ServletConfig config)
 		throws ServletException
 	{
-
+		
 		LocalizedResource langUtil = new LocalizedResource(null,null,SERVLET_PROP_MESSAGES);
 				
 		String port = config.getInitParameter("portNumber");
@@ -94,15 +92,25 @@
 				portNumber = p;
 		}
 
-		String tracingDirectory = config.getInitParameter("tracingDirectory");
+		this.tracingDirectory = config.getInitParameter("tracingDirectory");
+		
+		if ( this.tracingDirectory == null ) {
+			this.tracingDirectory = "";
+		}
 
 		String startup = config.getInitParameter("startNetworkServerOnInit");
 
 		// test if the server is already running
 		try {
 			//don't send output to console
-			if (server == null)
+			if (server == null) {
 				server = new NetworkServerControl(InetAddress.getByName(host), portNumber);
+				// assert this.tracingDirectory != null
+				if  ( ! this.tracingDirectory.trim().equals("")) {
+					server.setTraceDirectory(this.tracingDirectory);
+				}
+			}
+			
 			if (isServerStarted(server,1))
 				return;
 		} catch (Exception e) {}
@@ -401,7 +409,7 @@
 				out.println( "<h4>" + getHtmlLabelledMessageInstance(langUtil,
 					"SRV_TraceDir", "tracedir") + "</h4>");
 				out.println( "<INPUT type=text name=tracedirectory size=60 maxlength=256 " +
-					"id='tracedir' value=''>");
+					"id='tracedir' value='"+tracingDirectory+"'>");
 				out.println( "<h4> </h4>");
 				out.println( "<INPUT type=submit name=doaction value='"+traceDirMessage+ "'>" );
 				out.println( "<INPUT type=submit name=form value='"+returnMessage+ "'>" );
@@ -658,6 +666,9 @@
 				out.println( "<h4>"+localUtil.getTextMessage("SRV_StatusTraceOn")+"</h4>");
 			else
 				out.println( "<h4>"+localUtil.getTextMessage("SRV_StatusTraceOff")+"</h4>");
+			val = p.getProperty(Property.DRDA_PROP_PORTNUMBER);
+			out.println( "<h4>"+localUtil.getTextMessage("SRV_PortNumber", val)+"</h4>");
+			
 		}
 		catch (Exception e) {
 			printErrorForm(localUtil, request, e, returnMessage);
@@ -789,6 +800,7 @@
 		}
 
 		try {
+			this.tracingDirectory = traceDirectory;
 			server.setTraceDirectory(traceDirectory);
 			retval = true;
 		} catch (Exception e) 
@@ -938,9 +950,8 @@
 		{
 			lang = lang.substring(0, semi);
 		}
-		// trim any whitespace
-		lang = lang.trim();
-		
+		// trim any whitespace and fix the code, as some browsers might send a bad format
+		lang = fixLanguageCode(lang.trim());
 		return lang;
 	}
 	/**
@@ -952,10 +963,36 @@
 	 */
 	private int translationAvailable(String lang)
 	{
+		// assert lang == fixLanguageCode(lang)
+		// we don't need to use toUpperCase() anymore, as the lang is already fixed
 		for (int i = 0; i < knownLang.length; i++)
-			if (knownLang[i].toUpperCase(Locale.ENGLISH).equals(lang.toUpperCase(Locale.ENGLISH)))
+			if (knownLang[i].equals(lang))
 				return i;
 		return -1;
+	}
+	
+	/**
+	 * Fix the language code, as some browsers send then in a bad format (for instance, 
+	 * Firefox sends en-us instead of en_US).
+	 *
+	 * @param lang	language to be fixed
+	 * 
+	 * @return fixed version of the language, with _ separating parts and country in upper case
+	 */
+	private String fixLanguageCode( String lang ) {
+		int index = lang.indexOf('-');
+		if ( index != -1 ) {		
+			return fixLanguageCode( lang, index );
+		}
+		index = lang.indexOf('_');
+		if ( index != -1 ) {		
+			return fixLanguageCode( lang, index );
+		}
+		return lang;
+	}
+
+	private String fixLanguageCode(String lang, int index) {
+		return lang.substring(0,index) + "_" + lang.substring(index+1).toUpperCase(Locale.ENGLISH);
 	}
 
 	/**

Modified: db/derby/code/trunk/java/drda/org/apache/derby/loc/drda/servlet_en.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/drda/org/apache/derby/loc/drda/servlet_en.properties?rev=332444&r1=332443&r2=332444&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/loc/drda/servlet_en.properties (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/loc/drda/servlet_en.properties Thu Nov
10 20:22:43 2005
@@ -1,8 +1,8 @@
 # This file contains the text for Net Server servlet
 # The format is SRV_<short desc>
 
-SRV_Banner= Derby Network Server 
-SRV_Started= Derby Network Server has been started.
+SRV_Banner=Derby Network Server 
+SRV_Started=Derby Network Server has been started.
 SRV_StopButton=Press the button to stop the Network Server.
 SRV_NotStarted=The  Derby Network Server has not been started.
 SRV_LogOnButton=Press the button to turn logging on when the server is started.
@@ -50,4 +50,4 @@
 SRV_MissingParam=Required parameter not set ("{0}")
 SRV_BackToMain=Back to Main Page
 SRV_SkipToContent=Skip to Content
-
+SRV_PortNumber=Server is running on port {0}.



Mime
View raw message