00001 00002 // * Copyright (C) 2005-2015 Team XBMC 00003 // * http://xbmc.org 00004 // * 00005 // * This Program is free software; you can redistribute it and/or modify 00006 // * it under the terms of the GNU General Public License as published by 00007 // * the Free Software Foundation; either version 2, or (at your option) 00008 // * any later version. 00009 // * 00010 // * This Program is distributed in the hope that it will be useful, 00011 // * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // * GNU General Public License for more details. 00014 // * 00015 // * You should have received a copy of the GNU General Public License 00016 // * along with XBMC Remote; see the file license. If not, write to 00017 // * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 00018 // * http://www.gnu.org/copyleft/gpl.html 00019 // * 00020 // */ 00021 // 00022 //package org.xbmc.android.jsonrpc.io; 00023 // 00024 //import android.content.ContentProvider; 00025 //import android.content.ContentResolver; 00026 //import android.content.ContentValues; 00027 //import android.os.Parcel; 00028 //import android.os.Parcelable; 00029 //import android.util.Log; 00030 //import org.codehaus.jackson.JsonNode; 00031 // 00032 //import java.io.IOException; 00033 // 00035 // * Abstract class that handles reading and parsing an JSON-serialized API 00036 // * response into a set of ContentProviderOperation. It catches 00037 // * recoverable network exceptions and re-throws them as {@link ApiException}. 00038 // * Any local {@link ContentProvider} exceptions are considered unrecoverable. 00039 // * <p> 00040 // * This class is only designed to handle simple one-way synchronization. 00041 // * <p> 00042 // * This class was closely inspired by Google's official iosched app, see 00043 // * http://code.google.com/p/iosched/ 00044 // * 00045 // * @author freezy <freezy@xbmc.org> 00046 // */ 00047 //public abstract class JsonHandler implements Parcelable { 00048 // 00049 // private static final String TAG = JsonHandler.class.getSimpleName(); 00050 // 00051 // private final String mAuthority; 00052 // 00053 // public JsonHandler(String authority) { 00054 // mAuthority = authority; 00055 // } 00056 // 00057 // /** 00058 // * Parse the given HTTP response body, turning into a series of 00059 // * ContentProviderOperation that are immediately applied using the 00060 // * given {@link ContentResolver}. 00061 // * 00062 // * @param result Deserialized JSON response 00063 // * @param resolver Content resolver 00064 // * @throws ApiException Re-thrown errors 00065 // */ 00066 // public void applyResult(JsonNode result, ContentResolver resolver) throws ApiException { 00067 // try { 00068 // final long start = System.currentTimeMillis(); 00069 // 00070 // if (result == null) { 00071 // // TODO handle empty response correctly. 00072 // Log.w(TAG, "Empty response. DEFINE what to do, ignoring now."); 00073 // 00074 // } else { 00075 // 00076 // final ContentValues[] newBatch = parse(result, resolver); 00077 // Log.i(TAG, "Starting to execute " + newBatch.length + " batches.."); 00078 // insert(resolver, newBatch); 00079 // Log.i(TAG, "Execution done in " + (System.currentTimeMillis() - start) + "ms."); 00080 // } 00081 // } catch (IOException e) { 00082 // e.printStackTrace(); 00083 // } 00084 // } 00085 // 00086 // /** 00087 // * Parse the HTTP body's de-serialized {@link JsonNode}, returning a set 00088 // * of ContentProviderOperation that will bring the 00089 // * {@link ContentProvider} into sync with the parsed data. 00090 // * 00091 // * @param result HTTP body de-serialized 00092 // * @param resolver Content resolver 00093 // * @return Array of ContentValues 00094 // */ 00095 // protected abstract ContentValues[] parse(JsonNode result, ContentResolver resolver) throws IOException; 00096 // 00097 // protected abstract void insert(ContentResolver resolver, ContentValues[] batch); 00098 // 00099 // @Override 00100 // public int describeContents() { 00101 // return 0; 00102 // } 00103 // 00104 // @Override 00105 // public void writeToParcel(Parcel parcel, int flags) { 00106 // parcel.writeString(mAuthority); 00107 // } 00108 //}