/**
* JWAP - A Java Implementation of the WAP Protocols
* Copyright (C) 2001-2004 Niko Bender
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package net.sourceforge.jwap.wsp.header;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import net.sourceforge.jwap.util.Logger;
import net.sourceforge.jwap.util.TransTable;
import net.sourceforge.jwap.wsp.WSPDecoder;
/**
* This class implements the WAP default codepage for Header encoding/decoding
*
* @author Michel Marti
*/
public class WAPCodePage extends CodePage {
private static final String TT_CTENC = "content-encoding";
private static final String TT_WKPARMS = "wk-params-1.3";
private static final String TT_CHARSETS = "charsets";
private static final String TT_LNG = "languages";
private static final String TT_CCONTROL = "cache-control";
private static final String TT_CTYPES = "content-types-1.3";
private static final Logger log = Logger.getLogger(WAPCodePage.class);
private static SimpleDateFormat fmt = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz");
private TransTable transTable;
/**
* Construct a new WAP Code Page. Encoding is done according to WAP encoding
* version 1.1
* @throws IOException if the code-page translation table cannot be found
*/
protected WAPCodePage() throws IOException {
this(1, 1);
}
/**
* Construct a new WAP Code Page
* @param major WAP major version
* @param minor WAP minor version
* @throws IOException if the code-page translation table cannot be found
*/
protected WAPCodePage(int major, int minor) throws IOException {
super(1, true, "default");
StringBuffer rn = new StringBuffer("wsp-headers-").append(major)
.append(".").append(minor);
transTable = TransTable.getTable(rn.toString());
}
/**
* Returns an instance of the WAP Codepage. Encoding is done according
* to encoding version 1.1
*/
public static WAPCodePage getInstance() {
try {
return new WAPCodePage(1,1);
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
}
/**
* Returns an instance of the WAP Codepage. Encoding is done according
* to the specified encoding version.
* @param major the major encoding version
* @param minor the minor encoding version
* @throws IllegalArgumentException if no encoding exists for the
* specified major/minor version
*/
public static WAPCodePage getInstance(int major, int minor)
throws IllegalArgumentException {
try {
return new WAPCodePage(major, minor);
} catch (IOException e) {
throw new IllegalArgumentException(major + "." + minor +
": No encoding available");
}
}
public byte[] encode(String key, String value) throws HeaderParseException {
String lowKey = key.toLowerCase().trim();
Object o = transTable.str2code(lowKey);
if (log.isDebugEnabled()) {
log.debug("encode: '" + key + "' -> " + o);
}
// Not a Well-Known value?
if (o == null) {
if (log.isDebugEnabled()) {
log.debug(key +
": Not a well known value, using text-string encoding");
}
return Encoding.encodeHeader(key, Encoding.textString(value));
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
short wk = ((Integer) o).shortValue();
try {
if ("content-base".equals(lowKey)) {
throw new HeaderParseException(key +
": Deprecated Header field");
}
try {
// Invoke handler using reflection..
encodeHeader(lowKey, out, wk, value);
} catch (NoSuchMethodException nsme) {
log.warn(key +
": No handler for this header, using text-string encoding");
out.write(Encoding.encodeHeader(wk, Encoding.textString(value)));
}
} catch (HeaderParseException hpe) {
throw hpe;
} catch (IOException ex) {
throw new HeaderParseException("I/O Error while encoding.", ex);
} catch (Exception uex) {
log.warn("Unexpected exception while encoding "+key+"="+value, uex);
throw new HeaderParseException("Unexpected exception while encoding.",
uex);
}
return out.toByteArray();
}
public byte[] encode(String key, Date value) {
Object o = transTable.str2code(key.trim());
long secs = (value == null) ? 0 : (value.getTime() / 1000);
byte[] hv = Encoding.longInteger(secs);
if (o == null) {
return Encoding.encodeHeader(key, hv);
} else {
return Encoding.encodeHeader(((Integer) o).shortValue(), hv);
}
}
public byte[] encode(String key, long value) throws HeaderParseException {
Object o = transTable.str2code(key.trim());
short wk = ((o == null) ? (-1) : ((Integer) o).shortValue());
if (value < 0) {
throw new HeaderParseException(value +
": negative integer values not accepted");
}
byte[] hv = Encoding.integerValue(value);
if (o == null) {
return Encoding.encodeHeader(key, hv);
} else {
return Encoding.encodeHeader(wk, hv);
}
}
public void encodeAccept(OutputStream hdrs, short wk, String value)
throws IOException {
for (Enumeration e = HeaderToken.tokenize(value); e.hasMoreElements();) {
HeaderToken ht = (HeaderToken) e.nextElement();
String token = ht.getToken();
// Lookup content-type
Integer code = TransTable.getTable(TT_CTYPES).str2code(token);
if (code == null) {
hdrs.write(Encoding.encodeHeader(wk, Encoding.textString(token)));
} else {
hdrs.write(Encoding.encodeHeader(wk,
Encoding.shortInteger(code.shortValue())));
}
}
}
public void encodeAcceptCharset(OutputStream hdrs, short wk, String value)
throws IOException {
for (Enumeration e = HeaderToken.tokenize(value); e.hasMoreElements();) {
HeaderToken ht = (HeaderToken) e.nextElement();
String token = ht.getToken();
if ("*".equals(token)) {
hdrs.write(new byte[] { (byte) wk, (byte) 0xff });
continue;
}
Integer wkl = TransTable.getTable(TT_CHARSETS).str2code(token);
String qf = ht.getParameter("q");
if (qf == null) {
if (wkl != null) {
hdrs.write(Encoding.encodeHeader(wk,
Encoding.integerValue(wkl.longValue())));
} else {
hdrs.write(Encoding.encodeHeader(wk,
Encoding.extensionMedia(to
没有合适的资源?快使用搜索试试~ 我知道了~
jWAP-1.2-src.tar.gz_wap_wap stack
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 118 浏览量
2022-09-22
16:47:54
上传
评论
收藏 1.36MB GZ 举报
温馨提示
共186个文件
java:78个
xml:38个
wbxml:16个
WAP Stack implementation jwap.sourceforge.net
资源推荐
资源详情
资源评论
收起资源包目录
jWAP-1.2-src.tar.gz_wap_wap stack (186个子文件)
content-types-1.1 1KB
wsp-headers-1.1 781B
wk-params-1.1 95B
content-types-1.2 2KB
wsp-headers-1.2 969B
wk-params-1.2 137B
content-types-1.3 2KB
wsp-headers-1.3 1KB
wk-params-1.3 197B
content-types-1.4 2KB
wsp-headers-1.4 1KB
wk-params-1.4 282B
content-types-1.5 2KB
wsp-headers-1.5 1KB
encode.bat 3KB
decode.bat 3KB
cache-control 179B
CHANGELOG 4KB
charsets 4KB
content-encoding 59B
syncml_represent_v11_20020213.dtd 7KB
syncml_represent_v11_20020213.dtd 7KB
package.html 110B
package.html 102B
package.html 101B
package.html 98B
package.html 92B
package.html 92B
package.html 89B
package.html 79B
package.html 78B
http-status-codes 801B
xerces-2.4.0.jar 875KB
log4j-1.2.8.jar 344KB
junit-3.8.1.jar 118KB
xml-apis-1.0.b2.jar 107KB
WAPCodePage.java 31KB
CWSPSession.java 30KB
CWTPInitiator.java 30KB
WAPClient.java 20KB
CWTPResponder.java 19KB
CWSPMethodManager.java 17KB
CWSPHeaders.java 16KB
XMLContentHandler.java 15KB
WBXMLDecoder.java 15KB
CWSPPDU.java 14KB
CWSPCapabilities.java 13KB
BitArrayOutputStream.java 12KB
BitArrayInputStream.java 12KB
CWTPSocket.java 11KB
TokenRepository.java 10KB
CWTPPDU.java 9KB
WAPCodePageTest.java 8KB
CWTPEvent.java 8KB
CWTPInvoke.java 7KB
WMLExample.java 6KB
CWapGetExample2.java 6KB
Encoding.java 6KB
PublicIdentifiers.java 6KB
CWapGetExample.java 6KB
CodePage.java 5KB
CWapPostExample.java 5KB
Logger.java 5KB
CWSPAddress.java 5KB
CWSPRedirect.java 5KB
CWSPReply.java 5KB
TransTable.java 5KB
MultiPartData.java 5KB
CWTPAbort.java 5KB
WSPDecoder.java 5KB
WSPDecoderTest.java 5KB
WBXMLEncoder.java 4KB
Response.java 4KB
MultiPartEntry.java 4KB
CWTPAck.java 4KB
HeaderToken.java 4KB
Utils.java 4KB
CWTPResult.java 4KB
EncodingTest.java 3KB
WBXMLConverter.java 3KB
SwingWorker.java 3KB
CWSPPost.java 3KB
CWSPPushManager.java 3KB
IANACharSet.java 2KB
CWSPConnect.java 2KB
CWSPResult.java 2KB
GlobalTokens.java 2KB
PostRequest.java 2KB
CWSPPush.java 2KB
CWSPConnectReply.java 2KB
CWTPSegmResult.java 2KB
HeaderParseException.java 2KB
CWSPDataFragment.java 2KB
CWTPSegmInvoke.java 2KB
CWSPGet.java 2KB
AttributeNameToken.java 2KB
Request.java 2KB
CWSPResume.java 2KB
CWSPDisconnect.java 2KB
IWTPTransaction.java 2KB
共 186 条
- 1
- 2
资源评论
weixin_42651887
- 粉丝: 80
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功