Android Open Source - pulltorefresh_library_with_Indexable_listView Extended Xml Config Parser Factory

From Project

Back to project page pulltorefresh_library_with_Indexable_listView.


The source code is released under:

Apache License

If you think the Android project pulltorefresh_library_with_Indexable_listView 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

 * Copyright 2013 Naver Business Platform Corp.
 * // ww w  .j  a  v  a 2  s  .  c  om
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package com.handmark.pulltorefresh.configuration.xml;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
 * Parser of assets/pulltorefresh.xml creation factory 
 * @author Wonjun Kim
class ExtendedConfigXmlParserFactory {
  private static final String LOG_TAG = ExtendedConfigXmlParserFactory.class.getName();
   * pulltorefresh.xml path in assets folder
  private static final String XML_PATH_IN_ASSETS = "pulltorefresh.xml";
   * pulltorefresh.xml encoding type
  private static final String DEFAULT_ENCODING_TYPE = "utf-8";
   * Create a parser of assets/pulltorefresh.xml 
   * @param context
   * @return {@code parser} if creating parser has done, or {@code null} if an error occured during creation
  public static XmlPullParser createParser(Context context) {
    AssetManager am = context.getAssets();
    XmlPullParser parser = null;
    try {
      InputStream is =;
      parser = XmlPullParserFactory.newInstance().newPullParser();
      parser.setInput(is, DEFAULT_ENCODING_TYPE);
    } catch (FileNotFoundException e) {
      Log.d(LOG_TAG, "The configuration file 'assets/" + XML_PATH_IN_ASSETS + "' is missing. But the file is just an option. It is necessary only if you want to customize something in Pull To Refresh.");
      // explicitly assign null
      parser = null;
    } catch (XmlPullParserException e) {
      Log.w(LOG_TAG, "The error occurs below when generating parser.", e);
      // explicitly assign null
      parser = null;
    } catch (IOException e) {
      Log.w(LOG_TAG, "Loading "+XML_PATH_IN_ASSETS+" file has failed.", e);
      // explicitly assign null
      parser = null;
    // NOTE: this code makes a fatal error. so omit the code.
    // am.close();
    return parser;

Java Source Code List