Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4EC37DBE1 for ; Wed, 8 Aug 2012 06:55:46 +0000 (UTC) Received: (qmail 98286 invoked by uid 500); 8 Aug 2012 06:55:45 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 98191 invoked by uid 500); 8 Aug 2012 06:55:45 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 97840 invoked by uid 99); 8 Aug 2012 06:55:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Aug 2012 06:55:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Aug 2012 06:55:33 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E386323888CD; Wed, 8 Aug 2012 06:54:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1370674 [1/12] - in /db/derby/code/trunk/java/drda/org/apache/derby: drda/ impl/drda/ Date: Wed, 08 Aug 2012 06:54:47 -0000 To: derby-commits@db.apache.org From: kmarsden@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120808065449.E386323888CD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kmarsden Date: Wed Aug 8 06:54:46 2012 New Revision: 1370674 URL: http://svn.apache.org/viewvc?rev=1370674&view=rev Log: DERBY-5896 Change java/drda source code to use spaces instead of tabs Modified: db/derby/code/trunk/java/drda/org/apache/derby/drda/NetServlet.java db/derby/code/trunk/java/drda/org/apache/derby/drda/NetworkServerControl.java db/derby/code/trunk/java/drda/org/apache/derby/drda/build.xml db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/AppRequester.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ClientThread.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/CodePoint.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMReader.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAProtocolException.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAProtocolExceptionInfo.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAResultSet.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAStatement.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAXAProtocol.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAXid.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Database.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DecryptionManager.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DssConstants.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DssTrace.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EXTDTAInputStream.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/EbcdicCcsidManager.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/FdocaConstants.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/ReEncodedInputStream.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/SQLTypes.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/Session.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/XADatabase.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/memCheck.java db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/package.html Modified: db/derby/code/trunk/java/drda/org/apache/derby/drda/NetServlet.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/drda/NetServlet.java?rev=1370674&r1=1370673&r2=1370674&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 Wed Aug 8 06:54:46 2012 @@ -39,124 +39,124 @@ import org.apache.derby.iapi.reference.P import org.apache.derby.iapi.tools.i18n.LocalizedResource; /** - This servlet can be used to start Derby Network Server from a remote location. -

- These servlet configuration parameters are understood by this servlet. -

    -
  • portNumber
    - Port number to use. The default is 1527.
  • -
  • startNetworkServerOnInit
    - Starts the Derby Network Server at servlet - initialization if 'true'.
  • -
  • tracingDirectory
    - Directory for trace files
  • -
+ This servlet can be used to start Derby Network Server from a remote location. +

+ These servlet configuration parameters are understood by this servlet. +

    +
  • portNumber
    - Port number to use. The default is 1527.
  • +
  • startNetworkServerOnInit
    - Starts the Derby Network Server at servlet + initialization if 'true'.
  • +
  • tracingDirectory
    - Directory for trace files
  • +
