org.xmlpull.v1.XmlPullParserException Java Examples

The following examples show how to use org.xmlpull.v1.XmlPullParserException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KmlParser.java    From trekarta with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private static FileDataSource readKml(XmlPullParser parser) throws XmlPullParserException, IOException {
    FileDataSource dataSource = null;
    parser.require(XmlPullParser.START_TAG, NS, KmlFile.TAG_KML);
    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        // Both folder and document can be root containers
        if (name.equals(KmlFile.TAG_DOCUMENT) || name.equals(KmlFile.TAG_FOLDER)) {
            dataSource = readDocument(parser, name);
        } else {
            skip(parser);
        }
    }
    if (dataSource == null)
        throw new XmlPullParserException("No valid data", parser, null);
    return dataSource;
}
 
Example #2
Source File: KeyboardBuilder.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
private void parseKey(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (skip) {
        XmlParseUtils.checkEndTag(TAG_KEY, parser);
        if (DEBUG) startEndTag("<%s /> skipped", TAG_KEY);
        return;
    }
    final TypedArray keyAttr = mResources.obtainAttributes(
            Xml.asAttributeSet(parser), R.styleable.Keyboard_Key);
    final KeyStyle keyStyle = mParams.mKeyStyles.getKeyStyle(keyAttr, parser);
    final String keySpec = keyStyle.getString(keyAttr, R.styleable.Keyboard_Key_keySpec);
    if (TextUtils.isEmpty(keySpec)) {
        throw new ParseException("Empty keySpec", parser);
    }
    final Key key = new Key(keySpec, keyAttr, keyStyle, mParams, row);
    keyAttr.recycle();
    if (DEBUG) {
        startEndTag("<%s%s %s moreKeys=%s />", TAG_KEY, (key.isEnabled() ? "" : " disabled"),
                key, Arrays.toString(key.getMoreKeys()));
    }
    XmlParseUtils.checkEndTag(TAG_KEY, parser);
    endKey(key);
}
 
Example #3
Source File: XmlUtils.java    From a with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Read a flattened object from an XmlPullParser.  The XML data could
 * previously have been written with writeMapXml(), writeListXml(), or
 * writeValueXml().  The XmlPullParser must be positioned <em>at</em> the
 * tag that defines the value.
 *
 * @param parser The XmlPullParser from which to read the object.
 * @param name   An array of one string, used to return the name attribute
 *               of the value's tag.
 * @return Object The newly generated value object.
 * @see #readMapXml
 * @see #readListXml
 * @see #writeValueXml
 */
public static Object readValueXml(XmlPullParser parser, String[] name)
        throws XmlPullParserException, java.io.IOException {
    int eventType = parser.getEventType();
    do {
        if (eventType == parser.START_TAG) {
            return readThisValueXml(parser, name, null);
        } else if (eventType == parser.END_TAG) {
            throw new XmlPullParserException(
                    "Unexpected end tag at: " + parser.getName());
        } else if (eventType == parser.TEXT) {
            throw new XmlPullParserException(
                    "Unexpected text: " + parser.getText());
        }
        eventType = parser.next();
    } while (eventType != parser.END_DOCUMENT);

    throw new XmlPullParserException(
            "Unexpected end of document");
}
 
Example #4
Source File: PListParser.java    From Connect-SDK-Android-Core with Apache License 2.0 6 votes vote down vote up
private void skip(XmlPullParser parser) throws XmlPullParserException, IOException {
    if (parser.getEventType() != XmlPullParser.START_TAG) {
        throw new IllegalStateException();
    }
    int depth = 1;
    while (depth != 0) {
        switch (parser.next()) {
        case XmlPullParser.END_TAG:
            depth--;
            break;
        case XmlPullParser.START_TAG:
            depth++;
            break;
        }
    }
}
 
Example #5
Source File: BluetoothXmlParser.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
private Characteristic readCharacteristic(XmlPullParser parser) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, ns, Consts.TAG_CHARACTERISTIC);

    Characteristic characteristic = new Characteristic();

    String characteristicName = readCharacteristicName(parser);
    characteristic.setName(characteristicName);

    while (parser.next() != XmlPullParser.END_TAG) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }

        String name = parser.getName();
        if (name.equals(Consts.TAG_INFORMATIVE_TEXT)) {
            String summary = readSummary(parser);
            characteristic.setSummary(summary);
        } else if (name.equals(Consts.TAG_VALUE)) {
            ArrayList<Field> fields = readFieldValue(parser, characteristic);
        } else {
            skip(parser);
        }
    }

    return characteristic;
}
 
