Java Code Examples for org.xmlpull.v1.XmlPullParserException

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/utils/.

Source file: XmlUtils.java

  31 
vote

public static final void beginDocument(XmlPullParser parser,String firstElementName) throws XmlPullParserException, IOException {
  int type;
  while ((type=parser.next()) != parser.START_TAG && type != parser.END_DOCUMENT) {
    ;
  }
  if (type != parser.START_TAG) {
    throw new XmlPullParserException("No start tag found");
  }
  if (!parser.getName().equals(firstElementName)) {
    throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() + ", expected "+ firstElementName);
  }
}
 

Example 2

From project brut.apktool, under directory /apktool-lib/src/main/java/brut/androlib/res/decoder/.

Source file: AXmlResourceParser.java

  31 
vote

public int next() throws XmlPullParserException, IOException {
  if (m_reader == null) {
    throw new XmlPullParserException("Parser is not opened.",this,null);
  }
  try {
    doNext();
    return m_event;
  }
 catch (  IOException e) {
    close();
    throw e;
  }
}
 

Example 3

From project android-client_1, under directory /src/com/googlecode/asmack/.

Source file: XMLUtils.java

  30 
vote

/** 
 * Copy an XML fragment from a source (pull parser) to a destination (serializer), pulling all element namespaces into the empty prefix. Errata: Some common XMPP servers (read: ejabberd) don't handle stanzas like <n0:iq to="romeo@example.com" xmlns:n0="jabber:client"> this means we'll have to rename "n0" to "", which isn't the default behaviour.
 * @param xmlPullParser The pull parser for xml reading.
 * @param xmlSerializer The serializer for xml writing.
 * @throws XmlPullParserException In case of invalid XML.
 * @throws IOException In case of an closes connection.
 */
public final static void copyXML(XmlPullParser xmlPullParser,XmlSerializer xmlSerializer) throws XmlPullParserException, IOException {
  int startDepth=xmlPullParser.getDepth();
  String namespace=null;
  do {
    int type=xmlPullParser.next();
switch (type) {
case XmlPullParser.END_TAG:
      xmlSerializer.endTag(xmlPullParser.getNamespace(),xmlPullParser.getName());
    break;
case XmlPullParser.START_TAG:
  if (!xmlPullParser.getNamespace().equals(namespace)) {
    namespace=xmlPullParser.getNamespace();
    xmlSerializer.setPrefix("",namespace);
  }
xmlSerializer.startTag(xmlPullParser.getNamespace(),xmlPullParser.getName());
int attributeCount=xmlPullParser.getAttributeCount();
for (int i=0; i < attributeCount; i++) {
xmlSerializer.attribute(xmlPullParser.getAttributeNamespace(i),xmlPullParser.getAttributeName(i),xmlPullParser.getAttributeValue(i));
}
break;
case XmlPullParser.TEXT:
xmlSerializer.text(xmlPullParser.getText());
break;
case XmlPullParser.END_DOCUMENT:
throw new XmlPullParserException("Unexpected end of stream.");
default :
throw new IllegalStateException("Unexpected pull parser type " + type);
}
}
 while (xmlPullParser.getDepth() > startDepth);
}
 

Example 4

From project android_packages_apps_Nfc, under directory /src/com/android/nfc/.

Source file: RegisteredComponentCache.java

  30 
vote

void parseComponentInfo(ResolveInfo info,ArrayList<ComponentInfo> components) throws XmlPullParserException, IOException {
  ActivityInfo ai=info.activityInfo;
  PackageManager pm=mContext.getPackageManager();
  XmlResourceParser parser=null;
  try {
    parser=ai.loadXmlMetaData(pm,mMetaDataName);
    if (parser == null) {
      throw new XmlPullParserException("No " + mMetaDataName + " meta-data");
    }
    parseTechLists(pm.getResourcesForApplication(ai.applicationInfo),ai.packageName,parser,info,components);
  }
 catch (  NameNotFoundException e) {
    throw new XmlPullParserException("Unable to load resources for " + ai.packageName);
  }
 finally {
    if (parser != null)     parser.close();
  }
}
 

Example 5

