use of org.kxml2.io.KXmlParser in project android_frameworks_base by ResurrectionRemix.
the class LayoutParserWrapperTest method getParserFromString.
private static LayoutParserWrapper getParserFromString(String layoutContent) throws XmlPullParserException {
XmlPullParser parser = new KXmlParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new StringReader(layoutContent));
return new LayoutParserWrapper(parser);
}
use of org.kxml2.io.KXmlParser in project UltimateAndroid by cymcsg.
the class SvgToPath method parse.
private static PathInfo parse(InputStream in, boolean ignoreDefs, float dpi) {
try {
XmlPullParser xr = new KXmlParser();
SvgToPath svgHandler = new SvgToPath(xr);
svgHandler.setDpi(dpi);
if (ignoreDefs) {
xr.setInput(new InputStreamReader(in));
svgHandler.processSvg();
} else {
CopyInputStream cin = new CopyInputStream(in);
XmlPullParser ids = new KXmlParser();
ids.setInput(new InputStreamReader(cin.getCopy()));
IdHandler idHandler = new IdHandler(ids);
idHandler.processIds();
svgHandler.idXml = idHandler.idXml;
xr.setInput(new InputStreamReader(cin.getCopy()));
svgHandler.processSvg();
}
return svgHandler.pathInfo;
} catch (Exception e) {
Log.w(TAG, "Parse error: " + e);
throw new RuntimeException(e);
}
}
use of org.kxml2.io.KXmlParser in project android by JetBrains.
the class LayoutPsiPullParserTest method compareParsers.
private void compareParsers(PsiFile file, NextEventType nextEventType) throws Exception {
assertTrue(file instanceof XmlFile);
XmlFile xmlFile = (XmlFile) file;
KXmlParser referenceParser = createReferenceParser(file);
LayoutPsiPullParser parser = LayoutPsiPullParser.create(xmlFile, new RenderLogger("test", myModule));
assertEquals("Expected " + name(referenceParser.getEventType()) + " but was " + name(parser.getEventType()) + " (at line:column " + describePosition(referenceParser) + ")", referenceParser.getEventType(), parser.getEventType());
while (true) {
int expected, next;
switch(nextEventType) {
case NEXT:
expected = referenceParser.next();
next = parser.next();
break;
case NEXT_TOKEN:
expected = referenceParser.nextToken();
next = parser.nextToken();
break;
case NEXT_TAG:
{
try {
expected = referenceParser.nextTag();
} catch (Exception e) {
expected = referenceParser.getEventType();
}
try {
next = parser.nextTag();
} catch (Exception e) {
next = parser.getEventType();
}
break;
}
default:
throw new AssertionError("Unexpected type");
}
PsiElement element = null;
if (expected == START_TAG) {
assertNotNull(parser.getViewCookie());
assertTrue(parser.getViewCookie() instanceof TagSnapshot);
element = ((TagSnapshot) parser.getViewCookie()).tag;
}
if (expected == START_TAG) {
assertEquals(referenceParser.getName(), parser.getName());
if (element != xmlFile.getRootTag()) {
// KXmlParser seems to not include xmlns: attributes on the root tag!{
SortedSet<String> referenceAttributes = new TreeSet<>();
SortedSet<String> attributes = new TreeSet<>();
for (int i = 0; i < referenceParser.getAttributeCount(); i++) {
String s = referenceParser.getAttributePrefix(i) + ':' + referenceParser.getAttributeName(i) + '=' + referenceParser.getAttributeValue(i);
referenceAttributes.add(s);
}
for (int i = 0; i < parser.getAttributeCount(); i++) {
String s = parser.getAttributePrefix(i) + ':' + parser.getAttributeName(i) + '=' + parser.getAttributeValue(i);
attributes.add(s);
if (parser.getAttributeNamespace(i) != null) {
//noinspection ConstantConditions
assertEquals(normalizeValue(parser.getAttributeValue(i)), normalizeValue(parser.getAttributeValue(parser.getAttributeNamespace(i), parser.getAttributeName(i))));
}
}
assertEquals(referenceAttributes, attributes);
}
if (element instanceof XmlTag) {
XmlTag tag = (XmlTag) element;
for (XmlAttribute attribute : tag.getAttributes()) {
String namespace = attribute.getNamespace();
String name = attribute.getLocalName();
if (namespace.isEmpty()) {
String prefix = attribute.getNamespacePrefix();
if (!prefix.isEmpty()) {
name = prefix + ":" + prefix;
}
}
//noinspection ConstantConditions
assertEquals(namespace + ':' + name + " in element " + parser.getName(), normalizeValue(referenceParser.getAttributeValue(namespace, name)), normalizeValue(parser.getAttributeValue(namespace, name)));
}
}
} else if (expected == XmlPullParser.TEXT || expected == XmlPullParser.COMMENT) {
assertEquals(StringUtil.notNullize(referenceParser.getText()).trim(), StringUtil.notNullize(parser.getText()).trim());
}
if (expected != next) {
assertEquals("Expected " + name(expected) + " but was " + name(next) + "(At " + describePosition(referenceParser) + ")", expected, next);
}
if (expected == XmlPullParser.END_DOCUMENT) {
break;
}
}
}
use of org.kxml2.io.KXmlParser in project android_frameworks_base by crdroidandroid.
the class Xml method newPullParser.
/**
* Returns a new pull parser with namespace support.
*/
public static XmlPullParser newPullParser() {
try {
KXmlParser parser = new KXmlParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
return parser;
} catch (XmlPullParserException e) {
throw new AssertionError();
}
}
use of org.kxml2.io.KXmlParser in project android_frameworks_base by crdroidandroid.
the class ExpatPerformanceTest method runJavaPullParser.
private void runJavaPullParser() throws XmlPullParserException, IOException {
XmlPullParser pullParser;
long start = System.currentTimeMillis();
pullParser = new KXmlParser();
pullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
pullParser.setInput(newInputStream(), "UTF-8");
withPullParser(pullParser);
long elapsed = System.currentTimeMillis() - start;
Log.i(TAG, "java pull parser: " + elapsed + "ms");
}
Aggregations