01: /* JavaScript.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Aug 11 15:29:37 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.servlet;
20:
21: import org.zkoss.lang.Objects;
22:
23: /**
24: * Represents a javascript.
25: *
26: * @author tomyeh
27: */
28: public class JavaScript {
29: private final String _src, _charset, _content;
30:
31: /** Creates by specifying the file to contain the JavaScript codes.
32: *
33: * @param src URI of the file containing the JavaScript codes.
34: * @param charset the charset. If null, "UTF-8" is assumed.
35: */
36: public JavaScript(String src, String charset) {
37: if (src == null)
38: throw new IllegalArgumentException("null src");
39: if (charset == null || charset.length() == 0)
40: charset = "UTF-8";
41:
42: _src = src;
43: _charset = charset;
44: _content = null;
45: }
46:
47: /** Creates by assigning the content (JavaScript codes).
48: *
49: * @param content the JavaScript codes.
50: */
51: public JavaScript(String content) {
52: if (content == null)
53: throw new IllegalArgumentException("null content");
54: _src = _charset = null;
55: _content = content;
56: }
57:
58: /** Returns the URI of the file containing the JavaScript codes,
59: * or null if {@link #getContent} is not null.
60: */
61: public String getSrc() {
62: return _src;
63: }
64:
65: /** Returns the charset, or null if {@link #getContent} is not null. */
66: public String getCharset() {
67: return _charset;
68: }
69:
70: /** Returns the JavaScript codes, or null if {@link #getSrc} is not null.
71: */
72: public String getContent() {
73: return _content;
74: }
75:
76: //-- Object --//
77: public String toString() {
78: return "[src: " + _src + " charset=" + _charset + ']';
79: }
80:
81: public int hashCode() {
82: return _src.hashCode() + _charset.hashCode();
83: }
84:
85: public boolean equals(Object o) {
86: if (!(o instanceof JavaScript))
87: return false;
88: final JavaScript js = (JavaScript) o;
89: return Objects.equals(js._src, _src)
90: && Objects.equals(js._charset, _charset)
91: && Objects.equals(js._content, _content);
92: }
93: }
|