00001 package cedar.hepdata.webapp.services;
00002
00003 import java.io.IOException;
00004
00005 import org.apache.commons.logging.Log;
00006 import org.apache.tapestry.ioc.Configuration;
00007 import org.apache.tapestry.ioc.MappedConfiguration;
00008 import org.apache.tapestry.ioc.OrderedConfiguration;
00009
00010 import org.apache.tapestry.ioc.annotations.InjectService;
00011 import org.apache.tapestry.services.Request;
00012 import org.apache.tapestry.services.RequestFilter;
00013 import org.apache.tapestry.services.RequestHandler;
00014 import org.apache.tapestry.services.Response;
00015
00020 public class AppModule {
00021
00022
00023 public void contributeHibernateSessionSource(Configuration<String> cfg) {
00024 cfg.add("cedar.hepdata.model");
00025 }
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 public static void contributeApplicationDefaults(
00041 MappedConfiguration<String, String> configuration)
00042 {
00043
00044
00045
00046
00047
00048
00049 configuration.add("tapestry.supported-locales", "en");
00050 }
00051
00052
00071 public RequestFilter buildTimingFilter(final Log log)
00072 {
00073 return new RequestFilter()
00074 {
00075 public boolean service(Request request, Response response, RequestHandler handler)
00076 throws IOException
00077 {
00078 long startTime = System.currentTimeMillis();
00079
00080 try
00081 {
00082
00083
00084
00085
00086 return handler.service(request, response);
00087 }
00088 finally
00089 {
00090 long elapsed = System.currentTimeMillis() - startTime;
00091
00092 log.info(String.format("Request time: %d ms", elapsed));
00093 }
00094 }
00095 };
00096 }
00097
00103 public void contributeRequestHandler(OrderedConfiguration<RequestFilter> configuration,
00104 @InjectService("TimingFilter")
00105 RequestFilter filter)
00106 {
00107
00108
00109
00110
00111 configuration.add("Timing", filter);
00112 }
00113 }