*/ public class NetServlet extends HttpServlet { - private final static int MAX_CONNECT_TRYS = 20; - private final static String SERVLET_PROP_MESSAGES = "org.apache.derby.loc.drda.servlet"; - private final static String SERVLET_ADDRESS = "derbynet"; - private final static String[] knownLang = + private final static int MAX_CONNECT_TRYS = 20; + private final static String SERVLET_PROP_MESSAGES = "org.apache.derby.loc.drda.servlet"; + private final static String SERVLET_ADDRESS = "derbynet"; + private final static String[] knownLang = { "cs","en","es","de_DE","fr","hu","it", "ja_JP","ko_KR","pl","pt_BR","ru","zh_CN","zh_TW" }; // set at initialization - private String host = "localhost"; - private int portNumber = 1527; + private String host = "localhost"; + private int portNumber = 1527; // can be overridden by trips through doGet() - private volatile String tracingDirectory; - private volatile boolean logStatus= false; /* Logging off */ - private volatile boolean traceStatus = false; /* Tracing off */ - - private final static int NOT_GIVEN = -2; - private final static int INVALID = -3; - - private NetworkServerControl server; - - /** - Initialize the servlet. - Configuration parameters: -
    -
  • portNumber
    - Port number
  • -
  • host
    - Host name
  • -
  • traceDirectory
    - location of trace directory
  • -
  • startNetworkServerOnInit
    - start the server on initialization
  • -
- */ - public void init(ServletConfig config) - throws ServletException - { - - String port = config.getInitParameter("portNumber"); - if (port != null) { - int p = Integer.parseInt(port); - if (p > 0) - portNumber = p; - } - String hostName = config.getInitParameter("host"); - if (hostName != null) - host = hostName; - - 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) { - 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) {} - - if (startup != null) { - boolean start = Boolean.valueOf(startup).booleanValue(); - if (start) - { + private volatile String tracingDirectory; + private volatile boolean logStatus= false; /* Logging off */ + private volatile boolean traceStatus = false; /* Tracing off */ + + private final static int NOT_GIVEN = -2; + private final static int INVALID = -3; + + private NetworkServerControl server; + + /** + Initialize the servlet. + Configuration parameters: +
    +
  • portNumber
    - Port number
  • +
  • host
    - Host name
  • +
  • traceDirectory
    - location of trace directory
  • +
  • startNetworkServerOnInit
    - start the server on initialization
  • +
+ */ + public void init(ServletConfig config) + throws ServletException + { + + String port = config.getInitParameter("portNumber"); + if (port != null) { + int p = Integer.parseInt(port); + if (p > 0) + portNumber = p; + } + String hostName = config.getInitParameter("host"); + if (hostName != null) + host = hostName; + + 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) { + 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) {} + + if (startup != null) { + boolean start = Boolean.valueOf(startup).booleanValue(); + if (start) + { LocalizedResource langUtil = new LocalizedResource(null,null,SERVLET_PROP_MESSAGES); - runServer(langUtil, null, null); - return; - } - } - } - - /** - Get the form of NetServlet. Provides buttons and forms to control the - Network server. - */ + runServer(langUtil, null, null); + return; + } + } + } + + /** + Get the form of NetServlet. Provides buttons and forms to control the + Network server. + */ public synchronized void doGet (HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException - { - String logOnMessage; - String logOffMessage; - String traceOnMessage; - String traceOffMessage; - String traceOnOffMessage; - String startMessage; - String stopMessage; - String returnMessage; - String traceSessionMessage; - String traceDirMessage; - String netParamMessage; + throws ServletException, IOException + { + String logOnMessage; + String logOffMessage; + String traceOnMessage; + String traceOffMessage; + String traceOnOffMessage; + String startMessage; + String stopMessage; + String returnMessage; + String traceSessionMessage; + String traceDirMessage; + String netParamMessage; - LocalizedResource langUtil; + LocalizedResource langUtil; String locale[] = new String[ 1 ]; - - langUtil = getCurrentAppUI(request, locale); - response.setContentType("text/html; charset=UTF-8"); - - //prevent caching of the servlet since contents can change - beetle 4649 - response.setHeader("Cache-Control", "no-cache,no-store"); + + langUtil = getCurrentAppUI(request, locale); + response.setContentType("text/html; charset=UTF-8"); + + //prevent caching of the servlet since contents can change - beetle 4649 + response.setHeader("Cache-Control", "no-cache,no-store"); String formTarget = request.getContextPath() + request.getServletPath(); String formHeader = "
"+langUtil.getTextMessage("SRV_StopButton")+"" ); - out.println( "" ); - - out.println( "

"+langUtil.getTextMessage("SRV_LogButton2")+"

" ); - - if (logStatus) - { - out.println( "" ); - } - else - { - out.println( "" ); - } - out.println( "

"+langUtil.getTextMessage("SRV_TraceButton2")+"

" ); - if (traceStatus) - { - out.println( "" ); - } - else - { - out.println( "" ); - } - - out.println( "

"+langUtil.getTextMessage("SRV_TraceSession")+"

" ); - out.println( "" ); - out.println( "

"+langUtil.getTextMessage("SRV_TraceDirButton")+"

" ); - out.println( "" ); - out.println( "

"+langUtil.getTextMessage("SRV_ThreadButton")+"

" ); - out.println( "" ); - } - else if (form.equals(stopMessage)) - { - - printAsContentHeader(langUtil.getTextMessage("SRV_NotStarted"), out); - String logButton = getLogging(request); - String traceButton = getTrace(request); - if (logButton != null && logButton.equals(logOnMessage)) - logStatus = true; - if (logButton != null && logButton.equals(logOffMessage)) - logStatus = false; - if (traceButton != null && traceButton.equals(traceOnMessage)) - traceStatus = true; - if (traceButton != null && traceButton.equals(traceOffMessage)) - traceStatus = false; - if (logStatus) - { - out.println( "

"+langUtil.getTextMessage("SRV_LogOffButton")+"

" ); - out.println( "" ); - } - else - { - out.println( "

"+langUtil.getTextMessage("SRV_LogOnButton")+"

" ); - out.println( "" ); - } - if (traceStatus) - { - out.println( "

"+langUtil.getTextMessage("SRV_TraceOffButton")+"

" ); - out.println( "" ); - } - else - { - out.println( "

"+langUtil.getTextMessage("SRV_TraceOnButton")+"

" ); - out.println( "" ); - } - out.println( "

"+langUtil.getTextMessage("SRV_StartButton")+"

" ); - out.println( "" ); - } - else if (form.equals(traceSessionMessage)) - { - if (doAction != null) - { - if (doAction.equals(traceOnOffMessage)) - { - String sessionid = request.getParameter("sessionid"); + { + // check if server is still running and use that to determine which form + if (serverStatus) + { + form = startMessage; + } + else + { + form = stopMessage; + } + } + + out.println( formHeader); + // display forms + + form = escapeSingleQuotes(form); + doAction = escapeSingleQuotes(doAction); + if (form.equals(startMessage)) + { + String logButton = getLogging(request); + String traceButton = getTrace(request); + if (logButton != null && logButton.equals(logOnMessage)) + { + if (logging(langUtil, true, returnMessage, out)) + logStatus = true; + } + if (logButton != null && logButton.equals(logOffMessage)) + { + if (logging(langUtil, false, returnMessage, out)) + logStatus = false; + } + if (traceButton != null && traceButton.equals(traceOnMessage)) + { + if (traceAll(langUtil, true, returnMessage, out)) + traceStatus = true; + } + if (traceButton != null && traceButton.equals(traceOffMessage)) + { + if (traceAll(langUtil, false, returnMessage, out)) + traceStatus = false; + } + displayCurrentStatus(langUtil, returnMessage, out); + out.println( "

"+langUtil.getTextMessage("SRV_StopButton")+"

" ); + out.println( "" ); + + out.println( "

"+langUtil.getTextMessage("SRV_LogButton2")+"

" ); + + if (logStatus) + { + out.println( "" ); + } + else + { + out.println( "" ); + } + out.println( "

"+langUtil.getTextMessage("SRV_TraceButton2")+"

" ); + if (traceStatus) + { + out.println( "" ); + } + else + { + out.println( "" ); + } + + out.println( "

"+langUtil.getTextMessage("SRV_TraceSession")+"

" ); + out.println( "" ); + out.println( "

"+langUtil.getTextMessage("SRV_TraceDirButton")+"

" ); + out.println( "" ); + out.println( "

"+langUtil.getTextMessage("SRV_ThreadButton")+"

" ); + out.println( "" ); + } + else if (form.equals(stopMessage)) + { + + printAsContentHeader(langUtil.getTextMessage("SRV_NotStarted"), out); + String logButton = getLogging(request); + String traceButton = getTrace(request); + if (logButton != null && logButton.equals(logOnMessage)) + logStatus = true; + if (logButton != null && logButton.equals(logOffMessage)) + logStatus = false; + if (traceButton != null && traceButton.equals(traceOnMessage)) + traceStatus = true; + if (traceButton != null && traceButton.equals(traceOffMessage)) + traceStatus = false; + if (logStatus) + { + out.println( "

"+langUtil.getTextMessage("SRV_LogOffButton")+"

" ); + out.println( "" ); + } + else + { + out.println( "

"+langUtil.getTextMessage("SRV_LogOnButton")+"

" ); + out.println( "" ); + } + if (traceStatus) + { + out.println( "

"+langUtil.getTextMessage("SRV_TraceOffButton")+"

" ); + out.println( "" ); + } + else + { + out.println( "

"+langUtil.getTextMessage("SRV_TraceOnButton")+"

" ); + out.println( "" ); + } + out.println( "

"+langUtil.getTextMessage("SRV_StartButton")+"

" ); + out.println( "" ); + } + else if (form.equals(traceSessionMessage)) + { + if (doAction != null) + { + if (doAction.equals(traceOnOffMessage)) + { + String sessionid = request.getParameter("sessionid"); Integer session; - try { + try { session = Integer.valueOf(sessionid); } catch (NumberFormatException nfe) { - printErrorForm(langUtil, - langUtil.getTextMessage("SRV_InvalidVal", - sessionid, langUtil.getTextMessage("SRV_SessionID")), + printErrorForm(langUtil, + langUtil.getTextMessage("SRV_InvalidVal", + sessionid, langUtil.getTextMessage("SRV_SessionID")), returnMessage, out); - return; - } - Properties p; - try { - p = server.getCurrentProperties(); - } catch (Exception e) { - printErrorForm(langUtil, e, returnMessage, out); - return; - } - // if it's on, turn it off, if its off, turn it on - boolean val; - if (p.getProperty(Property.DRDA_PROP_TRACE+sessionid) != null) - val = false; - else - val = true; + return; + } + Properties p; + try { + p = server.getCurrentProperties(); + } catch (Exception e) { + printErrorForm(langUtil, e, returnMessage, out); + return; + } + // if it's on, turn it off, if its off, turn it on + boolean val; + if (p.getProperty(Property.DRDA_PROP_TRACE+sessionid) != null) + val = false; + else + val = true; if (traceSession(langUtil, val, session.intValue(), returnMessage, out)) - { + { out.println( "

" + langUtil.getTextMessage( val ? "SRV_StatusTraceNoOn" : "SRV_StatusTraceNoOff", session.toString()) + "

"); - } - else - return; - - } - } - printAsContentHeader(langUtil.getTextMessage("SRV_TraceSessButton"), out); - out.println( "

" + getHtmlLabelledMessageInstance(langUtil, - "SRV_SessionID", "sessionId") + "

"); - out.println( ""); - out.println( "

"); - out.println( "" ); - out.println( "" ); - } - else if (form.equals(traceDirMessage)) - { - boolean set = false; - String traceDirectory = null; - printAsContentHeader(traceDirMessage, out); - if (doAction != null) - { - if (doAction.equals(traceDirMessage)) - { - traceDirectory = getParam(request, "tracedirectory"); - if (traceDirectory(langUtil, traceDirectory, + } + else + return; + + } + } + printAsContentHeader(langUtil.getTextMessage("SRV_TraceSessButton"), out); + out.println( "

" + getHtmlLabelledMessageInstance(langUtil, + "SRV_SessionID", "sessionId") + "

"); + out.println( ""); + out.println( "

"); + out.println( "" ); + out.println( "" ); + } + else if (form.equals(traceDirMessage)) + { + boolean set = false; + String traceDirectory = null; + printAsContentHeader(traceDirMessage, out); + if (doAction != null) + { + if (doAction.equals(traceDirMessage)) + { + traceDirectory = getParam(request, "tracedirectory"); + if (traceDirectory(langUtil, traceDirectory, returnMessage, out) ) - set = true; - else - return; - - } - } - if (set) - { + set = true; + else + return; + + } + } + if (set) + { out.println("

" + langUtil.getTextMessage("SRV_TraceDirDone", escapeHTML(traceDirectory)) + "

"); - out.println( "" ); - } - else - { - out.println( "

" + getHtmlLabelledMessageInstance(langUtil, - "SRV_TraceDir", "tracedir") + "

"); - out.println( "" ); + } + else + { + out.println( "

" + getHtmlLabelledMessageInstance(langUtil, + "SRV_TraceDir", "tracedir") + "

"); + out.println( ""); - out.println( "

"); - out.println( "" ); - out.println( "" ); - } - } - else if (form.equals(netParamMessage)) - { - int maxThreads; - int timeSlice; - String maxName = langUtil.getTextMessage("SRV_NewMaxThreads"); - String sliceName = langUtil.getTextMessage("SRV_NewTimeSlice"); - try { - Properties p = server.getCurrentProperties(); - String val = p.getProperty(Property.DRDA_PROP_MAXTHREADS); - maxThreads= (new Integer(val)).intValue(); - val = p.getProperty(Property.DRDA_PROP_TIMESLICE); - timeSlice= (new Integer(val)).intValue(); - } catch (Exception e) { - printErrorForm(langUtil, e, returnMessage, out); - return; - } - if (doAction != null && doAction.equals(netParamMessage)) - { - int newMaxThreads = getIntParameter(request, "newmaxthreads", - "SRV_NewMaxThreads", langUtil, returnMessage, out); - int newTimeSlice = (newMaxThreads == INVALID) ? NOT_GIVEN : - getIntParameter(request, "newtimeslice", "SRV_NewTimeSlice", langUtil, - returnMessage, out); - if ((newMaxThreads == INVALID) || (newTimeSlice == INVALID)) - return; - else if (!(newMaxThreads == NOT_GIVEN && newTimeSlice == NOT_GIVEN)) - { - if (newMaxThreads != NOT_GIVEN) - maxThreads = newMaxThreads; - if (newTimeSlice != NOT_GIVEN) - timeSlice = newTimeSlice; - if (!setNetParam(langUtil, maxThreads, timeSlice, - returnMessage, out)) - return; - } - } - - out.println(formHeader); - printAsContentHeader(netParamMessage, out); - out.println( "

"+langUtil.getTextMessage("SRV_MaxThreads", new Integer(maxThreads).toString()) +"

"); - out.println( "

"+langUtil.getTextMessage("SRV_TimeSlice", new Integer(timeSlice).toString()) +"

"); - out.println( "

"); - out.println( "

"); - out.println( "" ); - out.println( "

"); - out.println( "" ); - out.println( "

"); - out.println( "" ); - out.println( "" ); - } - else - { - System.out.println("Internal Error: Unknown form, "+ form); + out.println( "

"); + out.println( "" ); + out.println( "" ); + } + } + else if (form.equals(netParamMessage)) + { + int maxThreads; + int timeSlice; + String maxName = langUtil.getTextMessage("SRV_NewMaxThreads"); + String sliceName = langUtil.getTextMessage("SRV_NewTimeSlice"); + try { + Properties p = server.getCurrentProperties(); + String val = p.getProperty(Property.DRDA_PROP_MAXTHREADS); + maxThreads= (new Integer(val)).intValue(); + val = p.getProperty(Property.DRDA_PROP_TIMESLICE); + timeSlice= (new Integer(val)).intValue(); + } catch (Exception e) { + printErrorForm(langUtil, e, returnMessage, out); + return; + } + if (doAction != null && doAction.equals(netParamMessage)) + { + int newMaxThreads = getIntParameter(request, "newmaxthreads", + "SRV_NewMaxThreads", langUtil, returnMessage, out); + int newTimeSlice = (newMaxThreads == INVALID) ? NOT_GIVEN : + getIntParameter(request, "newtimeslice", "SRV_NewTimeSlice", langUtil, + returnMessage, out); + if ((newMaxThreads == INVALID) || (newTimeSlice == INVALID)) + return; + else if (!(newMaxThreads == NOT_GIVEN && newTimeSlice == NOT_GIVEN)) + { + if (newMaxThreads != NOT_GIVEN) + maxThreads = newMaxThreads; + if (newTimeSlice != NOT_GIVEN) + timeSlice = newTimeSlice; + if (!setNetParam(langUtil, maxThreads, timeSlice, + returnMessage, out)) + return; + } + } + + out.println(formHeader); + printAsContentHeader(netParamMessage, out); + out.println( "

"+langUtil.getTextMessage("SRV_MaxThreads", new Integer(maxThreads).toString()) +"

"); + out.println( "

"+langUtil.getTextMessage("SRV_TimeSlice", new Integer(timeSlice).toString()) +"

"); + out.println( "

"); + out.println( "

"); + out.println( "" ); + out.println( "

"); + out.println( "" ); + out.println( "

"); + out.println( "" ); + out.println( "" ); + } + else + { + System.out.println("Internal Error: Unknown form, "+ form); out.println("Internal Error: Unknown form"); - } + } - out.println( "" ); + out.println( "" ); out.println( "" ); - } + } + + /** + Get the form of NetServlet. Provides a buttons and form to control the + Network server + + */ + public void doPost (HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException + { + // simply call the doGet() + doGet(request, response); + } - /** - Get the form of NetServlet. Provides a buttons and form to control the - Network server - - */ - public void doPost (HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException - { - // simply call the doGet() - doGet(request, response); - } - - private String getForm(HttpServletRequest request) throws java.io.IOException{ - return getParam(request, "form"); - } - private String getDoAction(HttpServletRequest request) throws java.io.IOException { - return getParam(request, "doaction"); - } - private String getLogging(HttpServletRequest request) throws java.io.IOException { - return getParam(request, "logform"); - } - private String getTrace(HttpServletRequest request) throws java.io.IOException { - return getParam(request, "traceform"); - } - - /** - * get UTF8 parameter value and decode international characters - * @param request HttpServletRequest - * @param paramName Parameter name - * @return decoded String - */ - private String getParam(HttpServletRequest request, String paramName) throws - java.io.IOException { - - String value = request.getParameter(paramName); + private String getForm(HttpServletRequest request) throws java.io.IOException{ + return getParam(request, "form"); + } + private String getDoAction(HttpServletRequest request) throws java.io.IOException { + return getParam(request, "doaction"); + } + private String getLogging(HttpServletRequest request) throws java.io.IOException { + return getParam(request, "logform"); + } + private String getTrace(HttpServletRequest request) throws java.io.IOException { + return getParam(request, "traceform"); + } + + /** + * get UTF8 parameter value and decode international characters + * @param request HttpServletRequest + * @param paramName Parameter name + * @return decoded String + */ + private String getParam(HttpServletRequest request, String paramName) throws + java.io.IOException { + + String value = request.getParameter(paramName); if (value != null) { return new String(value.getBytes("ISO-8859-1"),"UTF8"); } else { return null; } - } + } - /** - * Start the network server and attempt to connect to it before - * returning - * - * @param localUtil LocalizedResource to use to translate messages - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - * @exception ServletException throws an exception if error in starting the - * Network Server during initialization - */ - private void runServer + /** + * Start the network server and attempt to connect to it before + * returning + * + * @param localUtil LocalizedResource to use to translate messages + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + * @exception ServletException throws an exception if error in starting the + * Network Server during initialization + */ + private void runServer ( LocalizedResource localUtil, String returnMessage, PrintWriter out ) - throws ServletException - { - final Runnable service = new Runnable() { - public void run() { - try { - //Echo server output to console - NetworkServerControl runserver = new - NetworkServerControl(InetAddress.getByName(host), - portNumber); - runserver.start(null); - } - catch (Exception e) { - throw new RuntimeException(e.getMessage()); - } - } - }; - Thread servThread = null; - try { - servThread = (Thread) AccessController.doPrivileged( - new PrivilegedExceptionAction() { - public Object run() throws Exception - { - return new Thread(service); - } - } - ); - } - catch (Exception e) { - throw new RuntimeException(e.getMessage()); - } - servThread.start(); - - // try to connect to server - try { - boolean connectWorked = false; - int t = 0; - do - { - t++; - try { - Thread.sleep(100); - } catch (InterruptedException ie) { - throw new ServletException(localUtil.getTextMessage("SRV_Interupt")); - } - try { - if (isServerStarted(server,1)) - connectWorked = true; - } catch (Exception e) {} //ignore error we'll just try again - - }while (!connectWorked && t < MAX_CONNECT_TRYS); - if (t >= MAX_CONNECT_TRYS) - throw new Exception(localUtil.getTextMessage("SRV_MaxTrys", - new Integer(MAX_CONNECT_TRYS).toString())); - // turn logging on if required - if (logStatus) - server.logConnections(true); - // turn tracing on - if (traceStatus) - server.trace(true); - }catch (Exception e) { - if (out != null) - printErrorForm(localUtil, e, returnMessage, out); - else - throw new ServletException(e.getMessage()); - } - } - /** - * Display an error form - * - * @param localUtil LocalizedResource to use to translate messages - * @param e Exception to be displayed - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - */ - private void printErrorForm + throws ServletException + { + final Runnable service = new Runnable() { + public void run() { + try { + //Echo server output to console + NetworkServerControl runserver = new + NetworkServerControl(InetAddress.getByName(host), + portNumber); + runserver.start(null); + } + catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + } + }; + Thread servThread = null; + try { + servThread = (Thread) AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Object run() throws Exception + { + return new Thread(service); + } + } + ); + } + catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + servThread.start(); + + // try to connect to server + try { + boolean connectWorked = false; + int t = 0; + do + { + t++; + try { + Thread.sleep(100); + } catch (InterruptedException ie) { + throw new ServletException(localUtil.getTextMessage("SRV_Interupt")); + } + try { + if (isServerStarted(server,1)) + connectWorked = true; + } catch (Exception e) {} //ignore error we'll just try again + + }while (!connectWorked && t < MAX_CONNECT_TRYS); + if (t >= MAX_CONNECT_TRYS) + throw new Exception(localUtil.getTextMessage("SRV_MaxTrys", + new Integer(MAX_CONNECT_TRYS).toString())); + // turn logging on if required + if (logStatus) + server.logConnections(true); + // turn tracing on + if (traceStatus) + server.trace(true); + }catch (Exception e) { + if (out != null) + printErrorForm(localUtil, e, returnMessage, out); + else + throw new ServletException(e.getMessage()); + } + } + /** + * Display an error form + * + * @param localUtil LocalizedResource to use to translate messages + * @param e Exception to be displayed + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + */ + private void printErrorForm ( LocalizedResource localUtil, Exception e, String returnMessage, PrintWriter out ) - { - printAsContentHeader(localUtil.getTextMessage("SRV_NetworkServerError"), out); + { + printAsContentHeader(localUtil.getTextMessage("SRV_NetworkServerError"), out); out.println( "

" + localUtil.getTextMessage( "SRV_Message", escapeHTML(e.getMessage())) + "

" ); - out.println( "" ); - out.println( "" ); - out.println( "" ); - } - /** - * Display an error form - * - * @param localUtil LocalizedResource to use to translate messages - * @param msg String to be displayed - * @param out Form PrintWriter - * @param returnMessage localized continue message for continue button on error form - */ - private void printErrorForm + out.println( "" ); + out.println( "" ); + out.println( "" ); + } + /** + * Display an error form + * + * @param localUtil LocalizedResource to use to translate messages + * @param msg String to be displayed + * @param out Form PrintWriter + * @param returnMessage localized continue message for continue button on error form + */ + private void printErrorForm ( LocalizedResource localUtil, String msg, String returnMessage, PrintWriter out ) - { - printAsContentHeader(localUtil.getTextMessage("SRV_NetworkServerError"), out); + { + printAsContentHeader(localUtil.getTextMessage("SRV_NetworkServerError"), out); out.println( "

" + localUtil.getTextMessage("SRV_Message", escapeHTML(msg)) + "

" ); - out.println( "" ); - out.println( "" ); - out.println( "" ); - } - /** - * Display the current Network server status - * - * @param localUtil LocalizedResource to use for localizing messages - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - */ - private void displayCurrentStatus + out.println( "" ); + out.println( "" ); + out.println( "" ); + } + /** + * Display the current Network server status + * + * @param localUtil LocalizedResource to use for localizing messages + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + */ + private void displayCurrentStatus ( LocalizedResource localUtil, String returnMessage, PrintWriter out ) - { - try { + { + try { - printAsContentHeader(localUtil.getTextMessage("SRV_Started"), out); - Properties p = server.getCurrentProperties(); - String val = p.getProperty(Property.DRDA_PROP_LOGCONNECTIONS); - if (val.equals("true")) - logStatus = true; - else - logStatus = false; - if (logStatus) - out.println( "

"+localUtil.getTextMessage("SRV_StatusLogOn")+"

"); - else - out.println( "

"+localUtil.getTextMessage("SRV_StatusLogOff")+"

"); - val = p.getProperty(Property.DRDA_PROP_TRACEALL); - if (val.equals("true")) - traceStatus = true; - else - traceStatus = false; - if (traceStatus) - out.println( "

"+localUtil.getTextMessage("SRV_StatusTraceOn")+"

"); - else - out.println( "

"+localUtil.getTextMessage("SRV_StatusTraceOff")+"

"); - val = p.getProperty(Property.DRDA_PROP_PORTNUMBER); - out.println( "

"+localUtil.getTextMessage("SRV_PortNumber", val)+"

"); - - } - catch (Exception e) { - printErrorForm(localUtil, e, returnMessage, out); - } - } - /** - * Get the currrent server status by using test connection - * - * @return true if server is up and reachable; false; otherwise - */ - private boolean getServerStatus() - { - try { - - if (isServerStarted(server,1)) - return true; - } catch (Exception e) {} - return false; - } - /** - * Shutdown the network server - * - * @param localUtil LocalizedResource to use to translate messages - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - * @return true if succeeded; false; otherwise - */ - private boolean shutdownServer + printAsContentHeader(localUtil.getTextMessage("SRV_Started"), out); + Properties p = server.getCurrentProperties(); + String val = p.getProperty(Property.DRDA_PROP_LOGCONNECTIONS); + if (val.equals("true")) + logStatus = true; + else + logStatus = false; + if (logStatus) + out.println( "

"+localUtil.getTextMessage("SRV_StatusLogOn")+"

"); + else + out.println( "

"+localUtil.getTextMessage("SRV_StatusLogOff")+"

"); + val = p.getProperty(Property.DRDA_PROP_TRACEALL); + if (val.equals("true")) + traceStatus = true; + else + traceStatus = false; + if (traceStatus) + out.println( "

"+localUtil.getTextMessage("SRV_StatusTraceOn")+"

"); + else + out.println( "

"+localUtil.getTextMessage("SRV_StatusTraceOff")+"

"); + val = p.getProperty(Property.DRDA_PROP_PORTNUMBER); + out.println( "

"+localUtil.getTextMessage("SRV_PortNumber", val)+"

"); + + } + catch (Exception e) { + printErrorForm(localUtil, e, returnMessage, out); + } + } + /** + * Get the currrent server status by using test connection + * + * @return true if server is up and reachable; false; otherwise + */ + private boolean getServerStatus() + { + try { + + if (isServerStarted(server,1)) + return true; + } catch (Exception e) {} + return false; + } + /** + * Shutdown the network server + * + * @param localUtil LocalizedResource to use to translate messages + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + * @return true if succeeded; false; otherwise + */ + private boolean shutdownServer ( LocalizedResource localUtil, String returnMessage, PrintWriter out ) - { - boolean retval = false; - try { - server.shutdown(); - retval = true; - } catch (Exception e) - { - printErrorForm(localUtil, e, returnMessage, out); - } - return retval; - } - /** - * Turn logging of connections on - * - * @param localUtil LocalizedResource to use to translate messages - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - * @return true if succeeded; false; otherwise - */ - private boolean logging + { + boolean retval = false; + try { + server.shutdown(); + retval = true; + } catch (Exception e) + { + printErrorForm(localUtil, e, returnMessage, out); + } + return retval; + } + /** + * Turn logging of connections on + * + * @param localUtil LocalizedResource to use to translate messages + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + * @return true if succeeded; false; otherwise + */ + private boolean logging ( LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out ) - { - boolean retval = false; - try { - server.logConnections(val); - retval = true; - } catch (Exception e) - { - printErrorForm(localUtil, e, returnMessage, out); - } - return retval; - } - /** - * Change tracing for all sessions - * - * @param localUtil LocalizedResource to use to translate messages - * @param val if true, turn tracing on, if false turn it off - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - * @return true if succeeded; false; otherwise - */ - private boolean traceAll + { + boolean retval = false; + try { + server.logConnections(val); + retval = true; + } catch (Exception e) + { + printErrorForm(localUtil, e, returnMessage, out); + } + return retval; + } + /** + * Change tracing for all sessions + * + * @param localUtil LocalizedResource to use to translate messages + * @param val if true, turn tracing on, if false turn it off + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + * @return true if succeeded; false; otherwise + */ + private boolean traceAll ( LocalizedResource localUtil, boolean val, String returnMessage, PrintWriter out ) - { - boolean retval = false; - try { - server.trace(val); - retval = true; - } catch (Exception e) - { - printErrorForm(localUtil, e, returnMessage, out); - } - return retval; - } - /** - * Change tracing for a given session - * - * @param localUtil LocalizedResource to use to translate messages - * @param val if true, turn tracing on, if false turn it off - * @param session session to trace - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - * @return true if succeeded; false; otherwise - */ - private boolean traceSession + { + boolean retval = false; + try { + server.trace(val); + retval = true; + } catch (Exception e) + { + printErrorForm(localUtil, e, returnMessage, out); + } + return retval; + } + /** + * Change tracing for a given session + * + * @param localUtil LocalizedResource to use to translate messages + * @param val if true, turn tracing on, if false turn it off + * @param session session to trace + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + * @return true if succeeded; false; otherwise + */ + private boolean traceSession ( LocalizedResource localUtil, boolean val, @@ -804,67 +804,67 @@ public class NetServlet extends HttpServ String returnMessage, PrintWriter out ) - { - boolean retval = false; - try { - server.trace(session, val); - retval = true; - } catch (Exception e) - { - printErrorForm(localUtil, e, returnMessage, out); - } - return retval; - } - - /** - * Set trace directory - * - * @param localUtil LocalizedResource to use to translate messages - * @param traceDirectory directory for trace files - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - * @return true if succeeded; false; otherwise - */ - private boolean traceDirectory + { + boolean retval = false; + try { + server.trace(session, val); + retval = true; + } catch (Exception e) + { + printErrorForm(localUtil, e, returnMessage, out); + } + return retval; + } + + /** + * Set trace directory + * + * @param localUtil LocalizedResource to use to translate messages + * @param traceDirectory directory for trace files + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + * @return true if succeeded; false; otherwise + */ + private boolean traceDirectory ( LocalizedResource localUtil, String traceDirectory, String returnMessage, PrintWriter out ) - { - boolean retval = false; + { + boolean retval = false; - if ((traceDirectory == null) || traceDirectory.equals("")) { - printErrorForm(localUtil, - localUtil.getTextMessage("SRV_MissingParam", + if ((traceDirectory == null) || traceDirectory.equals("")) { + printErrorForm(localUtil, + localUtil.getTextMessage("SRV_MissingParam", localUtil.getTextMessage("SRV_TraceDir")), returnMessage, out); - return retval; - } + return retval; + } + + try { + this.tracingDirectory = traceDirectory; + server.setTraceDirectory(traceDirectory); + retval = true; + } catch (Exception e) + { + printErrorForm(localUtil, e, returnMessage, out); + } + return retval; + } - try { - this.tracingDirectory = traceDirectory; - server.setTraceDirectory(traceDirectory); - retval = true; - } catch (Exception e) - { - printErrorForm(localUtil, e, returnMessage, out); - } - return retval; - } - - /** - * Set Network server parameters - * - * @param localUtil LocalizedResource to use to translate messages - * @param max maximum number of threads - * @param slice time slice for each connection - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - * @return true if succeeded; false; otherwise - */ - private boolean setNetParam + /** + * Set Network server parameters + * + * @param localUtil LocalizedResource to use to translate messages + * @param max maximum number of threads + * @param slice time slice for each connection + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + * @return true if succeeded; false; otherwise + */ + private boolean setNetParam ( LocalizedResource localUtil, int max, @@ -872,40 +872,40 @@ public class NetServlet extends HttpServ String returnMessage, PrintWriter out ) - { - boolean retval = false; + { + boolean retval = false; - try { - server.setMaxThreads(max); - server.setTimeSlice(slice); - retval = true; - } catch (Exception e) - { - printErrorForm(localUtil, e, returnMessage, out); - } - return retval; - } - - - /** - * Set defaults for logging and tracing (both off) - */ - private void setDefaults() - { - logStatus = false; - traceStatus = false; - } - /** - * Get an integer parameter - * - * @param request HttpServetRequest for forms - * @param name parameter name - * @param fieldKey Key for the name of the field we're reading. - * @param localUtil LocalizedResource to use in localizing messages - * @param returnMessage localized continue message for continue button on error form - * @param out Form PrintWriter - */ - private int getIntParameter + try { + server.setMaxThreads(max); + server.setTimeSlice(slice); + retval = true; + } catch (Exception e) + { + printErrorForm(localUtil, e, returnMessage, out); + } + return retval; + } + + + /** + * Set defaults for logging and tracing (both off) + */ + private void setDefaults() + { + logStatus = false; + traceStatus = false; + } + /** + * Get an integer parameter + * + * @param request HttpServetRequest for forms + * @param name parameter name + * @param fieldKey Key for the name of the field we're reading. + * @param localUtil LocalizedResource to use in localizing messages + * @param returnMessage localized continue message for continue button on error form + * @param out Form PrintWriter + */ + private int getIntParameter ( HttpServletRequest request, String name, @@ -914,209 +914,209 @@ public class NetServlet extends HttpServ String returnMessage, PrintWriter out ) - { - String val = request.getParameter(name); - int retval; - if (val == null || val.equals("")) - return NOT_GIVEN; - try { - retval = (new Integer(val)).intValue(); - } catch (Exception e) { - printErrorForm(localUtil,localUtil.getTextMessage("SRV_InvalidVal", + { + String val = request.getParameter(name); + int retval; + if (val == null || val.equals("")) + return NOT_GIVEN; + try { + retval = (new Integer(val)).intValue(); + } catch (Exception e) { + printErrorForm(localUtil,localUtil.getTextMessage("SRV_InvalidVal", val, localUtil.getTextMessage(fieldKey)), returnMessage, out); - return INVALID; - } - if (retval < 0) { - // negative integers not allowed for the parameters we're getting. - printErrorForm(localUtil, localUtil.getTextMessage("SRV_InvalidVal", + return INVALID; + } + if (retval < 0) { + // negative integers not allowed for the parameters we're getting. + printErrorForm(localUtil, localUtil.getTextMessage("SRV_InvalidVal", val, localUtil.getTextMessage(fieldKey)), returnMessage, out); - return INVALID; - } - return retval; - } - /** - * Print Derby Network Server banner - */ - private void printBanner(LocalizedResource localUtil, PrintWriter out) - { + return INVALID; + } + return retval; + } + /** + * Print Derby Network Server banner + */ + private void printBanner(LocalizedResource localUtil, PrintWriter out) + { out.println(""); out.println(""); out.println(""); out.println(""+localUtil.getTextMessage("SRV_Banner")+""); out.println(""); out.println(""); - out.println("[ " + - localUtil.getTextMessage("SRV_SkipToContent") + " ]"); - out.println(" - [ " + - localUtil.getTextMessage("SRV_BackToMain") + " ]"); + out.println("[ " + + localUtil.getTextMessage("SRV_SkipToContent") + " ]"); + out.println(" - [ " + + localUtil.getTextMessage("SRV_BackToMain") + " ]"); out.println("
"); out.println("

"+localUtil.getTextMessage("SRV_Banner")+"

"); out.println("
"); - } + } + + /** + * Determine the locale file needed for this browsers preferences + * Defaults to the settings for derby.locale and derby.codeset if set + * English otherwise if browsers preferences can't be found + * + * @param request HttpServetRequest for forms + * @param locale Name of locale (return arg) + * @return the appUI which fits the browsers preferences + */ + private LocalizedResource getCurrentAppUI(HttpServletRequest request, String[] locale ) + { + LocalizedResource localUtil; + String acceptLanguage = request.getHeader("Accept-Language"); + localUtil = new LocalizedResource(null,null,SERVLET_PROP_MESSAGES); + // if no language specified use one set by derby.locale, derby.codeset + locale[ 0 ] = null; + if (acceptLanguage == null) + { + return localUtil; + } + // Use a tokenizer ot separate acceptable languages + StringTokenizer tokenizer = new StringTokenizer(acceptLanguage, ","); + while (tokenizer.hasMoreTokens()) + { + //Get the next acceptable language + String lang = tokenizer.nextToken(); + lang = getLocStringFromLanguage(lang); + int langindex = translationAvailable(lang); + // have we found one + if (langindex != -1) + { + localUtil.init(null, lang, SERVLET_PROP_MESSAGES); + // locale will be passed to server, server routines will get set appropriately + locale[ 0 ] = lang; + return localUtil; + } + } + // nothing worked use defaults + return localUtil; + + } + /** + * Get locale string from language which may have qvalue set + * + * @param lang language string to parse + * + * @return stripped language string to use in matching + */ + private String getLocStringFromLanguage(String lang) + { + int semi; + // Cut off any q-value that might come after a semi-colon + if ((semi = lang.indexOf(';')) != -1) + { + lang = lang.substring(0, semi); + } + // trim any whitespace and fix the code, as some browsers might send a bad format + lang = fixLanguageCode(lang.trim()); + return lang; + } + /** + * Check if the required translation is available + * + * @param lang language we are looking for + * + * @return index into language array if found, -1 otherwise; + */ + 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].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); + } - /** - * Determine the locale file needed for this browsers preferences - * Defaults to the settings for derby.locale and derby.codeset if set - * English otherwise if browsers preferences can't be found - * - * @param request HttpServetRequest for forms - * @param locale Name of locale (return arg) - * @return the appUI which fits the browsers preferences - */ - private LocalizedResource getCurrentAppUI(HttpServletRequest request, String[] locale ) - { - LocalizedResource localUtil; - String acceptLanguage = request.getHeader("Accept-Language"); - localUtil = new LocalizedResource(null,null,SERVLET_PROP_MESSAGES); - // if no language specified use one set by derby.locale, derby.codeset - locale[ 0 ] = null; - if (acceptLanguage == null) - { - return localUtil; - } - // Use a tokenizer ot separate acceptable languages - StringTokenizer tokenizer = new StringTokenizer(acceptLanguage, ","); - while (tokenizer.hasMoreTokens()) - { - //Get the next acceptable language - String lang = tokenizer.nextToken(); - lang = getLocStringFromLanguage(lang); - int langindex = translationAvailable(lang); - // have we found one - if (langindex != -1) - { - localUtil.init(null, lang, SERVLET_PROP_MESSAGES); - // locale will be passed to server, server routines will get set appropriately - locale[ 0 ] = lang; - return localUtil; - } - } - // nothing worked use defaults - return localUtil; - - } - /** - * Get locale string from language which may have qvalue set - * - * @param lang language string to parse - * - * @return stripped language string to use in matching - */ - private String getLocStringFromLanguage(String lang) - { - int semi; - // Cut off any q-value that might come after a semi-colon - if ((semi = lang.indexOf(';')) != -1) - { - lang = lang.substring(0, semi); - } - // trim any whitespace and fix the code, as some browsers might send a bad format - lang = fixLanguageCode(lang.trim()); - return lang; - } - /** - * Check if the required translation is available - * - * @param lang language we are looking for - * - * @return index into language array if found, -1 otherwise; - */ - 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].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); - } - - /** - * get an HTML labelled message from the resource bundle file, according to - * the given key. - */ - private String getHtmlLabelledMessageInstance(LocalizedResource localUtil, + /** + * get an HTML labelled message from the resource bundle file, according to + * the given key. + */ + private String getHtmlLabelledMessageInstance(LocalizedResource localUtil, String key, String id) { - if (id == null) - id = ""; + if (id == null) + id = ""; - return (""); + return (""); - } + } - /** - * Print the received string as a header. - * @param str The string to be printed as a header. - * @param out Form PrintWriter - */ - private void printAsContentHeader(String str, PrintWriter out) { - out.println("

" + str + "

"); - } - - /** - * If the received string has one or more single quotes - * in it, replace each one with the HTML escape-code - * for a single quote (apostrophe) so that the string - * can be properly displayed on a submit button. - * @param str The string in which we want to escape - * single quotes. - */ - private String escapeSingleQuotes(String str) { + /** + * Print the received string as a header. + * @param str The string to be printed as a header. + * @param out Form PrintWriter + */ + private void printAsContentHeader(String str, PrintWriter out) { + out.println("

" + str + "

"); + } - if ((str == null) || (str.indexOf("'") < 0)) - return str; + /** + * If the received string has one or more single quotes + * in it, replace each one with the HTML escape-code + * for a single quote (apostrophe) so that the string + * can be properly displayed on a submit button. + * @param str The string in which we want to escape + * single quotes. + */ + private String escapeSingleQuotes(String str) { - char [] cA = str.toCharArray(); + if ((str == null) || (str.indexOf("'") < 0)) + return str; + + char [] cA = str.toCharArray(); - // Worst (and extremely unlikely) case is every - // character is a single quote, which means the + // Worst (and extremely unlikely) case is every + // character is a single quote, which means the // escaped string would need to be 5 times as long. char [] result = new char[5*cA.length]; - int j = 0; - for (int i = 0; i < cA.length; i++) { + int j = 0; + for (int i = 0; i < cA.length; i++) { - if (cA[i] == '\'') { - result[j++] = '&'; - result[j++] = '#'; - result[j++] = '3'; - result[j++] = '9'; - result[j++] = ';'; - } - else - result[j++] = cA[i]; + if (cA[i] == '\'') { + result[j++] = '&'; + result[j++] = '#'; + result[j++] = '3'; + result[j++] = '9'; + result[j++] = ';'; + } + else + result[j++] = cA[i]; - } + } - return new String(result, 0, j); + return new String(result, 0, j); - } + } /** * Escapes potentially dangerous characters in data written to the browser. @@ -1202,21 +1202,21 @@ public class NetServlet extends HttpServ return String.copyValueOf(result, 0, j); } - private static boolean isServerStarted(NetworkServerControl server, int ntries) - { - for (int i = 1; i <= ntries; i ++) - { - try { - Thread.sleep(500); - server.ping(); - return true; - } - catch (Exception e) { - if (i == ntries) - return false; - } - } - return false; - } - + private static boolean isServerStarted(NetworkServerControl server, int ntries) + { + for (int i = 1; i <= ntries; i ++) + { + try { + Thread.sleep(500); + server.ping(); + return true; + } + catch (Exception e) { + if (i == ntries) + return false; + } + } + return false; + } + }