From project apps-for-android, under directory /Photostream/src/com/google/android/photostream/.

Source file: Flickr.java

  30 
vote

private void parsePhotoLocation(XmlPullParser parser,Location location) throws XmlPullParserException, IOException {
  int type;
  String name;
  final int depth=parser.getDepth();
  while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
    if (type != XmlPullParser.START_TAG) {
      continue;
    }
    name=parser.getName();
    if (RESPONSE_TAG_LOCATION.equals(name)) {
      try {
        location.mLatitude=Float.parseFloat(parser.getAttributeValue(null,RESPONSE_ATTR_LATITUDE));
        location.mLongitude=Float.parseFloat(parser.getAttributeValue(null,RESPONSE_ATTR_LONGITUDE));
      }
 catch (      NumberFormatException e) {
        throw new XmlPullParserException("Could not parse lat/lon",parser,e);
      }
    }
  }
}
 

Example 6

From project AsmackService, under directory /src/com/googlecode/asmack/.

Source file: XMLUtils.java

  30 
vote

/** 
 * Copy an XML fragment from a source (pull parser) to a destination (serializer), pulling all element namespaces into the empty prefix. Errata: Some common XMPP servers (read: ejabberd) don't handle stanzas like <n0:iq to="romeo@example.com" xmlns:n0="jabber:client"> this means we'll have to rename "n0" to "", which isn't the default behaviour.
 * @param xmlPullParser The pull parser for xml reading.
 * @param xmlSerializer The serializer for xml writing.
 * @throws XmlPullParserException In case of invalid XML.
 * @throws IOException In case of an closes connection.
 */
public final static void copyXML(XmlPullParser xmlPullParser,XmlSerializer xmlSerializer) throws XmlPullParserException, IOException {
  int startDepth=xmlPullParser.getDepth();
  String namespace=null;
  do {
    int type=xmlPullParser.next();
switch (type) {
case XmlPullParser.END_TAG:
      xmlSerializer.endTag(xmlPullParser.getNamespace(),xmlPullParser.getName());
    break;
case XmlPullParser.START_TAG:
  if (!xmlPullParser.getNamespace().equals(namespace)) {
    namespace=xmlPullParser.getNamespace();
    xmlSerializer.setPrefix("",namespace);
  }
xmlSerializer.startTag(xmlPullParser.getNamespace(),xmlPullParser.getName());
int attributeCount=xmlPullParser.getAttributeCount();
for (int i=0; i < attributeCount; i++) {
xmlSerializer.attribute(xmlPullParser.getAttributeNamespace(i),xmlPullParser.getAttributeName(i),xmlPullParser.getAttributeValue(i));
}
break;
case XmlPullParser.TEXT:
xmlSerializer.text(xmlPullParser.getText());
break;
case XmlPullParser.END_DOCUMENT:
throw new XmlPullParserException("Unexpected end of stream.");
default :
throw new IllegalStateException("Unexpected pull parser type " + type);
}
}
 while (xmlPullParser.getDepth() > startDepth);
}
 

Example 7

From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

/** 
 * Inflate a menu hierarchy from the specified XML resource. Throws {@link InflateException} if there is an error.
 * @param menuRes Resource ID for an XML layout resource to load (e.g.,<code>R.menu.main_activity</code>)
 * @param menu The Menu to inflate into. The items and submenus will beadded to this Menu.
 */
