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 public class WapSIPush implements WbxmlDocument
47 {
48 public static final String WBXML_CONTENT_TYPE = "application/vnd.wap.sic";
49 public static final String XML_CONTENT_TYPE = "text/vnd.wap.si";
50
51 public static final String[] SI_TAG_TOKENS = {
52 "si",
53 "indication",
54 "info",
55 "item",
56 };
57
58 public static final String[] SI_ATTR_START_TOKENS = {
59 "action=signal-none",
60 "action=signal-low",
61 "action=signal-medium",
62 "action=signal-high",
63 "action=delete",
64 "created",
65 "href",
66 "href=http://", // 0C
67 "href=http://www.", // 0D
68 "href=https://", // 0E
69 "href=https://www.", // 0F
70
71 "si-expires",
72 "si-id",
73 "class",
74 };
75
76 public static final String[] SI_ATTR_VALUE_TOKENS = {
77 ".com/",
78 ".edu/",
79 ".net/",
80 ".org/",
81 };
82
83 protected String myUri;
84 protected String myId;
85 protected Date myCreated;
86 protected Date myExpires;
87 protected String myAction;
88
89 protected String myMessage;
90
91 public WapSIPush(String uri, String message)
92 {
93 myUri = uri;
94 myMessage = message;
95 }
96
97
98
99
100
101
102
103 private byte[] encodeDateTime(Date theDate)
104 {
105 return null;
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 }
121
122 public String getUri()
123 {
124 return myUri;
125 }
126
127 public void setUri(String uri)
128 {
129 myUri = uri;
130 }
131
132 public String getId()
133 {
134 return myId;
135 }
136
137 public void setId(String id)
138 {
139 myId = id;
140 }
141
142 public Date getCreated()
143 {
144 return myCreated;
145 }
146
147 public void setCreated(Date created)
148 {
149 myCreated = created;
150 }
151
152 public Date getExpires()
153 {
154 return myExpires;
155 }
156
157 public void setExpires(Date expires)
158 {
159 myExpires = (Date) expires.clone();
160 }
161
162 public String getAction()
163 {
164 return myAction;
165 }
166
167 public void setAction(String action)
168 {
169 myAction = action;
170 }
171
172 public String getMessage()
173 {
174 return myMessage;
175 }
176
177 public void setMessage(String message)
178 {
179 myMessage = message;
180 }
181
182 public void writeXmlTo(XmlWriter writer) throws IOException
183 {
184 writer.setDoctype("si", "-//WAPFORUM//DTD SI 1.0//EN", "http://www.wapforum.org/DTD/si.dtd");
185
186 writer.addStartElement("si");
187 writer.addStartElement("indication", new XmlAttribute[]{new XmlAttribute("href", myUri)});
188 writer.addCharacters(myMessage);
189 writer.addEndElement();
190 writer.addEndElement();
191
192 writer.flush();
193 }
194
195 public XmlWriter getWbxmlWriter(OutputStream os)
196 {
197 return new WbxmlWriter(os, WapSIPush.SI_TAG_TOKENS, WapSIPush.SI_ATTR_START_TOKENS, WapSIPush.SI_ATTR_VALUE_TOKENS);
198 }
199
200 public String getWbxmlContentType()
201 {
202 return WBXML_CONTENT_TYPE;
203 }
204
205 public String getContentType()
206 {
207 return XML_CONTENT_TYPE;
208 }
209 }