Differences between revisions 2 and 3
Revision 2 as of 2008-11-09 22:54:37
Size: 2347
Comment:
Revision 3 as of 2009-09-20 23:20:48
Size: 2347
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

Inside AppModule.java:

   1     @Inject
   2     private RequestGlobals requestGlobals;
   3 
   4     @Inject
   5     private ThreadLocale threadLocale;
   6 
   7     public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
   8             @InjectService("TimingFilter")
   9             RequestFilter filter,
  10             ThreadLocale locale)
  11     {
  12         // Each contribution to an ordered configuration has a name, When necessary, you may
  13         // set constraints to precisely control the invocation order of the contributed filter
  14         // within the pipeline.
  15 
  16         Map<String, Locale> serverNameMapping = new HashMap<String,Locale>();
  17         
  18         serverNameMapping.put("www.domain.com", Locale.ENGLISH);
  19         serverNameMapping.put("www.domain.de", Locale.GERMAN);
  20         serverNameMapping.put("www.domain.fr", Locale.FRENCH);
  21         
  22         configuration.add("Timing", filter);
  23         configuration.add("HostBasedLocalization", new HostBasedLocaleFilter(threadLocale, Locale.GERMAN, serverNameMapping), "after:Localization");
  24 
  25     }

HostBasedLocaleFilter.java

   1 import java.io.IOException;
   2 import java.util.Locale;
   3 import java.util.Map;
   4 
   5 import org.apache.tapestry.ioc.services.ThreadLocale;
   6 import org.apache.tapestry.services.Request;
   7 import org.apache.tapestry.services.RequestFilter;
   8 import org.apache.tapestry.services.RequestHandler;
   9 import org.apache.tapestry.services.Response;
  10 
  11 public class HostBasedLocaleFilter implements RequestFilter {
  12 
  13         private Map<String, Locale> serverNameMapping;
  14 
  15         private Locale              defaultLocale;
  16 
  17         private ThreadLocale        threadLocale;
  18 
  19         public HostBasedLocaleFilter(final ThreadLocale threadLocale, final Locale defaultLocale, final Map<String, Locale> serverNameMapping) {
  20                 this.serverNameMapping = serverNameMapping;
  21                 this.defaultLocale = defaultLocale;
  22                 this.threadLocale = threadLocale;
  23         }
  24 
  25         public boolean service(Request request, Response response, RequestHandler handler) throws IOException {
  26                 String servername = request.getParameter("Host");
  27                 System.out.println(servername);
  28                 Locale locale = this.serverNameMapping.get(servername);
  29                 if (locale == null) {
  30                         locale = this.defaultLocale;
  31                 }
  32                 threadLocale.setLocale(locale);
  33                                 
  34                 return handler.service(request, response);
  35         }
  36 
  37 }

Tapestry5HowToDomainLevelLocalization (last edited 2009-09-20 23:20:48 by localhost)