01: /* LabelLocatorHook.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Apr 7 16:49:15 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.web.init;
20:
21: import javax.servlet.ServletContextListener;
22: import javax.servlet.ServletContextEvent;
23: import javax.servlet.ServletContext;
24:
25: //import org.zkoss.util.logging.Log;
26: import org.zkoss.util.resource.Labels;
27: import org.zkoss.web.util.resource.ServletLabelLocator;
28: import org.zkoss.web.util.resource.ServletLabelResovler;
29:
30: /**
31: * Used to hook a label locator to locate resources from the servlet context.
32: *
33: * <p>Note: you don't need to specify this in web.xml if you use ZK
34: * because org.zkoss.zk.ui.DHtmlLayoutServlet will register the label locator
35: * automatically.
36: *
37: * <p>If you don't use ZK, you could declare
38: <pre><code>
39: <listener>
40: <description>Load i3-label.properties from this Web app</description>
41: <display-name>Locating i3-label.properties</display-name>
42: <listener-class>org.zkoss.web.init.LabelLocatorHook</listener-class>
43: </listener>
44: </code></pre>
45: *
46: * @author tomyeh
47: */
48: public class LabelLocatorHook implements ServletContextListener {
49: //private static final Log log = Log.lookup(LabelLocatorHook.class);
50:
51: public void contextDestroyed(ServletContextEvent sce) {
52: }
53:
54: public void contextInitialized(ServletContextEvent sce) {
55: final ServletContext ctx = sce.getServletContext();
56: //if (log.debugable()) log.debug("Hook label locator for "+ctx);
57:
58: Labels.register(new ServletLabelLocator(ctx));
59: Labels.setVariableResolver(new ServletLabelResovler());
60: }
61: }
|