toshi 2005/01/05 23:27:20 Modified: java/webapps/axis happyaxis.jsp Added: java/webapps/axis i18nLib.jsp index.jsp Log: For i18n of Axis webapps. Revision Changes Path 1.19 +92 -128 ws-axis/java/webapps/axis/happyaxis.jsp Index: happyaxis.jsp =================================================================== RCS file: /home/cvs/ws-axis/java/webapps/axis/happyaxis.jsp,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- happyaxis.jsp 30 Dec 2004 02:01:19 -0000 1.18 +++ happyaxis.jsp 6 Jan 2005 07:27:20 -0000 1.19 @@ -1,13 +1,14 @@ -<%@ page import="java.io.InputStream, +<%@ page contentType="text/html; charset=utf-8" + import="java.io.InputStream, java.io.IOException, javax.xml.parsers.SAXParser, java.lang.reflect.*, javax.xml.parsers.SAXParserFactory" session="false" %> - <% - /* - * Copyright 2002,2004 The Apache Software Foundation. +<% +/* + * Copyright 2002,2004,2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +23,8 @@ * limitations under the License. */ %> - -Axis Happiness Page - - -<%! +<%! /* * Happiness tests for axis. These look at the classpath and warn if things * are missing. Normally addng this much code in a JSP page is mad @@ -38,20 +35,6 @@ * @author Brian Ewins */ - - /** - * Get a string providing install information. - * TODO: make this platform aware and give specific hints - */ - public String getInstallHints(HttpServletRequest request) { - - String hint= - "Note: On Tomcat 4.x and Java1.4, you may need to put libraries that contain " - +"java.* or javax.* packages into CATALINA_HOME/common/lib" - +"
jaxrpc.jar and saaj.jar are two such libraries."; - return hint; - } - /** * test for a class existing * @param classname @@ -106,39 +89,28 @@ if(clazz == null) { String url=""; if(homePage!=null) { - url="
See "+homePage+""; + url=getMessage("seeHomepage",homePage,homePage); } - out.write("

"+category+": could not find class "+classname - +" from file "+jarFile - +"
"+errorText - +url - +"

