1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.marre.wap.push;
36
37 import java.io.IOException;
38 import java.io.OutputStream;
39 import java.util.Date;
40
41 import org.marre.wap.wbxml.WbxmlDocument;
42 import org.marre.wap.wbxml.WbxmlWriter;
43 import org.marre.xml.XmlAttribute;
44 import org.marre.xml.XmlWriter;
45
46 /***
47 * Represents a WAP Service Loading Push message.
48 *
49 * @author Markus
50 * @version $Id: WapSLPush.java,v 1.1 2005/08/02 19:57:32 c95men Exp $
51 */
52 public class WapSLPush implements WbxmlDocument
53 {
54 /*** WBXML content type */
55 public static final String WBXML_CONTENT_TYPE = "application/vnd.wap.slc";
56 /*** XML content type */
57 public static final String XML_CONTENT_TYPE = "text/vnd.wap.sl";
58
59 /*** Action, execute-low */
60 public static final String ACTION_EXECUTE_LOW = "execute-low";
61 /*** Action, execute-high */
62 public static final String ACTION_EXECUTE_HIGH = "execute-high";
63 /*** Action, execute-cache */
64 public static final String ACTION_EXECUTE_CACHE = "execute-cache";
65
66 /*** WBXML tag tokens for wap sl push. */
67 public static final String[] SL_TAG_TOKENS = {
68 "sl",
69 };
70
71 /*** WBXML attr start tokens for wap sl push. */
72 public static final String[] SL_ATTR_START_TOKENS = {
73 "action=execute-low",
74 "action=execute-high",
75 "action=cache",
76 "href",
77 "href=http://", // 09
78 "href=http://www.", // 0A
79 "href=https://", // 0B
80 "href=https://www.", // 0C
81 };
82
83 /*** WBXML attr value tokens for wap sl push. */
84 public static final String[] SL_ATTR_VALUE_TOKENS = {
85 ".com/",
86 ".edu/",
87 ".net/",
88 ".org/",
89 };
90
91
92 /*** The uri. */
93 protected String uri_;
94 /*** The action. */
95 protected String action_;
96
97 /***
98 * Constructor.
99 *
100 * @param uri
101 */
102 public WapSLPush(String uri)
103 {
104 uri_ = uri;
105 }
106
107 /***
108 * Returns the URI.
109 *
110 * @return
111 */
112 public String getUri()
113 {
114 return uri_;
115 }
116
117 /***
118 * Sets the URI.
119 * @param uri
120 */
121 public void setUri(String uri)
122 {
123 uri_ = uri;
124 }
125
126 /***
127 * Retrieves the current set action.
128 *
129 * @return Action or null if not set.
130 */
131 public String getAction()
132 {
133 return action_;
134 }
135
136 /***
137 * Set the action.
138 *
139 * @param action Can be ACTION_EXECUTE_LOW, ACTION_EXECUTE_HIGH or ACTION_EXECUTE_CACHE.
140 */
141 public void setAction(String action)
142 {
143 if (! (ACTION_EXECUTE_CACHE.equals(action) ||
144 ACTION_EXECUTE_HIGH.equals(action) ||
145 ACTION_EXECUTE_LOW.equals(action)) ) {
146 throw new IllegalArgumentException("Action can only be execute-high, execute-low or cache.");
147 }
148 action_ = action;
149 }
150
151 /***
152 * Writes the xml document to the given writer.
153 *
154 * @param writer
155 */
156 public void writeXmlTo(XmlWriter writer) throws IOException
157 {
158 writer.setDoctype("sl", "-//WAPFORUM//DTD SL 1.0//EN", "http://www.wapforum.org/DTD/sl.dtd");
159
160 if (action_ == null) {
161 writer.addEmptyElement("sl", new XmlAttribute[]{new XmlAttribute("href", uri_)});
162 } else {
163 writer.addEmptyElement("sl", new XmlAttribute[]{new XmlAttribute("href", uri_),
164 new XmlAttribute("action", action_)});
165 }
166
167 writer.flush();
168 }
169
170 /***
171 * Returns a wbxml writer.
172 *
173 * @param os The os to write to.
174 * @return Wbxml writer.
175 */
176 public XmlWriter getWbxmlWriter(OutputStream os)
177 {
178 return new WbxmlWriter(os, WapSLPush.SL_TAG_TOKENS, WapSLPush.SL_ATTR_START_TOKENS, WapSLPush.SL_ATTR_VALUE_TOKENS);
179 }
180
181 /***
182 * Returns the wbxml content type.
183 *
184 * @return wbxml content type.
185 */
186 public String getWbxmlContentType()
187 {
188 return WBXML_CONTENT_TYPE;
189 }
190
191 /***
192 * Returns the text content type.
193 *
194 * @return Content type
195 */
196 public String getContentType()
197 {
198 return XML_CONTENT_TYPE;
199 }
200 }