Example #6
Source File: AXmlResourceParser.java    From apkReSign with Apache License 2.0 6 votes vote down vote up
public String nextText() throws XmlPullParserException,IOException {
	if(getEventType()!=START_TAG) {
		throw new XmlPullParserException("Parser must be on START_TAG to read next text.",this,null);
	}
	int eventType=next();
	if (eventType==TEXT) {
		String result=getText();
		eventType=next();
		if (eventType!=END_TAG) {
			throw new XmlPullParserException("Event TEXT must be immediately followed by END_TAG.",this,null);
		}
		return result;
	} else if (eventType==END_TAG) {
		return "";
	} else {
		throw new XmlPullParserException("Parser must be on START_TAG or TEXT to read text.",this,null);
	}
}
 
Example #7
Source File: KeyboardLayoutSet.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
static int readScriptId(final Resources resources, final InputMethodSubtype subtype) {
    final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX
            + SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
    final int xmlId = getXmlId(resources, layoutSetName);
    final XmlResourceParser parser = resources.getXml(xmlId);
    try {
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            // Bovinate through the XML stupidly searching for TAG_FEATURE, and read
            // the script Id from it.
            parser.next();
            final String tag = parser.getName();
            if (TAG_FEATURE.equals(tag)) {
                return readScriptIdFromTagFeature(resources, parser);
            }
        }
    } catch (final IOException | XmlPullParserException e) {
        throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e);
    } finally {
        parser.close();
    }
    // If the tag is not found, then the default script is Latin.
    return ScriptUtils.SCRIPT_LATIN;
}
 
Example #8
Source File: GPXParser.java    From android-gpx-parser with Apache License 2.0 6 votes vote down vote up
private Link readLink(XmlPullParser parser) throws IOException, XmlPullParserException {
    parser.require(XmlPullParser.START_TAG, namespace, TAG_LINK);

    Link.Builder linkBuilder = new Link.Builder();
    linkBuilder.setLinkHref(parser.getAttributeValue(namespace, TAG_HREF));

    while (loopMustContinue(parser.next())) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        switch (name) {
            case TAG_TEXT:
                linkBuilder.setLinkText(readString(parser, TAG_TEXT));
                break;
            case TAG_TYPE:
                linkBuilder.setLinkType(readString(parser, TAG_TYPE));
                break;
            default:
                skip(parser);
                break;
        }
    }
    parser.require(XmlPullParser.END_TAG, namespace, TAG_LINK);
    return linkBuilder.build();
}
 
Example #9
Source File: XmlUtils.java    From cwac-netsecurity with Apache License 2.0 6 votes vote down vote up
/**
 * Read an ArrayList object from an XmlPullParser.  The XML data could
 * previously have been generated by writeListXml().  The XmlPullParser
 * must be positioned <em>after</em> the tag that begins the list.
 *
 * @param parser The XmlPullParser from which to read the list data.
 * @param endTag Name of the tag that will end the list, usually "list".
 * @param name An array of one string, used to return the name attribute
 *             of the list's tag.
 *
 * @return HashMap The newly generated list.
 *
 * @see # readListXml
 */
private static final ArrayList readThisListXml(XmlPullParser parser, String endTag,
        String[] name, ReadMapCallback callback, boolean arrayMap)
        throws XmlPullParserException, IOException {
    ArrayList list = new ArrayList();

    int eventType = parser.getEventType();
    do {
        if (eventType == parser.START_TAG) {
            Object val = readThisValueXml(parser, name, callback, arrayMap);
            list.add(val);
            //System.out.println("Adding to list: " + val);
        } else if (eventType == parser.END_TAG) {
            if (parser.getName().equals(endTag)) {
                return list;
            }
            throw new XmlPullParserException(
                "Expected " + endTag + " end tag at: " + parser.getName());
        }
        eventType = parser.next();
    } while (eventType != parser.END_DOCUMENT);

    throw new XmlPullParserException(
        "Document ended before " + endTag + " end tag");
}
 
