I think my mail was broken, sorry for the late reply.
I don't think we should do that in tomcat 3.2 - it would be very hard to integrate
this with Apache,etc ( i.e. tomcat standalone will have a different behavior than
tomcat
integrated).
Another argument is that we still have problems detecting the encoding and
language - and I don't expect those to be fixed in 3.2.
I agree it's an useful feature, but I think it would be better to wait a bit and
make sure we understand how other web servers deal with that and how can we do
that in a way that's compatible.
Costin
Arieh Markel wrote:
> I am attaching the proposed patch for the DefaultServlet as specified
> in the discussion that took place this past week.
>
> The gist of it is that the decision for which file to serve is as follows:
>
> assume:
>
> reqCtry = request.getLocale().getCountry()
> reqLang = request.getLocale().getLanguage()
>
> defCtry = Locale.getDefault().getCountry()
> defLang = Locale.getDefault().getLanguage()
>
>
> a. try to serve from
>
> <docBase>/<reqLang>_<reqCtry>/path
>
> b. try serve from
>
> <docBase>/<reqLang>/path
>
> c. try to serve from
>
> <docBase>/<defLang>_<defCtry>/path
>
> d. try serve from
>
> <docBase>/<defLang>/path
>
> e. try serve from
>
> <docBase>/path
>
>
> Follow the context diffs for the 3.1 code and for the 3.2 code:
>
> 3.1 code:
>
> ===================================================================
> RCS file: RCS/DefaultServlet.java,v
> retrieving revision 1.1
> diff -u -r1.1 DefaultServlet.java
> --- DefaultServlet.java 2000/06/15 19:44:56 1.1
> +++ DefaultServlet.java 2000/06/20 22:42:04
> @@ -130,12 +130,10 @@
> requestURI = request.getRequestURI();
> }
>
> - // Clean up pathInfo
> - File file = null;
> - if ((pathInfo == null) || (pathInfo.length() < 1))
> - file = new File(docBase);
> - else // Avoid double slashes because docBase ends with one
> - file = new File(docBase + pathInfo.substring(1));
> + // Get the file matching the Locale
> + //
> + File file = getLocalizedFile (docBase, pathInfo, request.getLocale());
> +
> String absPath = file.getAbsolutePath();
>
> if( debug > 0 ) contextF.log( "DefaultServlet: " + absPath);
> @@ -221,6 +219,69 @@
> "File Not Found<br>" + requestURI);
> }
> }
> + }
> +
> + static Locale defLoc = Locale.getDefault ();
> + static String dLang = defLoc.getLanguage ();
> + static String dCoun = defLoc.getCountry ();
> +
> + private static File checkFile (String base, String info)
> + {
> + File file = null;
> +
> + if ((info == null) || (info.length() < 1))
> + file = new File(base);
> + else // Avoid double slashes because docBase ends with one
> + file = new File(base + info.substring(1));
> +
> + return file;
> + }
> +
> + private static File getLocalizedFile (String dBase, String pInfo,
> + Locale loc)
> + {
> + String rLang = loc.getLanguage();
> + String rCoun = loc.getCountry();
> +
> + File file = null;
> +
> + // first, try with the provided language+country
> + //
> + String base = null;
> +
> + if (null != rCoun && ! ("".equals (rCoun)) )
> + {
> + base = dBase + rLang + "_" + rCoun + "/";
> + if ((file = checkFile(base, pInfo)).exists())
> + return file;
> + }
> +
> + // now, try with the provided language only
> + base = dBase + rLang + "/";
> +
> + if ((file = checkFile(base, pInfo)).exists())
> + return file;
> +
> + // now, try with the default language+country
> + //
> + if (null != dCoun && ! ("".equals (dCoun)) )
> + {
> + base = dBase + dLang + "_" + dCoun + "/";
> +
> + if ((file = checkFile(base, pInfo)).exists())
> + return file;
> + }
> +
> + // now, try with the default language
> + //
> + base = dBase + dLang + "/";
> +
> + if ((file = checkFile(base, pInfo)).exists())
> + return file;
> +
> + // now, try with nothing
> +
> + return checkFile(dBase, pInfo);
> }
>
> private String getWelcomeFile(File file) {
>
> 3.2 Code:
>
> ===================================================================
> RCS file: RCS/DefaultServlet.java,v
> retrieving revision 1.1
> diff -u -r1.1 DefaultServlet.java
> --- DefaultServlet.java 2000/06/20 22:40:23 1.1
> +++ DefaultServlet.java 2000/06/20 22:45:39
> @@ -130,12 +130,10 @@
> requestURI = request.getRequestURI();
> }
>
> - // Clean up pathInfo
> - File file = null;
> - if (pathInfo == null) // pathInfo can't be "" ( spec )
> - file = new File(docBase);
> - else // Avoid double slashes because docBase ends with one
> - file = new File(docBase + pathInfo.substring(1));
> + // Get the file matching the Locale
> + //
> + File file = getLocalizedFile (docBase, pathInfo, request.getLocale());
> +
> String absPath = file.getAbsolutePath();
>
> if( debug > 0 ) contextF.log( "DefaultServlet: " + absPath);
> @@ -221,6 +219,69 @@
> "File Not Found<br>" + requestURI);
> }
> }
> + }
> +
> + static Locale defLoc = Locale.getDefault ();
> + static String dLang = defLoc.getLanguage ();
> + static String dCoun = defLoc.getCountry ();
> +
> + private static File checkFile (String base, String info)
> + {
> + File file = null;
> +
> + if ((info == null) || (info.length() < 1))
> + file = new File(base);
> + else // Avoid double slashes because docBase ends with one
> + file = new File(base + info.substring(1));
> +
> + return file;
> + }
> +
> + private static File getLocalizedFile (String dBase, String pInfo,
> + Locale loc)
> + {
> + String rLang = loc.getLanguage();
> + String rCoun = loc.getCountry();
> +
> + File file = null;
> +
> + // first, try with the provided language+country
> + //
> + String base = null;
> +
> + if (null != rCoun && ! ("".equals (rCoun)) )
> + {
> + base = dBase + rLang + "_" + rCoun + "/";
> + if ((file = checkFile(base, pInfo)).exists())
> + return file;
> + }
> +
> + // now, try with the provided language only
> + base = dBase + rLang + "/";
> +
> + if ((file = checkFile(base, pInfo)).exists())
> + return file;
> +
> + // now, try with the default language+country
> + //
> + if (null != dCoun && ! ("".equals (dCoun)) )
> + {
> + base = dBase + dLang + "_" + dCoun + "/";
> +
> + if ((file = checkFile(base, pInfo)).exists())
> + return file;
> + }
> +
> + // now, try with the default language
> + //
> + base = dBase + dLang + "/";
> +
> + if ((file = checkFile(base, pInfo)).exists())
> + return file;
> +
> + // now, try with nothing
> +
> + return checkFile(dBase, pInfo);
> }
>
> private String getWelcomeFile(File file) {
>
>
> --
> Arieh Markel Sun Microsystems Inc.
> Network Storage 500 Eldorado Blvd. MS UBRM11-194
> e-mail: arieh.markel@sun.COM Broomfield, CO 80021
> Let's go Panthers !!!! Phone: (303) 272-8547 x78547
> (e-mail me with subject SEND PUBLIC KEY to get public key)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
|