📄 kxmlparser.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2008-6-16 11:16:50
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
package org.kxml2.io;
import java.io.*;
import java.util.Hashtable;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
public class KXmlParser
implements XmlPullParser
{
public KXmlParser()
{
elementStack = new String[16];
nspStack = new String[8];
nspCounts = new int[4];
txtBuf = new char[128];
attributes = new String[16];
stackMismatch = 0;
peek = new int[2];
srcBuf = new char[Runtime.getRuntime().freeMemory() < 0x100000L ? '\200' : 8192];
}
private final boolean isProp(String s, boolean flag, String s1)
{
if(!s.startsWith("http://xmlpull.org/v1/doc/"))
return false;
if(flag)
return s.substring(42).equals(s1);
else
return s.substring(40).equals(s1);
}
private final boolean adjustNsp()
throws XmlPullParserException
{
boolean flag = false;
for(int i = 0; i < attributeCount << 2; i += 4)
{
String s = attributes[i + 2];
int l = s.indexOf(':');
String s2;
if(l != -1)
{
s2 = s.substring(0, l);
s = s.substring(l + 1);
} else
{
if(!s.equals("xmlns"))
continue;
s2 = s;
s = null;
}
if(!s2.equals("xmlns"))
{
flag = true;
continue;
}
int j1 = nspCounts[depth]++ << 1;
nspStack = ensureCapacity(nspStack, j1 + 2);
nspStack[j1] = s;
nspStack[j1 + 1] = attributes[i + 3];
if(s != null && attributes[i + 3].equals(""))
error("illegal empty namespace");
System.arraycopy(attributes, i + 4, attributes, i, (--attributeCount << 2) - i);
i -= 4;
}
if(flag)
{
for(int j = (attributeCount << 2) - 4; j >= 0; j -= 4)
{
String s1 = attributes[j + 2];
int i1 = s1.indexOf(':');
if(i1 == 0 && !relaxed)
throw new RuntimeException("illegal attribute name: " + s1 + " at " + this);
if(i1 == -1)
continue;
String s3 = s1.substring(0, i1);
s1 = s1.substring(i1 + 1);
String s4 = getNamespace(s3);
if(s4 == null && !relaxed)
throw new RuntimeException("Undefined Prefix: " + s3 + " in " + this);
attributes[j] = s4;
attributes[j + 1] = s3;
attributes[j + 2] = s1;
}
}
int k = name.indexOf(':');
if(k == 0)
error("illegal tag name: " + name);
if(k != -1)
{
prefix = name.substring(0, k);
name = name.substring(k + 1);
}
namespace = getNamespace(prefix);
if(namespace == null)
{
if(prefix != null)
error("undefined prefix: " + prefix);
namespace = "";
}
return flag;
}
private final String[] ensureCapacity(String as[], int i)
{
if(as.length >= i)
{
return as;
} else
{
String as1[] = new String[i + 16];
System.arraycopy(as, 0, as1, 0, as.length);
return as1;
}
}
private final void error(String s)
throws XmlPullParserException
{
if(relaxed)
{
if(error == null)
error = "ERR: " + s;
} else
{
exception(s);
}
}
private final void exception(String s)
throws XmlPullParserException
{
throw new XmlPullParserException(s.length() >= 100 ? s.substring(0, 100) + "\n" : s, this, null);
}
private final void nextImpl()
throws IOException, XmlPullParserException
{
if(reader == null)
exception("No Input specified");
if(type == 3)
depth--;
do
{
attributeCount = -1;
if(degenerated)
{
degenerated = false;
type = 3;
return;
}
if(error != null)
{
for(int i = 0; i < error.length(); i++)
push(error.charAt(i));
error = null;
type = 9;
return;
}
if(relaxed && (stackMismatch > 0 || peek(0) == -1 && depth > 0))
{
int j = depth - 1 << 2;
type = 3;
namespace = elementStack[j];
prefix = elementStack[j + 1];
name = elementStack[j + 2];
if(stackMismatch != 1)
error = "missing end tag /" + name + " inserted";
if(stackMismatch > 0)
stackMismatch--;
return;
}
prefix = null;
name = null;
namespace = null;
type = peekType();
switch(type)
{
case 6: // '\006'
pushEntity();
return;
case 2: // '\002'
parseStartTag(false);
return;
case 3: // '\003'
parseEndTag();
return;
case 1: // '\001'
return;
case 4: // '\004'
pushText(60, !token);
if(depth == 0 && isWhitespace)
type = 7;
return;
case 5: // '\005'
default:
type = parseLegacy(token);
break;
}
} while(type == 998);
}
private final int parseLegacy(boolean flag)
throws IOException, XmlPullParserException
{
String s = "";
int i = 0;
read();
int j = read();
byte byte0;
byte byte1;
if(j == 63)
{
if((peek(0) == 120 || peek(0) == 88) && (peek(1) == 109 || peek(1) == 77))
{
if(flag)
{
push(peek(0));
push(peek(1));
}
read();
read();
if((peek(0) == 108 || peek(0) == 76) && peek(1) <= 32)
{
if(line != 1 || column > 4)
error("PI must not start with xml");
parseStartTag(true);
if(attributeCount < 1 || !"version".equals(attributes[2]))
error("version expected");
version = attributes[3];
int l = 1;
if(l < attributeCount && "encoding".equals(attributes[6]))
{
encoding = attributes[7];
l++;
}
if(l < attributeCount && "standalone".equals(attributes[4 * l + 2]))
{
String s1 = attributes[3 + 4 * l];
if("yes".equals(s1))
standalone = new Boolean(true);
else
if("no".equals(s1))
standalone = new Boolean(false);
else
error("illegal standalone value: " + s1);
l++;
}
if(l != attributeCount)
error("illegal xmldecl");
isWhitespace = true;
txtPos = 0;
return 998;
}
}
byte0 = 63;
byte1 = 8;
} else
if(j == 33)
{
if(peek(0) == 45)
{
byte1 = 9;
s = "--";
byte0 = 45;
} else
if(peek(0) == 91)
{
byte1 = 5;
s = "[CDATA[";
byte0 = 93;
flag = true;
} else
{
byte1 = 10;
s = "DOCTYPE";
byte0 = -1;
}
} else
{
error("illegal: <" + j);
return 9;
}
for(int i1 = 0; i1 < s.length(); i1++)
read(s.charAt(i1));
if(byte1 == 10)
{
parseDoctype(flag);
} else
{
do
{
int k = read();
if(k == -1)
{
error("Unexpected EOF");
return 9;
}
if(flag)
push(k);
if((byte0 == 63 || k == byte0) && peek(0) == byte0 && peek(1) == 62)
break;
i = k;
} while(true);
if(byte0 == 45 && i == 45)
error("illegal comment delimiter: --->");
read();
read();
if(flag && byte0 != 63)
txtPos--;
}
return byte1;
}
private final void parseDoctype(boolean flag)
throws IOException, XmlPullParserException
{
int i = 1;
boolean flag1 = false;
do
{
int j;
do
{
j = read();
switch(j)
{
case -1:
error("Unexpected EOF");
return;
case 39: // '\''
flag1 = !flag1;
break;
case 60: // '<'
if(!flag1)
i++;
break;
case 62: // '>'
if(!flag1 && --i == 0)
return;
break;
}
} while(!flag);
push(j);
} while(true);
}
private final void parseEndTag()
throws IOException, XmlPullParserException
{
read();
read();
name = readName();
skip();
read('>');
int i = depth - 1 << 2;
if(depth == 0)
{
error("element stack empty");
type = 9;
return;
}
if(!name.equals(elementStack[i + 3]))
{
error("expected: /" + elementStack[i + 3] + " read: " + name);
int j;
for(j = i; j >= 0 && !name.toLowerCase().equals(elementStack[j + 3].toLowerCase()); j -= 4)
stackMismatch++;
if(j < 0)
{
stackMismatch = 0;
type = 9;
return;
}
}
namespace = elementStack[i];
prefix = elementStack[i + 1];
name = elementStack[i + 2];
}
private final int peekType()
throws IOException
{
switch(peek(0))
{
case -1:
return 1;
case 38: // '&'
return 6;
case 60: // '<'
switch(peek(1))
{
case 47: // '/'
return 3;
case 33: // '!'
case 63: // '?'
return 999;
}
return 2;
}
return 4;
}
private final String get(int i)
{
return new String(txtBuf, i, txtPos - i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -