1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is "SMS Library for the Java platform".
15 *
16 * The Initial Developer of the Original Code is Markus Eriksson.
17 * Portions created by the Initial Developer are Copyright (C) 2002
18 * the Initial Developer. All Rights Reserved.
19 *
20 * Contributor(s):
21 *
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the MPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the MPL, the GPL or the LGPL.
33 *
34 * ***** END LICENSE BLOCK ***** */
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", // 05
53 "indication", // 06
54 "info", // 07
55 "item", // 08
56 };
57
58 public static final String[] SI_ATTR_START_TOKENS = {
59 "action=signal-none", // 05
60 "action=signal-low", // 06
61 "action=signal-medium", // 07
62 "action=signal-high", // 08
63 "action=delete", // 09
64 "created", // 0A
65 "href", // 0B
66 "href=http://", // 0C
67 "href=http://www.", // 0D
68 "href=https://", // 0E
69 "href=https://www.", // 0F
70
71 "si-expires", // 10
72 "si-id", // 11
73 "class", // 12
74 };
75
76 public static final String[] SI_ATTR_VALUE_TOKENS = {
77 ".com/", // 85
78 ".edu/", // 86
79 ".net/", // 87
80 ".org/", // 88
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 * public static void main(String argv[]) throws Exception { SIPush push =
99 * new SIPush("http://wap.tv4.se/", "TV4 Nyheter");
100 * push.writeTo(getWbxmlWriter(), new FileOutputStream("si.wbxml")); }
101 */
102
103 private byte[] encodeDateTime(Date theDate)
104 {
105 return null;
106 /*
107 * If used, the attribute value MUST be expressed in a date/time
108 * representation based on [ISO8601] as specified in [HTML4]. However,
109 * SI does not allow use of time zones; the time MUST always be
110 * expressed in Co-ordinated Universal Time (UTC), a 24-hour timekeeping
111 * system (indicated by the ?Z?). The format is: YYYY-MM-DDThh:mm:ssZ
112 * Where: YYYY = 4 digit year (?0000? ... ?9999?) MM = 2 digit month
113 * (?01?=January, ?02?=February ... ?12?=December) DD = 2 digit day
114 * (?01?, ?02? ... ?31?) hh = 2 digit hour, 24-hour timekeeping system
115 * (00 ... 23) mm = 2 digit minute (?00? ... ?59?) ss = 2 digit second
116 * (?00? ... ?59?) Note: T and Z appear literally in the string.
117 * Example: 1999-04-30T06:40:00Z means 6.40 in the morning UTC on the
118 * 30th of April 1999.
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 }