Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: chrome/test/android/javatests_staging/src/org/chromium/chrome/test/omaha/AttributeFinder.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/android/javatests_staging/src/org/chromium/chrome/test/omaha/AttributeFinder.java
diff --git a/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/omaha/AttributeFinder.java b/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/omaha/AttributeFinder.java
new file mode 100644
index 0000000000000000000000000000000000000000..4fdea1f82f13cebf5afde89d77c99c7a83e643a6
--- /dev/null
+++ b/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/omaha/AttributeFinder.java
@@ -0,0 +1,69 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.test.omaha;
+
+import android.util.Log;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+/**
+ * Pulls out a given tag attribute's value from the XML.
+ * Assumes that the same tag doesn't appear twice with the same attribute.
+ */
+public class AttributeFinder extends DefaultHandler {
+ private static final String TAG = "AttributeFinder";
+
+ private final String mDesiredTag;
+ private final String mDesiredAttribute;
+ private boolean mTagFound;
+ private String mValue;
+
+ public AttributeFinder(String xml, String tag, String attribute) {
+ mDesiredTag = tag;
+ mDesiredAttribute = attribute;
+
+ try {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ SAXParser saxParser = factory.newSAXParser();
+ saxParser.parse(new InputSource(new StringReader(xml)), this);
+ } catch (IOException e) {
+ Log.e(TAG, "Hit IOException", e);
+ } catch (ParserConfigurationException e) {
+ Log.e(TAG, "Hit ParserConfigurationException", e);
+ } catch (SAXParseException e) {
+ Log.e(TAG, "Hit SAXParseException", e);
+ } catch (SAXException e) {
+ Log.e(TAG, "Hit SAXException", e);
+ }
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String tag, Attributes attributes)
+ throws SAXException {
+ if (tag.equals(mDesiredTag)) {
+ mTagFound = true;
+ mValue = mDesiredAttribute != null ? attributes.getValue(mDesiredAttribute) : null;
+ }
+ }
+
+ public boolean isTagFound() {
+ return mTagFound;
+ }
+
+ public String getValue() {
+ return mValue;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698