Example #10
Source File: XmlConfigSource.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private CertificatesEntryRef parseCertificatesEntry(XmlResourceParser parser,
        boolean defaultOverridePins)
        throws IOException, XmlPullParserException, ParserException {
    boolean overridePins =
            parser.getAttributeBooleanValue(null, "overridePins", defaultOverridePins);
    int sourceId = parser.getAttributeResourceValue(null, "src", -1);
    String sourceString = parser.getAttributeValue(null, "src");
    CertificateSource source = null;
    if (sourceString == null) {
        throw new ParserException(parser, "certificates element missing src attribute");
    }
    if (sourceId != -1) {
        // TODO: Cache ResourceCertificateSources by sourceId
        source = new ResourceCertificateSource(sourceId, mContext);
    } else if ("system".equals(sourceString)) {
        source = SystemCertificateSource.getInstance();
    } else if ("user".equals(sourceString)) {
        source = UserCertificateSource.getInstance();
    } else {
        throw new ParserException(parser, "Unknown certificates src. "
                + "Should be one of system|user|@resourceVal");
    }
    XmlUtils.skipCurrentTag(parser);
    return new CertificatesEntryRef(source, overridePins);
}
 
Example #11
Source File: PersistentDataStore.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void loadFromXml(XmlPullParser parser)
        throws IOException, XmlPullParserException {
    XmlUtils.beginDocument(parser, TAG_DISPLAY_MANAGER_STATE);
    final int outerDepth = parser.getDepth();
    while (XmlUtils.nextElementWithin(parser, outerDepth)) {
        if (parser.getName().equals(TAG_REMEMBERED_WIFI_DISPLAYS)) {
            loadRememberedWifiDisplaysFromXml(parser);
        }
        if (parser.getName().equals(TAG_DISPLAY_STATES)) {
            loadDisplaysFromXml(parser);
        }
        if (parser.getName().equals(TAG_STABLE_DEVICE_VALUES)) {
            mStableDeviceValues.loadFromXml(parser);
        }
        if (parser.getName().equals(TAG_BRIGHTNESS_CONFIGURATIONS)) {
            mBrightnessConfigurations.loadFromXml(parser);
        }
    }
}
 
Example #12
Source File: AutoInstallsLayout.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses the layout and returns the number of elements added on the homescreen.
 */
protected int parseLayout(int layoutId, ArrayList<Long> screenIds)
        throws XmlPullParserException, IOException {
    XmlResourceParser parser = mSourceRes.getXml(layoutId);
    beginDocument(parser, mRootTag);
    final int depth = parser.getDepth();
    int type;
    HashMap<String, TagParser> tagParserMap = getLayoutElementsMap();
    int count = 0;

    while (((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        count += parseAndAddNode(parser, tagParserMap, screenIds);
    }
    return count;
}
 
Example #13
Source File: KeyboardBuilder.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
private void parseMerge(final XmlPullParser parser, final KeyboardRow row, final boolean skip)
        throws XmlPullParserException, IOException {
    if (DEBUG) startTag("<%s>", TAG_MERGE);
    while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
        final int event = parser.next();
        if (event == XmlPullParser.START_TAG) {
            final String tag = parser.getName();
            if (TAG_MERGE.equals(tag)) {
                if (row == null) {
                    parseKeyboardContent(parser, skip);
                } else {
                    parseRowContent(parser, row, skip);
                }
                return;
            }
            throw new XmlParseUtils.ParseException(
                    "Included keyboard layout must have <merge> root element", parser);
        }
    }
}
 
Example #14
Source File: OnvifUtils.java    From ONVIF-Java with Apache License 2.0 6 votes vote down vote up
/**
 * Util method for parsing.
 * Retrieve the XAddrs from the XmlPullParser given.
 */
public static String retrieveXAddrs(XmlPullParser xpp) throws IOException, XmlPullParserException {
    String result = "";
    int eventType = xpp.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {

        if (eventType == XmlPullParser.START_TAG && xpp.getName().equals("XAddrs")) {
            xpp.next();
            result = xpp.getText();
            break;
        }
        eventType = xpp.next();
    }

    return result;
}
 
Example #15
Source File: XmlConfigSource.java    From cwac-netsecurity with Apache License 2.0 6 votes vote down vote up
private Domain parseDomain(XmlResourceParser parser, Set<String> seenDomains)
        throws IOException, XmlPullParserException, ParserException {
    boolean includeSubdomains =
            parser.getAttributeBooleanValue(null, "includeSubdomains", false);
    if (parser.next() != XmlPullParser.TEXT) {
        throw new ParserException(parser, "Domain name missing");
    }
    String domain = parser.getText().trim().toLowerCase(Locale.US);
    if (parser.next() != XmlPullParser.END_TAG) {
        throw new ParserException(parser, "domain contains additional elements");
    }
    // Domains are matched using a most specific match, so don't allow duplicates.
    // includeSubdomains isn't relevant here, both android.com + subdomains and android.com
    // match for android.com equally. Do not allow any duplicates period.
    if (!seenDomains.add(domain)) {
        throw new ParserException(parser, domain + " has already been specified");
    }
    return new Domain(domain, includeSubdomains);
}
 
Example #16
Source File: KeyboardBuilder.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
private void parseKeyStyle(final XmlPullParser parser, final boolean skip)
        throws XmlPullParserException, IOException {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyStyleAttr = mResources.obtainAttributes(
            attr, R.styleable.Keyboard_KeyStyle);
    final TypedArray keyAttrs = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
    try {
        if (!keyStyleAttr.hasValue(R.styleable.Keyboard_KeyStyle_styleName)) {
            throw new XmlParseUtils.ParseException("<" + TAG_KEY_STYLE
                    + "/> needs styleName attribute", parser);
        }
        if (DEBUG) {
            startEndTag("<%s styleName=%s />%s", TAG_KEY_STYLE,
                    keyStyleAttr.getString(R.styleable.Keyboard_KeyStyle_styleName),
                    skip ? " skipped" : "");
        }
        if (!skip) {
            mParams.mKeyStyles.parseKeyStyleAttributes(keyStyleAttr, keyAttrs, parser);
        }
    } finally {
        keyStyleAttr.recycle();
        keyAttrs.recycle();
    }
    XmlParseUtils.checkEndTag(TAG_KEY_STYLE, parser);
}
 
Example #17
Source File: GPXParser.java    From android-gpx-parser with Apache License 2.0 6 votes vote down vote up
private Copyright readCopyright(XmlPullParser parser) throws XmlPullParserException, IOException {
    parser.require(XmlPullParser.START_TAG, namespace, TAG_COPYRIGHT);

    Copyright.Builder copyrightBuilder = new Copyright.Builder();
    copyrightBuilder.setAuthor(parser.getAttributeValue(namespace, TAG_AUTHOR));

    while (loopMustContinue(parser.next())) {
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            continue;
        }
        String name = parser.getName();
        switch (name) {
            case TAG_YEAR:
                copyrightBuilder.setYear(readYear(parser));
                break;
            case TAG_LICENSE:
                copyrightBuilder.setLicense(readString(parser, TAG_LICENSE));
                break;
            default:
                skip(parser);
                break;
        }
    }
    parser.require(XmlPullParser.END_TAG, namespace, TAG_COPYRIGHT);
    return copyrightBuilder.build();
}
 
Example #18
Source File: XFormUpdateInfoInstaller.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean initialize(AndroidCommCarePlatform platform, boolean isUpgrade) throws
        IOException, InvalidReferenceException, InvalidStructureException,
        XmlPullParserException, UnfullfilledRequirementsException {
    platform.setUpdateInfoFormXmlns(namespace);
    return super.initialize(platform, isUpgrade);
}
 
Example #19
Source File: XmlParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected DomainResource parseDomainResourceContained(XmlPullParser xpp)  throws IOException, FHIRFormatError, XmlPullParserException {
	next(xpp);
	int eventType = nextNoWhitespace(xpp);
	if (eventType == XmlPullParser.START_TAG) { 
		DomainResource dr = (DomainResource) parseResource(xpp);
		nextNoWhitespace(xpp);
		next(xpp);
		return dr;
	} else {
		unknownContent(xpp);
		return null;
	}
}
 
Example #20
Source File: KmlContainerParser.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains a Container object (created if a Document or Folder start tag is read by the
 * XmlPullParser) and assigns specific elements read from the XmlPullParser to the container.
 */

/* package */
static KmlContainer createContainer(XmlPullParser parser)
        throws XmlPullParserException, IOException {
    return assignPropertiesToContainer(parser);
}
 
Example #21
Source File: Dsmlv2Engine.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Processes the file given and return the result of the operations
 * 
 * @param dsmlInput the DSMLv2 formatted request input
 * @return the XML response in DSMLv2 Format
 * @throws XmlPullParserException if an error occurs in the parser
 */
public String processDSML( String dsmlInput ) throws XmlPullParserException
{
    parser = new Dsmlv2Parser( grammar );
    parser.setInput( dsmlInput );

    return processDSML();
}
 
Example #22
Source File: XmlUtils.java    From PreferenceFragment with Apache License 2.0 5 votes vote down vote up
public static void skipCurrentTag(XmlPullParser parser)
        throws XmlPullParserException, IOException {
    int outerDepth = parser.getDepth();
    int type;
    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
           && (type != XmlPullParser.END_TAG
                   || parser.getDepth() > outerDepth)) {
    }
}
 
Example #23
Source File: SocketReadingMode.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * After SASL authentication was successful we should open a new stream and offer
 * new stream features such as resource binding and session establishment. Notice that
 * resource binding and session establishment should only be offered to clients (i.e. not
 * to servers or external components)
 */
protected void saslSuccessful() throws XmlPullParserException, IOException {
    StringBuilder sb = new StringBuilder(420);
    sb.append(geStreamHeader());
    sb.append("<stream:features>");

    // Include specific features such as resource binding and session establishment
    // for client sessions
    String specificFeatures = socketReader.session.getAvailableStreamFeatures();
    if (specificFeatures != null) {
        sb.append(specificFeatures);
    }
    sb.append("</stream:features>");
    socketReader.connection.deliverRawText(sb.toString());
}
 
Example #24
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
protected SingleSegmentBase parseSegmentBase(XmlPullParser xpp, SingleSegmentBase parent)
    throws XmlPullParserException, IOException {

  long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
  long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
      parent != null ? parent.presentationTimeOffset : 0);

  long indexStart = parent != null ? parent.indexStart : 0;
  long indexLength = parent != null ? parent.indexLength : 0;
  String indexRangeText = xpp.getAttributeValue(null, "indexRange");
  if (indexRangeText != null) {
    String[] indexRange = indexRangeText.split("-");
    indexStart = Long.parseLong(indexRange[0]);
    indexLength = Long.parseLong(indexRange[1]) - indexStart + 1;
  }

  RangedUri initialization = parent != null ? parent.initialization : null;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
      initialization = parseInitialization(xpp);
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentBase"));

  return buildSingleSegmentBase(initialization, timescale, presentationTimeOffset, indexStart,
      indexLength);
}
 
Example #25
Source File: FontListParser.java    From font-compat with Apache License 2.0 5 votes vote down vote up
private static Alias readAlias(XmlPullParser parser)
        throws XmlPullParserException, IOException {
    Alias alias = new Alias();
    alias.name = parser.getAttributeValue(null, "name");
    alias.toName = parser.getAttributeValue(null, "to");
    String weightStr = parser.getAttributeValue(null, "weight");
    if (weightStr == null) {
        alias.weight = 400;
    } else {
        alias.weight = Integer.parseInt(weightStr);
    }
    skip(parser);  // alias tag is empty, ignore any contents and consume end tag
    return alias;
}
 
