01: /* ServletLabelLocator.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Sat Apr 8 19:51:08 2006, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2006 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.util.resource;
20:
21: import java.util.Locale;
22: import java.io.IOException;
23: import java.net.URL;
24: import javax.servlet.ServletContext;
25:
26: import org.zkoss.util.resource.LabelLocator;
27:
28: /**
29: * Used by Lables to load labels from a servlet context.
30: *
31: * @author tomyeh
32: */
33: public class ServletLabelLocator implements LabelLocator {
34: private final ServletContext _ctx;
35:
36: public ServletLabelLocator(ServletContext ctx) {
37: if (ctx == null)
38: throw new IllegalArgumentException("null");
39: _ctx = ctx;
40: }
41:
42: //-- LabelLocator --//
43: public URL locate(Locale locale) throws IOException {
44: return _ctx.getResource("/WEB-INF/" + getI3LabelName(locale));
45: }
46:
47: /** Returns the filename of i3-label.properties. */
48: private static final String getI3LabelName(Locale locale) {
49: return locale.equals(Locale.ENGLISH) ? "i3-label.properties"
50: : "i3-label_" + locale + ".properties";
51: }
52:
53: //-- Object --//
54: public int hashCode() {
55: return _ctx.hashCode();
56: }
57:
58: public boolean equals(Object o) {
59: return o instanceof ServletLabelLocator
60: && ((ServletLabelLocator) o)._ctx.equals(_ctx);
61: }
62: }
|