"); + out.write(getMessage("couldNotFound",category,classname,jarFile,errorText,url)); return 1; } else { String location = getLocation(out, clazz); + if(location == null) { - out.write("Found "+ description + " (" + classname + ")
"); + out.write("

  • "+getMessage("foundClass00",description,classname)+"

  • "); } else { - out.write("Found "+ description + " (" + classname + ") at " + location + "
    "); + out.write("
  • "+getMessage("foundClass01",description,classname,location)+"

  • "); } return 0; } } catch(NoClassDefFoundError ncdfe) { String url=""; if(homePage!=null) { - url="
    See "+homePage+""; + url=getMessage("seeHomepage",homePage,homePage); } - out.write("

    "+category+": could not find a dependency" - +" of class "+classname - +" from file "+jarFile - +"
    "+errorText - +url - +"
    The root cause was: "+ncdfe.getMessage() - +"
    This can happen e.g. if "+classname+" is in" - +" the 'common' classpath, but a dependency like " - +" activation.jar is only in the webapp classpath." - +"

    "); + out.write(getMessage("couldNotFoundDep",category, classname, errorText, url)); + out.write(getMessage("theRootCause",ncdfe.getMessage(), classname)); return 1; } } @@ -168,7 +140,7 @@ } } catch (Throwable t){ } - return "an unknown location"; + return getMessage("classFoundError"); } /** @@ -188,7 +160,7 @@ String errorText, String homePage) throws IOException { return probeClass(out, - "Error", + ""+getMessage("error")+"", classname, jarFile, description, @@ -213,7 +185,7 @@ String errorText, String homePage) throws IOException { return probeClass(out, - "Warning", + ""+getMessage("warning")+"", classname, jarFile, description, @@ -222,28 +194,6 @@ } /** - * probe for a resource existing, - * @param out - * @param resource - * @param errorText - * @throws Exception - */ - int wantResource(JspWriter out, - String resource, - String errorText) throws Exception { - if(!resourceExists(resource)) { - out.write("

    Warning: could not find resource "+resource - +"
    " - +errorText); - return 0; - } else { - out.write("found "+resource+"
    "); - return 1; - } - } - - - /** * get servlet version string * */ @@ -255,8 +205,6 @@ return Integer.toString(major) + '.' + Integer.toString(minor); } - - /** * what parser are we using. * @return the classname of the parser @@ -264,7 +212,7 @@ private String getParserName() { SAXParser saxParser = getSAXParser(); if (saxParser == null) { - return "Could not create an XML Parser"; + return getMessage("couldNotCreateParser"); } // check to what is in the classname @@ -323,15 +271,32 @@ } return false; } - %> -Axis Happiness Page - -

    Axis Happiness Page

    -

    Examining webapp configuration

    -

    -

    Needed Components

    +<%@ include file="i18nLib.jsp" %> + +<% + // initialize a private HttpServletRequest + setRequest(request); +%> + + +<%= getMessage("pageTitle") %> + + + +<% + out.print("

    "+ getMessage("pageTitle") +"

    "); + out.print("

    "+ getMessage("pageRole") +"

    "); +%> + +<%= getLocaleChoice() %> + +<% + out.print("

    "+ getMessage("neededComponents") +"

    "); +%> + + +<% + out.print("

    "+ getMessage("optionalComponents") +"

    "); +%> + +<% out.write("

    "); //is everythng we need here if(needed==0) { //yes, be happy - out.write("The core axis libraries are present. "); + out.write(getMessage("happyResult00")); } else { //no, be very unhappy response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - out.write("" - +needed - +" core axis librar" - +(needed==1?"y is":"ies are") - +" missing"); + out.write(getMessage("unhappyResult00",Integer.toString(needed))); } //now look at wanted stuff if(wanted>0) { - out.write("" - +wanted - +" optional axis librar" - +(wanted==1?"y is":"ies are") - +" missing"); + out.write(getMessage("unhappyResult01",Integer.toString(wanted))); } else { - out.write("The optional components are present."); + out.write(getMessage("happyResult01")); } out.write("

    "); +%> + -

    Examining Application Server

    +

    <%= getMessage("apsExamining") %>

    + + + <% if(xmlParser.indexOf("crimson")>=0) { %>

    - We recommend Xerces 2 - over Crimson as the XML parser for Axis + <%= getMessage("recommendedParser") %>

    <% } %> -

    Examining System Properties

    +

    <%= getMessage("sysExamining") %>

    +
    - Platform: <%= getServletConfig().getServletContext().getServerInfo() %> + <%= getMessage("apsPlatform") %>: + <%= getServletConfig().getServletContext().getServerInfo() %> - - 1.1 ws-axis/java/webapps/axis/i18nLib.jsp Index: i18nLib.jsp =================================================================== <%@ page contentType="text/html; charset=utf-8" import="java.util.*" %> <% /* * Copyright 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ %> <%! /* * A library file to produce i18n web applications. This can be easily * reused from your jsp(s) - just include and call any methods. * @author toshi */ // private variable HttpServletRequest _req = null; /** * Set a HttpServletRequest to a private variable. * @param request HttpServletRequest */ void setRequest(HttpServletRequest request) { _req = request; } /** * Get a ResourceBundle object. * @return a ResourceBundle object */ ResourceBundle getRB() { String strLocale = _req.getParameter("locale"); ResourceBundle objRb = null; Locale objLcl = null; if (strLocale!=null) { objLcl=new Locale(strLocale,""); } else { objLcl=_req.getLocale(); } Locale.setDefault(objLcl); objRb = ResourceBundle.getBundle("i18n",objLcl); return objRb; } /** * Get a list of locale choice * @return a list of supported locales */ String getLocaleChoice() { String choice = getRB().getString("locales"); StringBuffer buf = new StringBuffer(); buf.append("
    \n"); buf.append(getRB().getString("language")); buf.append(": "); StringTokenizer st = new StringTokenizer(choice); String locale = null; while (st.hasMoreTokens()) { locale = st.nextToken(); buf.append("["+ locale +"] "); } buf.append("\n
    \n"); return buf.toString(); } /** * Get a message from i18n.properties with several arguments. * @param key The resource key * @return The formatted message */ String getMessage(String key) { return getMessage(key, null, null, null, null, null); } /** * Get a message from i18n.properties with several arguments. * @param key The resource key * @param arg0 The argument to place in variable {0} * @return The formatted message */ String getMessage(String key, String arg0) { return getMessage(key, arg0, null, null, null, null); } /** * Get a message from i18n.properties with several arguments. * @param key The resource key * @param arg0 The argument to place in variable {0} * @param arg1 The argument to place in variable {1} * @return The formatted message */ String getMessage(String key, String arg0, String arg1) { return getMessage(key, arg0, arg1, null, null, null); } /** * Get a message from i18n.properties with several arguments. * @param key The resource key * @param arg0 The argument to place in variable {0} * @param arg1 The argument to place in variable {1} * @param arg2 The argument to place in variable {2} * @return The formatted message */ String getMessage(String key, String arg0, String arg1, String arg2) { return getMessage(key, arg0, arg1, arg2, null, null); } /** * Get a message from i18n.properties with several arguments. * @param key The resource key * @param arg0 The argument to place in variable {0} * @param arg1 The argument to place in variable {1} * @param arg2 The argument to place in variable {2} * @param arg3 The argument to place in variable {3} * @return The formatted message */ String getMessage(String key, String arg0, String arg1, String arg2, String arg3) { return getMessage(key, arg0, arg1, arg2, arg3, null); } /** * Get a message from i18n.properties with several arguments. * @param key The resource key * @param arg0 The argument to place in variable {0} * @param arg1 The argument to place in variable {1} * @param arg2 The argument to place in variable {2} * @param arg3 The argument to place in variable {3} * @param arg4 The argument to place in variable {4} * @return The formatted message */ String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4) { String strPattern = getRB().getString(key); String [] params = { arg0, arg1, arg2, arg3, arg4 }; for (int i=0; i<5; i++) { if (params[i]!=null) params[i]=params[i].replaceAll("\\\\","\\\\\\\\"); if (params[i]!=null) params[i]=params[i].replaceAll("%20"," "); } if (arg0!=null) strPattern = strPattern.replaceAll("\\{0\\}",params[0]); if (arg1!=null) strPattern = strPattern.replaceAll("\\{1\\}",params[1]); if (arg2!=null) strPattern = strPattern.replaceAll("\\{2\\}",params[2]); if (arg3!=null) strPattern = strPattern.replaceAll("\\{3\\}",params[3]); if (arg4!=null) strPattern = strPattern.replaceAll("\\{4\\}",params[4]); return strPattern; } %> 1.1 ws-axis/java/webapps/axis/index.jsp Index: index.jsp =================================================================== <%@ page contentType="text/html; charset=utf-8" %> <% /* * Copyright 2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ %> <%@ include file="i18nLib.jsp" %> <% // initialize a private HttpServletRequest setRequest(request); %> Apache-Axis

    Apache-AXIS

    <%= getLocaleChoice() %> <% out.print(getMessage("welcomeMessage")+"

    "); out.print(getMessage("operationType")); %>

    <% out.print(getMessage("sideNote") +"

    "); %> <% out.print("

    "+ getMessage("validatingAxis") +"

    "); out.print(getMessage("validationNote00") +"

    "); out.print(getMessage("validationNote01")); %>