/* Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE. */
// Contributors: Paul Hackenberger (unterminated entity handling in relaxed mode)
package org.kxml2.io;
import java.io.*;
import java.util.*;
import org.xmlpull.v1.*;
/** A simple, pull based XML parser. This classe replaces the kXML 1
XmlParser class and the corresponding event classes. */
public class KXmlParser implements XmlPullParser {
private Object location;
static final private String UNEXPECTED_EOF = "Unexpected EOF";
static final private String ILLEGAL_TYPE = "Wrong event type";
static final private int LEGACY = 999;
static final private int XML_DECL = 998;
// general
private String version;
private Boolean standalone;
private boolean processNsp;
private boolean relaxed;
private Hashtable entityMap;
private int depth;
private String[] elementStack = new String[16];
private String[] nspStack = new String[8];
private int[] nspCounts = new int[4];
// source
private Reader reader;
private String encoding;
private char[] srcBuf;
private int srcPos;
private int srcCount;
private int line;
private int column;
// txtbuffer
private char[] txtBuf = new char[128];
private int txtPos;
// Event-related
private int type;
//private String text;
private boolean isWhitespace;
private String namespace;
private String prefix;
private String name;
private boolean degenerated;
private int attributeCount;
private String[] attributes = new String[16];
private int stackMismatch = 0;
private String error;
/**
* A separate peek buffer seems simpler than managing
* wrap around in the first level read buffer */
private int[] peek = new int[2];
private int peekCount;
private boolean wasCR;
private boolean unresolved;
private boolean token;
public KXmlParser() {
srcBuf =
new char[Runtime.getRuntime().freeMemory() >= 1048576 ? 8192 : 128];
}
private final boolean isProp(String n1, boolean prop, String n2) {
if (!n1.startsWith("http://xmlpull.org/v1/doc/"))
return false;
if (prop)
return n1.substring(42).equals(n2);
else
return n1.substring(40).equals(n2);
}
private final boolean adjustNsp() throws XmlPullParserException {
boolean any = false;
for (int i = 0; i < attributeCount << 2; i += 4) {
// * 4 - 4; i >= 0; i -= 4) {
String attrName = attributes[i + 2];
int cut = attrName.indexOf(':');
String prefix;
if (cut != -1) {
prefix = attrName.substring(0, cut);
attrName = attrName.substring(cut + 1);
}
else if (attrName.equals("xmlns")) {
prefix = attrName;
attrName = null;
}
else
continue;
if (!prefix.equals("xmlns")) {
any = true;
}
else {
int j = (nspCounts[depth]++) << 1;
nspStack = ensureCapacity(nspStack, j + 2);
nspStack[j] = attrName;
nspStack[j + 1] = attributes[i + 3];
if (attrName != null && attributes[i + 3].equals(""))
error("illegal empty namespace");
// prefixMap = new PrefixMap (prefixMap, attrName, attr.getValue ());
//System.out.println (prefixMap);
System.arraycopy(
attributes,
i + 4,
attributes,
i,
((--attributeCount) << 2) - i);
i -= 4;
}
}
if (any) {
for (int i = (attributeCount << 2) - 4; i >= 0; i -= 4) {
String attrName = attributes[i + 2];
int cut = attrName.indexOf(':');
if (cut == 0 && !relaxed)
throw new RuntimeException(
"illegal attribute name: " + attrName + " at " + this);
else if (cut != -1) {
String attrPrefix = attrName.substring(0, cut);
attrName = attrName.substring(cut + 1);
String attrNs = getNamespace(attrPrefix);
if (attrNs == null && !relaxed)
throw new RuntimeException(
"Undefined Prefix: " + attrPrefix + " in " + this);
attributes[i] = attrNs;
attributes[i + 1] = attrPrefix;
attributes[i + 2] = attrName;
/*
if (!relaxed) {
for (int j = (attributeCount << 2) - 4; j > i; j -= 4)
if (attrName.equals(attributes[j + 2])
&& attrNs.equals(attributes[j]))
exception(
"Duplicate Attribute: {"
+ attrNs
+ "}"
+ attrName);
}
*/
}
}
}
int cut = name.indexOf(':');
if (cut == 0)
error("illegal tag name: " + name);
if (cut != -1) {
prefix = name.substring(0, cut);
name = name.substring(cut + 1);
}
this.namespace = getNamespace(prefix);
if (this.namespace == null) {
if (prefix != null)
error("undefined prefix: " + prefix);
this.namespace = NO_NAMESPACE;
}
return any;
}
private final String[] ensureCapacity(String[] arr, int required) {
if (arr.length >= required)
return arr;
String[] bigger = new String[required + 16];
System.arraycopy(arr, 0, bigger, 0, arr.length);
return bigger;
}
private final void error(String desc) throws XmlPullParserException {
if (relaxed) {
if (error == null)
error = "ERR: " + desc;
}
else
exception(desc);
}
private final void exception(String desc) throws XmlPullParserException {
throw new XmlPullParserException(
desc.length() < 100 ? desc : desc.substring(0, 100) + "\n",
this,
null);
}
/**
* common base for next and nextToken. Clears the state, except from
* txtPos and whitespace. Does not set the t
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
LBS_Android源码(定位系统) (136个子文件)
resources.ap_ 125KB
Cobub.apk 187KB
LocationService.class 6KB
GPSActivity.class 6KB
WIFIActivity.class 4KB
CellActivity.class 4KB
CellActivity$WSAsyncTask.class 3KB
WIFIActivity$WSAsyncTask.class 3KB
IPActivity$WSAsyncTask.class 3KB
GPSActivity$WSAsyncTask.class 3KB
Locations.class 3KB
AddressActivity$WSAsyncTask.class 3KB
AddressActivity.class 2KB
IPActivity.class 2KB
CobubMainActivity.class 2KB
GPSActivity$SampleLocationListener.class 2KB
R$id.class 2KB
Cord.class 1KB
AddressActivity$1.class 1020B
AddressActivity$2.class 1001B
CellActivity$1.class 996B
WIFIActivity$1.class 996B
GPSActivity$1.class 988B
WIFIActivity$2.class 983B
CellActivity$2.class 983B
IPActivity$1.class 980B
GPSActivity$2.class 977B
IPActivity$2.class 971B
R$drawable.class 798B
R.class 561B
Constants.class 556B
R$layout.class 528B
AboutActivity.class 516B
R$string.class 421B
R$menu.class 386B
R$attr.class 334B
CobubApp.class 290B
.classpath 280B
Thumbs.db 27KB
Thumbs.db 21KB
Thumbs.db 16KB
classes.dex 126KB
KXmlParser.java 39KB
WbxmlParser.java 31KB
WV.java 29KB
SoapSerializationEnvelope.java 20KB
KXmlSerializer.java 15KB
WbxmlSerializer.java 14KB
Node.java 11KB
GPSActivity.java 10KB
AddressActivity.java 9KB
Element.java 9KB
SoapEnvelope.java 9KB
LocationService.java 8KB
WIFIActivity.java 7KB
CellActivity.java 7KB
SoapObject.java 6KB
SyncML.java 6KB
HttpTransportSE.java 6KB
IPActivity.java 6KB
Base64.java 5KB
IsoDate.java 5KB
MarshalHashtable.java 5KB
Transport.java 4KB
R.java 4KB
Wml.java 4KB
Document.java 4KB
MapsActivity.java 4KB
SoapFault.java 3KB
CobubMainActivity.java 3KB
ServiceConnection.java 3KB
PropertyInfo.java 3KB
SoapPrimitive.java 3KB
Marshal.java 3KB
KvmSerializable.java 3KB
ServiceConnectionSE.java 3KB
DM.java 2KB
MarshalFloat.java 2KB
Wbxml.java 2KB
MarshalBase64.java 2KB
MarshalDate.java 2KB
Locations.java 2KB
FwdRef.java 1KB
Cord.java 813B
AboutActivity.java 304B
Constants.java 231B
CobubApp.java 113B
MyPositionOverlay.java 73B
background.png 30KB
background.png 30KB
background.png 30KB
getbyip.png 12KB
search_pressed.png 8KB
icon.png 8KB
header.png 7KB
icon.png 6KB
search.png 5KB
icon.png 5KB
about.png 4KB
about.png 4KB
共 136 条
- 1
- 2
javahr
- 粉丝: 23
- 资源: 38
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页