public void inflate(int menuRes,Menu menu){
  XmlResourceParser parser=null;
  try {
    parser=mContext.getResources().getLayout(menuRes);
    AttributeSet attrs=Xml.asAttributeSet(parser);
    parseMenu(parser,attrs,menu);
  }
 catch (  XmlPullParserException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
catch (  IOException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
 finally {
    if (parser != null)     parser.close();
  }
}
 

Example 8

From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

/** 
 * Inflate a menu hierarchy from the specified XML resource. Throws {@link InflateException} if there is an error.
 * @param menuRes Resource ID for an XML layout resource to load (e.g.,<code>R.menu.main_activity</code>)
 * @param menu The Menu to inflate into. The items and submenus will beadded to this Menu.
 */
public void inflate(int menuRes,Menu menu){
  XmlResourceParser parser=null;
  try {
    parser=mContext.getResources().getLayout(menuRes);
    AttributeSet attrs=Xml.asAttributeSet(parser);
    parseMenu(parser,attrs,menu);
  }
 catch (  XmlPullParserException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
catch (  IOException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
 finally {
    if (parser != null)     parser.close();
  }
}
 

Example 9

From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

/** 
 * Inflate a menu hierarchy from the specified XML resource. Throws {@link InflateException} if there is an error.
 * @param menuRes Resource ID for an XML layout resource to load (e.g.,<code>R.menu.main_activity</code>)
 * @param menu The Menu to inflate into. The items and submenus will beadded to this Menu.
 */
public void inflate(int menuRes,Menu menu){
  XmlResourceParser parser=null;
  try {
    parser=mContext.getResources().getLayout(menuRes);
    AttributeSet attrs=Xml.asAttributeSet(parser);
    parseMenu(parser,attrs,menu);
  }
 catch (  XmlPullParserException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
catch (  IOException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
 finally {
    if (parser != null)     parser.close();
  }
}
 

Example 10

From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

/** 
 * Inflate a menu hierarchy from the specified XML resource. Throws {@link InflateException} if there is an error.
 * @param menuRes Resource ID for an XML layout resource to load (e.g.,<code>R.menu.main_activity</code>)
 * @param menu The Menu to inflate into. The items and submenus will beadded to this Menu.
 */
public void inflate(int menuRes,Menu menu){
  XmlResourceParser parser=null;
  try {
    parser=mContext.getResources().getLayout(menuRes);
    AttributeSet attrs=Xml.asAttributeSet(parser);
    parseMenu(parser,attrs,menu);
  }
 catch (  XmlPullParserException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
catch (  IOException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
 finally {
    if (parser != null)     parser.close();
  }
}
 

Example 11

From project andlytics, under directory /actionbarsherlock/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

/** 
 * Inflate a menu hierarchy from the specified XML resource. Throws {@link InflateException} if there is an error.
 * @param menuRes Resource ID for an XML layout resource to load (e.g.,<code>R.menu.main_activity</code>)
 * @param menu The Menu to inflate into. The items and submenus will beadded to this Menu.
 */
public void inflate(int menuRes,Menu menu){
  XmlResourceParser parser=null;
  try {
    parser=mContext.getResources().getLayout(menuRes);
    AttributeSet attrs=Xml.asAttributeSet(parser);
    parseMenu(parser,attrs,menu);
  }
 catch (  XmlPullParserException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
catch (  IOException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
 finally {
    if (parser != null)     parser.close();
  }
}
 

Example 12

From project Android, under directory /AndroidNolesCore/src/io/.

Source file: RemoteExecutor.java

  29 
vote

public void executeWithPullParser(String urlString,final XmlHandler handler,int size){
  final XMLParserConnection connection=new XMLParserConnection(mContext);
  connection.execute(urlString,size,new XMLParserConnection.XMLParserListener(){
    public void onPostExecute(    XmlPullParser parser) throws XmlPullParserException, IOException {
      handler.parseAndApply(parser,mResolver);
    }
  }
);
}
 

Example 13

From project android-animation-backport, under directory /animation-backport/src/backports/animation/.

Source file: AnimationUtils.java

  29 
vote

/** 
 * Loads an  {@link Interpolator} object from a resource
 * @param context Application context used to access resources
 * @param id The resource id of the animation to load
 * @return The animation object reference by the specified id
 * @throws NotFoundException
 */
public static Interpolator loadInterpolator(Context context,int id) throws NotFoundException {
  XmlResourceParser parser=null;
  try {
    parser=context.getResources().getAnimation(id);
    return createInterpolatorFromXml(context,parser);
  }
 catch (  XmlPullParserException ex) {
    NotFoundException rnf=new NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id));
    rnf.initCause(ex);
    throw rnf;
  }
catch (  IOException ex) {
    NotFoundException rnf=new NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id));
    rnf.initCause(ex);
    throw rnf;
  }
 finally {
    if (parser != null)     parser.close();
  }
}
 

Example 14

From project android-api_1, under directory /android-lib/src/com/catchnotes/api/.

Source file: CatchAPI.java

  29 
vote

/** 
 * Fetches a list of note references representing all of the user's notes.
 * @param noteRefs List where fetched note refs will be returned.
 * @return RESULT_OK on success.
 */
public int getSyncV2(List<CatchNoteRef> noteRefs){
  int returnCode=RESULT_ERROR;
  if (noteRefs == null) {
    return returnCode;
  }
  String endpoint=API_ENDPOINT_NOTES + ".xml";
  HttpResponse response=performGET(endpoint,null,true);
  if (response != null) {
    if (isResponseOK(response)) {
      boolean parseResult=false;
      try {
        CatchNotesXmlParser xmlParser=new CatchNotesXmlParser();
        xmlParser.parseSyncV2XML(response,noteRefs);
        parseResult=true;
      }
 catch (      IllegalArgumentException e) {
        log("caught an IllegalArgumentException processing response from GET " + endpoint,e);
      }
catch (      XmlPullParserException e) {
        log("caught an XmlPullParserException processing response from GET " + endpoint,e);
      }
catch (      IOException e) {
        log("caught an IOException processing response from GET " + endpoint,e);
      }
      returnCode=(parseResult == true) ? RESULT_OK : RESULT_ERROR_RESPONSE;
    }
 else     if (isResponseUnauthorized(response)) {
      returnCode=RESULT_UNAUTHORIZED;
    }
 else     if (isResponseServerError(response)) {
      returnCode=RESULT_SERVER_ERROR;
    }
    consumeResponse(response);
  }
  return returnCode;
}
 

Example 15

From project android-joedayz, under directory /Proyectos/ConsumirWS/src/net/ivanvega/ConsumirWS/.

Source file: ConsumirWSActivity.java

  29 
vote

/** 
 * Called when the activity is first created. 
 */
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  lsvAndroidOS=(ListView)findViewById(R.id.lst);
  btn=(Button)findViewById(R.id.btn);
  btn.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      request=new SoapObject(NAMESPACE,METHOD_NAME);
      envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
      envelope.dotNet=true;
      envelope.setOutputSoapObject(request);
      HttpTransportSE transporte=new HttpTransportSE(URL);
      try {
        transporte.call(SOAP_ACTION,envelope);
        resultsRequestSOAP=(SoapPrimitive)envelope.getResponse();
      }
 catch (      IOException e) {
        e.printStackTrace();
      }
catch (      XmlPullParserException e) {
        e.printStackTrace();
      }
      String strJSON=resultsRequestSOAP.toString();
      crearLista(strJSON);
    }
  }
);
}
 

Example 16

From project android-thaiime, under directory /latinime/src/com/android/inputmethod/deprecated/languageswitcher/.

Source file: InputLanguageSelection.java

  29 
vote

private Pair<Long,Boolean> hasDictionaryOrLayout(Locale locale){
  if (locale == null)   return new Pair<Long,Boolean>(null,false);
  final Resources res=getResources();
  final Locale saveLocale=LocaleUtils.setSystemLocale(res,locale);
  final Long dictionaryId=DictionaryFactory.getDictionaryId(this,locale);
  boolean hasLayout=false;
  try {
    final String localeStr=locale.toString();
    final String[] layoutCountryCodes=KeyboardBuilder.parseKeyboardLocale(this,R.xml.kbd_qwerty).split(",",-1);
    if (!TextUtils.isEmpty(localeStr) && layoutCountryCodes.length > 0) {
      for (      String s : layoutCountryCodes) {
        if (s.equals(localeStr)) {
          hasLayout=true;
          break;
        }
      }
    }
  }
 catch (  XmlPullParserException e) {
  }
catch (  IOException e) {
  }
  LocaleUtils.setSystemLocale(res,saveLocale);
  return new Pair<Long,Boolean>(dictionaryId,hasLayout);
}
 

Example 17

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/provider/.

Source file: BooksStore.java

  29 
vote

/** 
 * Finds the book with the specified id.
 * @param id The id of the book to find (ISBN-10, ISBN-13, etc.)
 * @return A Book instance if the book was found or null otherwise.
 */
public Book findBook(String id){
  final Uri.Builder uri=buildFindBookQuery(id);
  final HttpGet get=new HttpGet(uri.build().toString());
  final Book book=createBook();
  final boolean[] result=new boolean[1];
  try {
    executeRequest(new HttpHost(mHost,80,"http"),get,new ResponseHandler(){
      public void handleResponse(      InputStream in) throws IOException {
        parseResponse(in,new ResponseParser(){
          public void parseResponse(          XmlPullParser parser) throws XmlPullParserException, IOException {
            result[0]=parseBook(parser,book);
          }
        }
);
      }
    }
);
    if (TextUtils.isEmpty(book.mEan) && id.length() == 13) {
      book.mEan=id;
    }
 else     if (TextUtils.isEmpty(book.mIsbn) && id.length() == 10) {
      book.mIsbn=id;
    }
    return result[0] ? book : null;
  }
 catch (  IOException e) {
    android.util.Log.e(LOG_TAG,"Could not find the item with ISBN/EAN: " + id);
  }
  return null;
}
 

Example 18

From project androidpn, under directory /androidpn-server-bin-tomcat/src/org/androidpn/server/xmpp/net/.

Source file: StanzaHandler.java

  29 
vote

private void createSession(XmlPullParser xpp) throws XmlPullParserException, IOException {
  for (int eventType=xpp.getEventType(); eventType != XmlPullParser.START_TAG; ) {
    eventType=xpp.next();
  }
  String namespace=xpp.getNamespace(null);
  if ("jabber:client".equals(namespace)) {
    session=ClientSession.createSession(serverName,connection,xpp);
    if (session == null) {
      StringBuilder sb=new StringBuilder(250);
      sb.append("<?xml version='1.0' encoding='UTF-8'?>");
      sb.append("<stream:stream from=\"").append(serverName);
      sb.append("\" id=\"").append(randomString(5));
      sb.append("\" xmlns=\"").append(xpp.getNamespace(null));
      sb.append("\" xmlns:stream=\"").append(xpp.getNamespace("stream"));
      sb.append("\" version=\"1.0\">");
      StreamError error=new StreamError(StreamError.Condition.bad_namespace_prefix);
      sb.append(error.toXML());
      connection.deliverRawText(sb.toString());
      connection.close();
      log.warn("Closing session due to bad_namespace_prefix in stream header: " + namespace);
    }
  }
}
 

Example 19

From project androidZenWriter, under directory /library/src/com/actionbarsherlock/view/.

Source file: MenuInflater.java

  29 
vote

/** 
 * Inflate a menu hierarchy from the specified XML resource. Throws {@link InflateException} if there is an error.
 * @param menuRes Resource ID for an XML layout resource to load (e.g.,<code>R.menu.main_activity</code>)
 * @param menu The Menu to inflate into. The items and submenus will beadded to this Menu.
 */
public void inflate(int menuRes,Menu menu){
  XmlResourceParser parser=null;
  try {
    parser=mContext.getResources().getLayout(menuRes);
    AttributeSet attrs=Xml.asAttributeSet(parser);
    parseMenu(parser,attrs,menu);
  }
 catch (  XmlPullParserException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
catch (  IOException e) {
    throw new InflateException("Error inflating menu XML",e);
  }
 finally {
    if (parser != null)     parser.close();
  }
}
 

Example 20

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.

Source file: DeviceAdminSettings.java

  29 
vote

void updateList(){
  mActiveAdmins.clear();
  List<ComponentName> cur=mDPM.getActiveAdmins();
  if (cur != null) {
    for (int i=0; i < cur.size(); i++) {
      mActiveAdmins.add(cur.get(i));
    }
  }
  mAvailableAdmins.clear();
  List<ResolveInfo> avail=getPackageManager().queryBroadcastReceivers(new Intent(DeviceAdminReceiver.ACTION_DEVICE_ADMIN_ENABLED),PackageManager.GET_META_DATA);
  int count=avail == null ? 0 : avail.size();
  for (int i=0; i < count; i++) {
    ResolveInfo ri=avail.get(i);
    try {
      DeviceAdminInfo dpi=new DeviceAdminInfo(this,ri);
      if (dpi.isVisible() || mActiveAdmins.contains(dpi.getComponent())) {
        mAvailableAdmins.add(dpi);
      }
    }
 catch (    XmlPullParserException e) {
      Log.w(TAG,"Skipping " + ri.activityInfo,e);
    }
catch (    IOException e) {
      Log.w(TAG,"Skipping " + ri.activityInfo,e);
    }
  }
  getListView().setAdapter(new PolicyListAdapter());
}
 

Example 21

From project android_packages_apps_Exchange, under directory /src/com/android/exchange/adapter/.

Source file: ProvisionParser.java

  29 
vote

void parseProvisionDocXml(String doc) throws IOException {
  Policy policy=new Policy();
  try {
    XmlPullParserFactory factory=XmlPullParserFactory.newInstance();
    XmlPullParser parser=factory.newPullParser();
    parser.setInput(new ByteArrayInputStream(doc.getBytes()),"UTF-8");
    int type=parser.getEventType();
    if (type == XmlPullParser.START_DOCUMENT) {
      type=parser.next();
      if (type == XmlPullParser.START_TAG) {
        String tagName=parser.getName();
        if (tagName.equals("wap-provisioningdoc")) {
          parseWapProvisioningDoc(parser,policy);
        }
      }
    }
  }
 catch (  XmlPullParserException e) {
    throw new IOException();
  }
  setPolicy(policy);
}
 

Example 22

From project android_packages_apps_FileManager, under directory /src/org/openintents/filemanager/.

Source file: FileManagerActivity.java

  29 
vote

/** 
 */
private void getMimeTypes(){
  MimeTypeParser mtp=null;
  try {
    mtp=new MimeTypeParser(this,this.getPackageName());
  }
 catch (  NameNotFoundException e) {
  }
  XmlResourceParser in=getResources().getXml(R.xml.mimetypes);
  try {
    mMimeTypes=mtp.fromXmlResource(in);
  }
 catch (  XmlPullParserException e) {
    Log.e(TAG,"PreselectedChannelsActivity: XmlPullParserException",e);
    throw new RuntimeException("PreselectedChannelsActivity: XmlPullParserException");
  }
catch (  IOException e) {
    Log.e(TAG,"PreselectedChannelsActivity: IOException",e);
    throw new RuntimeException("PreselectedChannelsActivity: IOException");
  }
}
 

Example 23

From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/util/.

Source file: BackupUtil.java

  29 
vote

public static int restoreBackup(Context context){
  XmlPullParser parser=Xml.newPullParser();
  FileInputStream file=null;
  int appsRestored=0;
  try {
    file=new FileInputStream(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/subackup.xml"));
    parser.setInput(file,"UTF-8");
    int eventType=parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
        if (parser.getName().equalsIgnoreCase("apps")) {
          parser.next();
          appsRestored=restoreApps(context,parser);
        }
 else         if (parser.getName().equalsIgnoreCase("prefs")) {
          parser.next();
          restorePrefs(context,parser);
        }
      break;
  }
  eventType=parser.next();
}
}
 catch (XmlPullParserException e) {
Log.e(TAG,"Error restoring backup",e);
return -1;
}
catch (IOException e) {
Log.e(TAG,"Error restoring backup",e);
return -1;
}
return appsRestored;
}
 

Example 24

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/deprecated/languageswitcher/.

Source file: InputLanguageSelection.java

  29 
vote

private Pair<Long,Boolean> hasDictionaryOrLayout(Locale locale){
  if (locale == null)   return new Pair<Long,Boolean>(null,false);
  final Resources res=getResources();
  final Locale saveLocale=LocaleUtils.setSystemLocale(res,locale);
  final Long dictionaryId=DictionaryFactory.getDictionaryId(this,locale);
  boolean hasLayout=false;
  try {
    final String localeStr=locale.toString();
    final String[] layoutCountryCodes=KeyboardBuilder.parseKeyboardLocale(this,R.xml.kbd_qwerty).split(",",-1);
    if (!TextUtils.isEmpty(localeStr) && layoutCountryCodes.length > 0) {
      for (      String s : layoutCountryCodes) {
        if (s.equals(localeStr)) {
          hasLayout=true;
          break;
        }
      }
    }
  }
 catch (  XmlPullParserException e) {
  }
catch (  IOException e) {
  }
  LocaleUtils.setSystemLocale(res,saveLocale);
  return new Pair<Long,Boolean>(dictionaryId,hasLayout);
}
 

Example 25

From project android_packages_wallpapers_basic, under directory /src/com/android/wallpaper/polarclock/.

Source file: PolarClockWallpaper.java

  29 
vote

ClockEngine(){
  XmlResourceParser xrp=getResources().getXml(R.xml.polar_clock_palettes);
  try {
    int what=xrp.getEventType();
    while (what != END_DOCUMENT) {
      if (what == START_TAG) {
        if ("palette".equals(xrp.getName())) {
          ClockPalette pal=ClockPalette.parseXmlPaletteTag(xrp);
          if (pal.getId() != null) {
            mPalettes.put(pal.getId(),pal);
          }
        }
      }
      what=xrp.next();
    }
  }
 catch (  IOException e) {
    Log.e(LOG_TAG,"An error occured during wallpaper configuration:",e);
  }
catch (  XmlPullParserException e) {
    Log.e(LOG_TAG,"An error occured during wallpaper configuration:",e);
  }
 finally {
    xrp.close();
  }
  mPalette=CyclingClockPalette.getFallback();
}
 

Example 26

From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/io/.

Source file: LocalBlocksHandler.java

  29 
vote

@Override public ArrayList<ContentProviderOperation> parse(XmlPullParser parser,ContentResolver resolver) throws XmlPullParserException, IOException {
  final ArrayList<ContentProviderOperation> batch=Lists.newArrayList();
  final String selection=Blocks.BLOCK_TYPE + "=? OR " + Blocks.BLOCK_TYPE+ "=?";
  final String[] selectionArgs={ParserUtils.BLOCK_TYPE_FOOD,ParserUtils.BLOCK_TYPE_OFFICE_HOURS};
  batch.add(ContentProviderOperation.newDelete(Blocks.CONTENT_URI).withSelection(selection,selectionArgs).build());
  int type;
  while ((type=parser.next()) != END_DOCUMENT) {
    if (type == START_TAG && Tags.BLOCK.equals(parser.getName())) {
      batch.add(parseBlock(parser));
    }
  }
  return batch;
}
 

Example 27

From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/io/.

Source file: TwunchesHandler.java

  29 
vote

@Override public ArrayList<ContentProviderOperation> parse(XmlPullParser parser,ContentResolver resolver) throws XmlPullParserException, IOException {
  final ArrayList<ContentProviderOperation> batch=Lists.newArrayList();
  batch.add(ContentProviderOperation.newDelete(Twunches.CONTENT_URI).build());
  int type;
  while ((type=parser.next()) != END_DOCUMENT) {
    if (type == START_TAG && Tags.TWUNCH.equals(parser.getName())) {
      ContentProviderOperation operation=parseTwunch(parser,resolver);
      if (operation == null) {
        break;
      }
      batch.add(operation);
    }
  }
  return batch;
}
 

Example 28

From project BibleQuote-for-Android, under directory /src/com/BibleQuote/dal/repository/.

Source file: XmlTskRepository.java

  29 
vote

private XmlPullParser getParser() throws XmlPullParserException, UnsupportedEncodingException, TskNotFoundException {
  File tskDir=new File(DataConstants.FS_APP_DIR_NAME);
  File tsk=new File(tskDir,"tsk.xml");
  InputStreamReader iReader;
  try {
    iReader=new InputStreamReader(new FileInputStream(tsk),"UTF-8");
  }
 catch (  FileNotFoundException e) {
    throw new TskNotFoundException();
  }
  BufferedReader buf=new BufferedReader(iReader);
  XmlPullParser parser=Xml.newPullParser();
  parser.setInput(buf);
  return parser;
}
 

Example 29

From project BusFollower, under directory /src/net/argilo/busfollower/.

Source file: FetchRoutesTask.java

  29 
vote

@Override protected GetRouteSummaryForStopResult doInBackground(String... stopNumber){
  GetRouteSummaryForStopResult result=null;
  try {
    stop=new Stop(applicationContext,db,stopNumber[0]);
    dataFetcher=new OCTranspoDataFetcher(applicationContext,db);
    result=dataFetcher.getRouteSummaryForStop(stop.getNumber());
    errorString=Util.getErrorString(applicationContext,result.getError());
    if (errorString == null) {
      if (result.getRoutes().isEmpty()) {
        errorString=applicationContext.getString(R.string.no_routes);
      }
    }
  }
 catch (  IOException e) {
    errorString=applicationContext.getString(R.string.server_error);
  }
catch (  XmlPullParserException e) {
    errorString=applicationContext.getString(R.string.invalid_response);
  }
catch (  IllegalArgumentException e) {
    errorString=e.getMessage();
  }
catch (  IllegalStateException e) {
  }
  return result;
}
 

Example 30

From project callmeter, under directory /src/de/ub0r/android/callmeter/data/.

Source file: DataProvider.java

  29 
vote

/** 
 * Parse all values of a given XML element to import it as {@link ContentValues} into {@link SQLiteDatabase}.
 * @param context {@link Context}
 * @param parser XmlPullParser
 * @param lists list of  {@link ContentValues} {@link ArrayList}s.
 * @param name name of the holding element
 * @param list current list
 * @throws XmlPullParserException XmlPullParserException
 * @throws IOException IOException
 */
private static void parseValues(final Context context,final XmlPullParser parser,final HashMap<String,ArrayList<ContentValues>> lists,final String name,final ArrayList<ContentValues> list) throws XmlPullParserException, IOException {
  String element=name.substring(0,name.length() - 1);
  while (parser.next() != XmlPullParser.END_TAG) {
    if (parser.getEventType() != XmlPullParser.START_TAG) {
      continue;
    }
    parser.require(XmlPullParser.START_TAG,null,element);
    ContentValues cv=new ContentValues();
    while (parser.next() != XmlPullParser.END_TAG || !element.equals(parser.getName())) {
      if (parser.getEventType() != XmlPullParser.START_TAG) {
        continue;
      }
      String k=parser.getName();
      if (k.equals("hours")) {
        parser.next();
        ArrayList<ContentValues> l=new ArrayList<ContentValues>();
        lists.put(DataProvider.Hours.TABLE,l);
        parseValues(context,parser,lists,k,l);
      }
 else       if (k.equals("numbers")) {
        parser.next();
        ArrayList<ContentValues> l=new ArrayList<ContentValues>();
        lists.put(DataProvider.Numbers.TABLE,l);
        parseValues(context,parser,lists,k,l);
      }
 else {
        parser.next();
        String v=parser.getText();
        if (!TextUtils.isEmpty(v)) {
          cv.put(k,decodeString(v));
        }
      }
    }
    if (cv.size() > 0) {
      list.add(cv);
    }
  }
}
 

Example 31

From project CineShowTime-Android, under directory /Libraries/GreenDroid/src/greendroid/widget/item/.

Source file: DrawableItem.java

  29 
vote

@Override public void inflate(Resources r,XmlPullParser parser,AttributeSet attrs) throws XmlPullParserException, IOException {
  super.inflate(r,parser,attrs);
  TypedArray a=r.obtainAttributes(attrs,R.styleable.DrawableItem);
  drawableId=a.getResourceId(R.styleable.DrawableItem_drawable,0);
  a.recycle();
}
 

Example 32

From project com.juick.xmpp, under directory /src/com/juick/xmpp/extensions/.

Source file: Delay.java

  29 
vote

public static Delay parse(XmlPullParser parser) throws XmlPullParserException, IOException {
  Delay delay=new Delay();
  String from=parser.getAttributeValue(null,"from");
  if (from != null) {
    delay.from=new JID(from);
  }
  delay.stamp=parser.getAttributeValue(null,"stamp");
  delay.description=XmlUtils.getTagText(parser);
  return delay;
}