package com.handmark.pulltorefresh.configuration.xml;

import java.io.IOException;
import java.io.InputStream;

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 = am.open(XML_PATH_IN_ASSETS);
			parser = XmlPullParserFactory.newInstance().newPullParser();
			parser.setInput(is, DEFAULT_ENCODING_TYPE);
			
		} 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;
	}
}

@@ -48,16 +48,54 @@
 n.xml;%0A%0A
+import java.io.FileNotFoundException;%0A
 import j
@@ -1307,16 +1307,302 @@
 E);%0A%09%09%09%0A
+%09%09%7D catch (FileNotFoundException e) %7B%0A%09%09%09Log.d(LOG_TAG, %22The configuration file 'assets/%22 + XML_PATH_IN_ASSETS + %22' is missing. But the file is just an option. It is necessary only if you want to customize something in Pull To Refresh.%22);%0A%09%09%09// explicitly assign null%0A%09%09%09parser = null;%0A
 %09%09%7D catc

Send the debug message from ExtendXmlConfigParserFactory.createParser() method when FileNotFoundException throws