Android Open Source - arcgis-runtime-samples-android Mil2525c Message Parser From Project Back to project page arcgis-runtime-samples-android .
License The source code is released under:
Apache License
If you think the Android project arcgis-runtime-samples-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.arcgis.android.samples.milsym2525c;
/ * f r o m w w w . j a v a 2 s . c o m * /
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.util.Log;
import android.util.Xml;
public class Mil2525cMessageParser {
// no namespace
private static final String ns = null;
public List<GeoMessage> parse(InputStream in)
throws XmlPullParserException, IOException {
try {
// instantiate a parser, use an InputStream as input
XmlPullParser parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(in, null);
// start the parsing process
parser.nextTag();
// invoke readFeed() method to extract and process data
return readGeoMessages(parser);
} finally {
in.close();
}
}
/**
*
* @param parser
* @return List containing the entries extracted from feed
* @throws XmlPullParserException
* @throws IOException
*/
private List<GeoMessage> readGeoMessages(XmlPullParser parser)
throws XmlPullParserException, IOException {
List<GeoMessage> geoMessages = new ArrayList<GeoMessage>();
parser.require(XmlPullParser.START_TAG, ns, "geomessages" );
while (parser.next() != XmlPullParser.END_TAG) {
String pName = parser.getName();
// Start looking for the geomessage tag
if (pName != null && pName.equals("geomessage" )) {
geoMessages.add(readGeoMessage(parser));
} else {
Log.d("DEBUG" , "TAG NAME = " + pName);
continue ;
}
}
return geoMessages;
}
// Parses the contents of an geomessage.
private GeoMessage readGeoMessage(XmlPullParser parser)
throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, ns, "geomessage" );
String name = null;
String type = null;
String action = null;
String id = null;
String controlpoints = null;
String wkid = null;
String sic = null;
String uniquedesignation = null;
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue ;
}
String pName = parser.getName();
if (pName.equals("_name" )) {
name = readName(parser);
} else if (pName.equals("_type" )) {
type = readType(parser);
} else if (pName.equals("_action" )) {
action = readAction(parser);
} else if (pName.equals("_id" )) {
id = readID(parser);
} else if (pName.equals("_control_points" )) {
controlpoints = readControlPoints(parser);
} else if (pName.equals("_wkid" )) {
wkid = readWkid(parser);
} else if (pName.equals("sic" )) {
sic = readSic(parser);
} else if (pName.equals("uniquedesignation" )) {
uniquedesignation = readUniqueDesignation(parser);
}
}
return new GeoMessage(name, type, action, id, controlpoints, wkid, sic,
uniquedesignation);
}
private String readUniqueDesignation(XmlPullParser parser)
throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "uniquedesignation" );
String uniquedesignation = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "uniquedesignation" );
return uniquedesignation;
}
private String readSic(XmlPullParser parser) throws IOException,
XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "sic" );
String sic = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "sic" );
return sic;
}
private String readWkid(XmlPullParser parser) throws IOException,
XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "_wkid" );
String wkid = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "_wkid" );
return wkid;
}
private String readControlPoints(XmlPullParser parser) throws IOException,
XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "_control_points" );
String controlpoints = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "_control_points" );
return controlpoints;
}
private String readID(XmlPullParser parser) throws IOException,
XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "_id" );
String id = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "_id" );
return id;
}
private String readAction(XmlPullParser parser) throws IOException,
XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "_action" );
String action = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "_action" );
return action;
}
private String readType(XmlPullParser parser) throws IOException,
XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "_type" );
String type = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "_type" );
return type;
}
private String readName(XmlPullParser parser) throws IOException,
XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "_name" );
String name = readText(parser);
parser.require(XmlPullParser.END_TAG, ns, "_name" );
return name;
}
// extract text values.
private String readText(XmlPullParser parser) throws IOException,
XmlPullParserException {
String result = "" ;
if (parser.next() == XmlPullParser.TEXT) {
result = parser.getText();
parser.nextTag();
}
return result;
}
public class GeoMessage {
public final String name;
public final String type;
public final String action;
public final String id;
public final String controlpoints;
public final String wkid;
public final String sic;
public final String uniquedesignation;
private GeoMessage(String name, String type, String action, String id,
String controlpoints, String wkid, String sic,
String uniquedesignation) {
this.name = name;
this.type = type;
this.action = action;
this.id = id;
this.controlpoints = controlpoints;
this.wkid = wkid;
this.sic = sic;
this.uniquedesignation = uniquedesignation;
}
}
}
Java Source Code List com.arcgis.android.samples.ExportTileCacheTask.ExportTileCacheTaskSampleActivity.java com.arcgis.android.samples.cloudportal.featureservicetablequery.MainActivity.java com.arcgis.android.samples.cloudportal.querycloudfeatureservice.MainActivity.java com.arcgis.android.samples.dynamiclayer.DynamicLayerRendererActivity.java com.arcgis.android.samples.geometrysample.BufferFragment.java com.arcgis.android.samples.geometrysample.GeometrySampleActivity.java com.arcgis.android.samples.geometrysample.GeometryUtil.java com.arcgis.android.samples.geometrysample.SampleListFragment.java com.arcgis.android.samples.geometrysample.SpatialRelationshipsFragment.java com.arcgis.android.samples.geometrysample.UnionDifferenceFragment.java com.arcgis.android.samples.localdata.localrasterdata.EditTextUtils.java com.arcgis.android.samples.localdata.localrasterdata.FileBrowserFragment.java com.arcgis.android.samples.localdata.localrasterdata.HillshadeRendererParametersFragment.java com.arcgis.android.samples.localdata.localrasterdata.MainActivity.java com.arcgis.android.samples.localdata.localrasterdata.OnDialogDismissListener.java com.arcgis.android.samples.localdata.localrasterdata.RendererType.java com.arcgis.android.samples.localdata.localrasterdata.StretchParametersFragment.java com.arcgis.android.samples.maps.basemaps.MainActivity.java com.arcgis.android.samples.maps.fragmentmanagement.BasemapListFragment.java com.arcgis.android.samples.maps.fragmentmanagement.MainActivity.java com.arcgis.android.samples.maps.fragmentmanagement.MapFragment.java com.arcgis.android.samples.maps.helloworld.MainActivity.java com.arcgis.android.samples.maps.maplegend.LegendDialogFragment.java com.arcgis.android.samples.maps.maplegend.MainActivity.java com.arcgis.android.samples.maps.maprotation.Compass.java com.arcgis.android.samples.maps.maprotation.MainActivity.java com.arcgis.android.samples.maps.switchmaps.MainActivity.java com.arcgis.android.samples.maps.switchmaps.MapFragment.java com.arcgis.android.samples.milsym2525c.MainActivity.java com.arcgis.android.samples.milsym2525c.Mil2525cMessageParser.java com.arcgis.android.samples.oauth2sample.MapFragment.java com.arcgis.android.samples.oauth2sample.OAuth2Sample.java com.arcgis.android.samples.oauth2sample.UserContentActivity.java com.arcgis.android.samples.oauth2sample.UserContentArrayAdapter.java com.arcgis.android.samples.oauth2sample.UserContentFragment.java com.arcgis.android.samples.oauth2sample.UserWebmaps.java com.arcgis.android.samples.search.placesearch.MainActivity.java com.esri.android.sample.closestfacilities.MainActivity.java com.esri.android.samples.mbtiles.LocalMBTiles.java com.esri.android.samples.mbtiles.MBTilesLayer.java com.esri.android.samples.mgrsgrid.LocateMGRSActivity.java com.esri.arcgis.android.sample.runtimegeodb.CreateRuntimeGeodatabaseActivity.java com.esri.arcgis.android.sample.simplemap.SimpleMapActivity.java com.esri.arcgis.android.sample.simplemap.SimpleMapFragment.java com.esri.arcgis.android.sample.simplemap.SingleFragmentActivity.java com.esri.arcgis.android.samples.GeoJSONEarthquakeMap.GeoJSONEarthquakeMapActivity.java com.esri.arcgis.android.samples.PopupUICustomization.LayerQueryTask.java com.esri.arcgis.android.samples.PopupUICustomization.MyAttachmentsView.java com.esri.arcgis.android.samples.PopupUICustomization.MyEditAttributesAdapter.java com.esri.arcgis.android.samples.PopupUICustomization.MyMediaAdapter.java com.esri.arcgis.android.samples.PopupUICustomization.MyMediaView.java com.esri.arcgis.android.samples.PopupUICustomization.MyReadOnlyAttributesAdapter.java com.esri.arcgis.android.samples.PopupUICustomization.MyTitleView.java com.esri.arcgis.android.samples.PopupUICustomization.PopupFragment.java com.esri.arcgis.android.samples.PopupUICustomization.PopupUICustomizationActivity.java com.esri.arcgis.android.samples.addcsv2graphic.AddCSVActivity.java com.esri.arcgis.android.samples.attributeeditor.AttributeEditorActivity.java com.esri.arcgis.android.samples.attributeeditor.AttributeItem.java com.esri.arcgis.android.samples.attributeeditor.AttributeListAdapter.java com.esri.arcgis.android.samples.attributeeditor.FeatureLayerUtils.java com.esri.arcgis.android.samples.basiclicense.MainActivity.java com.esri.arcgis.android.samples.basiclicense.MessageDialogFragment.java com.esri.arcgis.android.samples.classbreaksrenderer.ClassBreaksRendererActivity.java com.esri.arcgis.android.samples.featuredusergroup.FeaturedGroupsActivity.java com.esri.arcgis.android.samples.featuredusergroup.GroupsFragment.java com.esri.arcgis.android.samples.featuredusergroup.ItemsFragment.java com.esri.arcgis.android.samples.featuredusergroup.MapActivity.java com.esri.arcgis.android.samples.geometryeditor.ConfirmDiscardDialogFragment.java com.esri.arcgis.android.samples.geometryeditor.EditFailedDialogFragment.java com.esri.arcgis.android.samples.geometryeditor.FeatureTypeData.java com.esri.arcgis.android.samples.geometryeditor.FeatureTypeDialogFragment.java com.esri.arcgis.android.samples.geometryeditor.GeometryEditorActivity.java com.esri.arcgis.android.samples.identifytask.Identify.java com.esri.arcgis.android.samples.measure.MainActivity.java com.esri.arcgis.android.samples.nearby.Nearby.java com.esri.arcgis.android.samples.offlineeditor.GDBUtil.java com.esri.arcgis.android.samples.offlineeditor.OfflineActions.java com.esri.arcgis.android.samples.offlineeditor.OfflineEditorActivity.java com.esri.arcgis.android.samples.offlineeditor.TemplatePicker.java com.esri.arcgis.android.samples.offlineroutingandgeocoding.RoutingAndGeocoding.java com.esri.arcgis.android.samples.popupinwebmapforediting.PopupInWebmapForEditing.java com.esri.arcgis.android.samples.popupinwebmapforviewing.PopupInWebmapForViewing.java com.esri.arcgis.android.samples.querytask.MainActivity.java com.esri.arcgis.android.samples.routing.MyAdapter.java com.esri.arcgis.android.samples.routing.RoutingDialogFragment.java com.esri.arcgis.android.samples.routing.RoutingListFragment.java com.esri.arcgis.android.samples.routing.RoutingSample.java com.esri.arcgis.android.samples.servicearea.EditFragment.java com.esri.arcgis.android.samples.servicearea.ServiceAreaSample.java com.esri.arcgis.android.samples.standardlicense.MainActivity.java com.esri.arcgis.android.samples.standardlicense.MessageDialogFragment.java com.esri.arcgis.android.samples.standardlicenseoffline.MainActivity.java com.esri.arcgis.android.samples.standardlicenseoffline.MessageDialogFragment.java com.esri.arcgis.android.samples.uniquevaluerenderer.UniqueValueRendererSampleActivity.java com.esri.arcgis.android.samples.viewshed.Viewshed.java com.esri.arcgis.android.samples.wmslayer.MainActivity.java com.esri.arcgis.samples.offlineanalysis.MainActivity.java