1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.bluetooth.client.map; 18import android.util.Log; 19 20import org.xmlpull.v1.XmlPullParser; 21import org.xmlpull.v1.XmlPullParserException; 22import org.xmlpull.v1.XmlPullParserFactory; 23 24import java.io.IOException; 25import java.io.InputStream; 26import java.util.ArrayList; 27 28class BluetoothMapFolderListing { 29 30 private static final String TAG = "BluetoothMasFolderListing"; 31 32 private final ArrayList<String> mFolders; 33 34 public BluetoothMapFolderListing(InputStream in) { 35 mFolders = new ArrayList<String>(); 36 37 parse(in); 38 } 39 40 public void parse(InputStream in) { 41 42 try { 43 XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser(); 44 xpp.setInput(in, "utf-8"); 45 46 int event = xpp.getEventType(); 47 while (event != XmlPullParser.END_DOCUMENT) { 48 switch (event) { 49 case XmlPullParser.START_TAG: 50 if (xpp.getName().equals("folder")) { 51 mFolders.add(xpp.getAttributeValue(null, "name")); 52 } 53 break; 54 } 55 56 event = xpp.next(); 57 } 58 59 } catch (XmlPullParserException e) { 60 Log.e(TAG, "XML parser error when parsing XML", e); 61 } catch (IOException e) { 62 Log.e(TAG, "I/O error when parsing XML", e); 63 } 64 } 65 66 public ArrayList<String> getList() { 67 return mFolders; 68 } 69} 70