Example #26
Source File: MediaPresentationDescriptionParser.java    From Exoplayer_VLC with Apache License 2.0 5 votes vote down vote up
protected MediaPresentationDescription parseMediaPresentationDescription(XmlPullParser xpp,
    String contentId, Uri baseUrl) throws XmlPullParserException, IOException, ParseException {
  long availabilityStartTime = parseDateTime(xpp, "availabilityStartTime", -1);
  long durationMs = parseDuration(xpp, "mediaPresentationDuration", -1);
  long minBufferTimeMs = parseDuration(xpp, "minBufferTime", -1);
  String typeString = xpp.getAttributeValue(null, "type");
  boolean dynamic = (typeString != null) ? typeString.equals("dynamic") : false;
  long minUpdateTimeMs = (dynamic) ? parseDuration(xpp, "minimumUpdatePeriod", -1) : -1;
  long timeShiftBufferDepthMs = (dynamic) ? parseDuration(xpp, "timeShiftBufferDepth", -1)
      : -1;
  UtcTimingElement utcTiming = null;

  List<Period> periods = new ArrayList<Period>();
  do {
    xpp.next();
    if (isStartTag(xpp, "BaseURL")) {
      baseUrl = parseBaseUrl(xpp, baseUrl);
    } else if (isStartTag(xpp, "UTCTiming")) {
      utcTiming = parseUtcTiming(xpp);
    } else if (isStartTag(xpp, "Period")) {
      periods.add(parsePeriod(xpp, contentId, baseUrl, durationMs));
    }
  } while (!isEndTag(xpp, "MPD"));

  return buildMediaPresentationDescription(availabilityStartTime, durationMs, minBufferTimeMs,
      dynamic, minUpdateTimeMs, timeShiftBufferDepthMs, utcTiming, periods);
}
 
Example #27
Source File: KmlFeatureParser.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new KmlPoint object
 *
 * @return KmlPoint object
 */
private static KmlPoint createPoint(XmlPullParser parser)
        throws XmlPullParserException, IOException {
    LatLngAlt latLngAlt = null;
    int eventType = parser.getEventType();
    while (!(eventType == END_TAG && parser.getName().equals("Point"))) {
        if (eventType == START_TAG && parser.getName().equals("coordinates")) {
            latLngAlt = convertToLatLngAlt(parser.nextText());
        }
        eventType = parser.next();
    }
    return new KmlPoint(latLngAlt.latLng, latLngAlt.altitude);
}
 
Example #28
Source File: XmlParserBase.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
protected void skipElementWithContent(XmlPullParser xpp) throws XmlPullParserException, IOException  {
	// when this is called, we are pointing an element that may have content
	while (xpp.getEventType() != XmlPullParser.END_TAG) {
		next(xpp);
		if (xpp.getEventType() == XmlPullParser.START_TAG) 
			skipElementWithContent(xpp);
	}
	next(xpp);
}
 
Example #29
Source File: PluginManifestUtil.java    From AndroidPlugin with MIT License 5 votes vote down vote up
private static void parseApplicationInfo(PlugInfo info, String namespace,
        XmlPullParser parser) throws XmlPullParserException, IOException {
    String applicationName = parser.getAttributeValue(namespace, "name");
    String packageName = info.getPackageInfo().packageName;
    ApplicationInfo applicationInfo = info.getPackageInfo().applicationInfo;
    applicationInfo.name = getName(applicationName, packageName);
}
 
Example #30
Source File: XmlConfigSource.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private Pin parsePin(XmlResourceParser parser)
        throws IOException, XmlPullParserException, ParserException {
    String digestAlgorithm = parser.getAttributeValue(null, "digest");
    if (!Pin.isSupportedDigestAlgorithm(digestAlgorithm)) {
        throw new ParserException(parser, "Unsupported pin digest algorithm: "
                + digestAlgorithm);
    }
    if (parser.next() != XmlPullParser.TEXT) {
        throw new ParserException(parser, "Missing pin digest");
    }
    String digest = parser.getText().trim();
    byte[] decodedDigest = null;
    try {
        decodedDigest = Base64.decode(digest, 0);
    } catch (IllegalArgumentException e) {
        throw new ParserException(parser, "Invalid pin digest", e);
    }
    int expectedLength = Pin.getDigestLength(digestAlgorithm);
    if (decodedDigest.length != expectedLength) {
        throw new ParserException(parser, "digest length " + decodedDigest.length
                + " does not match expected length for " + digestAlgorithm + " of "
                + expectedLength);
    }
    if (parser.next() != XmlPullParser.END_TAG) {
        throw new ParserException(parser, "pin contains additional elements");
    }
    return new Pin(digestAlgorithm, decodedDigest);
}