01: /* Context.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: May 28, 2007 7:15:37 PM, Created by henrichen
10: }}IS_NOTE
11:
12: Copyright (C) 2007 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.zkmob;
20:
21: import java.io.IOException;
22: import java.util.Hashtable;
23:
24: import javax.microedition.io.HttpConnection;
25: import javax.microedition.lcdui.Display;
26:
27: /**
28: * UiFactory Connection Context.
29: *
30: * @author henrichen
31: *
32: */
33: public class Context {
34: HttpConnection _conn;
35: String _prefix;
36: Display _disp;
37:
38: public Context(HttpConnection conn, Display disp) {
39: _conn = conn;
40: _disp = disp;
41: }
42:
43: /**
44: * Prefix the url with current connection if a relative url path.
45: * @param url the url to be prefix.
46: * @return prefix url.
47: */
48: public String prefixURL(String url) {
49: if (url != null && !url.startsWith("http://")
50: && !url.startsWith("https://")) {
51: url = getPrefix() + url;
52: }
53: return url;
54: }
55:
56: /**
57: * Get the Mobile Display
58: * @return the mobile display
59: */
60: public Display getDisplay() {
61: return _disp;
62: }
63:
64: private String getPrefix() {
65: if (_prefix == null) {
66: _prefix = _conn.getProtocol()
67: + "://"
68: + _conn.getHost()
69: + (_conn.getPort() != 80 ? (":" + _conn.getPort())
70: : "");
71: }
72: return _prefix;
73: }
74: }
|