📄 kxmlparser.java
字号:
}
if(s1 == null)
s1 = "UTF-8";
int j = srcCount;
setInput(((Reader) (new InputStreamReader(inputstream, s1))));
encoding = s;
srcCount = j;
}
catch(Exception exception1)
{
throw new XmlPullParserException("Invalid stream or encoding: " + exception1.toString(), this, exception1);
}
}
public boolean getFeature(String s)
{
if("http://xmlpull.org/v1/doc/features.html#process-namespaces".equals(s))
return processNsp;
if(isProp(s, false, "relaxed"))
return relaxed;
else
return false;
}
public String getInputEncoding()
{
return encoding;
}
public void defineEntityReplacementText(String s, String s1)
throws XmlPullParserException
{
if(entityMap == null)
{
throw new RuntimeException("entity replacement text must be defined after setInput!");
} else
{
entityMap.put(s, s1);
return;
}
}
public Object getProperty(String s)
{
if(isProp(s, true, "xmldecl-version"))
return version;
if(isProp(s, true, "xmldecl-standalone"))
return standalone;
if(isProp(s, true, "location"))
return location == null ? reader.toString() : location;
else
return null;
}
public int getNamespaceCount(int i)
{
if(i > depth)
throw new IndexOutOfBoundsException();
else
return nspCounts[i];
}
public String getNamespacePrefix(int i)
{
return nspStack[i << 1];
}
public String getNamespaceUri(int i)
{
return nspStack[(i << 1) + 1];
}
public String getNamespace(String s)
{
if("xml".equals(s))
return "http://www.w3.org/XML/1998/namespace";
if("xmlns".equals(s))
return "http://www.w3.org/2000/xmlns/";
for(int i = (getNamespaceCount(depth) << 1) - 2; i >= 0; i -= 2)
{
if(s == null)
{
if(nspStack[i] == null)
return nspStack[i + 1];
continue;
}
if(s.equals(nspStack[i]))
return nspStack[i + 1];
}
return null;
}
public int getDepth()
{
return depth;
}
public String getPositionDescription()
{
StringBuffer stringbuffer = new StringBuffer(type >= XmlPullParser.TYPES.length ? "unknown" : XmlPullParser.TYPES[type]);
stringbuffer.append(' ');
if(type == 2 || type == 3)
{
if(degenerated)
stringbuffer.append("(empty) ");
stringbuffer.append('<');
if(type == 3)
stringbuffer.append('/');
if(prefix != null)
stringbuffer.append("{" + namespace + "}" + prefix + ":");
stringbuffer.append(name);
int i = attributeCount << 2;
for(int j = 0; j < i; j += 4)
{
stringbuffer.append(' ');
if(attributes[j + 1] != null)
stringbuffer.append("{" + attributes[j] + "}" + attributes[j + 1] + ":");
stringbuffer.append(attributes[j + 2] + "='" + attributes[j + 3] + "'");
}
stringbuffer.append('>');
} else
if(type != 7)
if(type != 4)
stringbuffer.append(getText());
else
if(isWhitespace)
{
stringbuffer.append("(whitespace)");
} else
{
String s = getText();
if(s.length() > 16)
s = s.substring(0, 16) + "...";
stringbuffer.append(s);
}
stringbuffer.append("@" + line + ":" + column);
if(location != null)
{
stringbuffer.append(" in ");
stringbuffer.append(location);
} else
if(reader != null)
{
stringbuffer.append(" in ");
stringbuffer.append(reader.toString());
}
return stringbuffer.toString();
}
public int getLineNumber()
{
return line;
}
public int getColumnNumber()
{
return column;
}
public boolean isWhitespace()
throws XmlPullParserException
{
if(type != 4 && type != 7 && type != 5)
exception("Wrong event type");
return isWhitespace;
}
public String getText()
{
return type >= 4 && (type != 6 || !unresolved) ? get(0) : null;
}
public char[] getTextCharacters(int ai[])
{
if(type >= 4)
{
if(type == 6)
{
ai[0] = 0;
ai[1] = name.length();
return name.toCharArray();
} else
{
ai[0] = 0;
ai[1] = txtPos;
return txtBuf;
}
} else
{
ai[0] = -1;
ai[1] = -1;
return null;
}
}
public String getNamespace()
{
return namespace;
}
public String getName()
{
return name;
}
public String getPrefix()
{
return prefix;
}
public boolean isEmptyElementTag()
throws XmlPullParserException
{
if(type != 2)
exception("Wrong event type");
return degenerated;
}
public int getAttributeCount()
{
return attributeCount;
}
public String getAttributeType(int i)
{
return "CDATA";
}
public boolean isAttributeDefault(int i)
{
return false;
}
public String getAttributeNamespace(int i)
{
if(i >= attributeCount)
throw new IndexOutOfBoundsException();
else
return attributes[i << 2];
}
public String getAttributeName(int i)
{
if(i >= attributeCount)
throw new IndexOutOfBoundsException();
else
return attributes[(i << 2) + 2];
}
public String getAttributePrefix(int i)
{
if(i >= attributeCount)
throw new IndexOutOfBoundsException();
else
return attributes[(i << 2) + 1];
}
public String getAttributeValue(int i)
{
if(i >= attributeCount)
throw new IndexOutOfBoundsException();
else
return attributes[(i << 2) + 3];
}
public String getAttributeValue(String s, String s1)
{
for(int i = (attributeCount << 2) - 4; i >= 0; i -= 4)
if(attributes[i + 2].equals(s1) && (s == null || attributes[i].equals(s)))
return attributes[i + 3];
return null;
}
public int getEventType()
throws XmlPullParserException
{
return type;
}
public int next()
throws XmlPullParserException, IOException
{
txtPos = 0;
isWhitespace = true;
int i = 9999;
token = false;
do
{
nextImpl();
if(type < i)
i = type;
} while(i > 6 || i >= 4 && peekType() >= 4);
type = i;
if(type > 4)
type = 4;
return type;
}
public int nextToken()
throws XmlPullParserException, IOException
{
isWhitespace = true;
txtPos = 0;
token = true;
nextImpl();
return type;
}
public int nextTag()
throws XmlPullParserException, IOException
{
next();
if(type == 4 && isWhitespace)
next();
if(type != 3 && type != 2)
exception("unexpected type");
return type;
}
public void require(int i, String s, String s1)
throws XmlPullParserException, IOException
{
if(i != type || s != null && !s.equals(getNamespace()) || s1 != null && !s1.equals(getName()))
exception("expected: " + XmlPullParser.TYPES[i] + " {" + s + "}" + s1);
}
public String nextText()
throws XmlPullParserException, IOException
{
if(type != 2)
exception("precondition: START_TAG");
next();
String s;
if(type == 4)
{
s = getText();
next();
} else
{
s = "";
}
if(type != 3)
exception("END_TAG expected");
return s;
}
public void setFeature(String s, boolean flag)
throws XmlPullParserException
{
if("http://xmlpull.org/v1/doc/features.html#process-namespaces".equals(s))
processNsp = flag;
else
if(isProp(s, false, "relaxed"))
relaxed = flag;
else
exception("unsupported feature: " + s);
}
public void setProperty(String s, Object obj)
throws XmlPullParserException
{
if(isProp(s, true, "location"))
location = obj;
else
throw new XmlPullParserException("unsupported property: " + s);
}
public void skipSubTree()
throws XmlPullParserException, IOException
{
require(2, null, null);
int i = 1;
do
{
if(i <= 0)
break;
int j = next();
if(j == 3)
i--;
else
if(j == 2)
i++;
} while(true);
}
private Object location;
private static final String UNEXPECTED_EOF = "Unexpected EOF";
private static final String ILLEGAL_TYPE = "Wrong event type";
private static final int LEGACY = 999;
private static final int XML_DECL = 998;
private String version;
private Boolean standalone;
private boolean processNsp;
private boolean relaxed;
private Hashtable entityMap;
private int depth;
private String elementStack[];
private String nspStack[];
private int nspCounts[];
private Reader reader;
private String encoding;
private char srcBuf[];
private int srcPos;
private int srcCount;
private int line;
private int column;
private char txtBuf[];
private int txtPos;
private int type;
private boolean isWhitespace;
private String namespace;
private String prefix;
private String name;
private boolean degenerated;
private int attributeCount;
private String attributes[];
private int stackMismatch;
private String error;
private int peek[];
private int peekCount;
private boolean wasCR;
private boolean unresolved;
private boolean token;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -