@@ -20,7 +20,8 @@
|
|||||||
package org.RickBarrette.osj.forum;
|
package org.RickBarrette.osj.forum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will be used to house the constraints of this application
|
* This class will be used to house the constraints of this application
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class Constraints {
|
public class Constraints {
|
||||||
|
|||||||
@@ -50,6 +50,13 @@ public class ForumDetailActivity extends FragmentActivity implements OnItemSelec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(final Fragment listFragment, final String id) {
|
||||||
|
final Intent detailIntent = new Intent(this, TopicDetailActivity.class);
|
||||||
|
detailIntent.putExtra(TopicDetailFragment.ARG_ITEM_ID, id);
|
||||||
|
startActivity(detailIntent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
@@ -59,11 +66,4 @@ public class ForumDetailActivity extends FragmentActivity implements OnItemSelec
|
|||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemSelected(Fragment listFragment, String id) {
|
|
||||||
final Intent detailIntent = new Intent(this, TopicDetailActivity.class);
|
|
||||||
detailIntent.putExtra(TopicDetailFragment.ARG_ITEM_ID, id);
|
|
||||||
startActivity(detailIntent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,10 +20,10 @@
|
|||||||
package org.RickBarrette.osj.forum;
|
package org.RickBarrette.osj.forum;
|
||||||
|
|
||||||
import org.RickBarrette.osj.forum.content.ForumContent;
|
import org.RickBarrette.osj.forum.content.ForumContent;
|
||||||
|
import org.RickBarrette.osj.forum.content.ForumContent.ForumItem;
|
||||||
import org.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
import org.RickBarrette.osj.forum.content.OnItemSelectedListener;
|
||||||
import org.RickBarrette.osj.forum.content.TopicAdapter;
|
import org.RickBarrette.osj.forum.content.TopicAdapter;
|
||||||
import org.RickBarrette.osj.forum.content.TopicContent;
|
import org.RickBarrette.osj.forum.content.TopicContent;
|
||||||
import org.RickBarrette.osj.forum.content.ForumContent.ForumItem;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -33,9 +33,9 @@ import android.widget.AbsListView;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This fragment will be used to display information about the forum
|
* This fragment will be used to display information about the forum
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ForumDetailFragment extends ListFragment {
|
public class ForumDetailFragment extends ListFragment {
|
||||||
@@ -52,10 +52,11 @@ public class ForumDetailFragment extends ListFragment {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
|
* @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(final Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
if (!(activity instanceof OnItemSelectedListener))
|
if (!(activity instanceof OnItemSelectedListener))
|
||||||
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
||||||
@@ -69,13 +70,13 @@ public class ForumDetailFragment extends ListFragment {
|
|||||||
if (getArguments().containsKey(ARG_ITEM_ID))
|
if (getArguments().containsKey(ARG_ITEM_ID))
|
||||||
mItem = ForumContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
|
mItem = ForumContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
|
||||||
|
|
||||||
new Thread( new Runnable(){
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run() {
|
||||||
TopicContent.getTopics((String) mItem.content.get("forum_id"), getActivity());
|
TopicContent.getTopics((String) mItem.content.get("forum_id"), getActivity());
|
||||||
getActivity().runOnUiThread(new Runnable(){
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run() {
|
||||||
setListAdapter(new TopicAdapter(getActivity()));
|
setListAdapter(new TopicAdapter(getActivity()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -85,15 +86,16 @@ public class ForumDetailFragment extends ListFragment {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView, android.view.View, int, long)
|
*
|
||||||
|
* @see android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView,
|
||||||
|
* android.view.View, int, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
|
||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position).id);
|
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position).id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(final Bundle outState) {
|
public void onSaveInstanceState(final Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ForumListActivity extends FragmentActivity implements OnItemSelecte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||||
final MenuInflater inflater = getMenuInflater();
|
final MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.main_menu, menu);
|
inflater.inflate(R.menu.main_menu, menu);
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
@@ -61,33 +61,32 @@ public class ForumListActivity extends FragmentActivity implements OnItemSelecte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(final Fragment listFragment, final String id) {
|
public void onItemSelected(final Fragment listFragment, final String id) {
|
||||||
if(listFragment instanceof ForumDetailFragment){
|
if (listFragment instanceof ForumDetailFragment) {
|
||||||
final Intent detailIntent = new Intent(this, TopicListActivity.class);
|
final Intent detailIntent = new Intent(this, TopicListActivity.class);
|
||||||
detailIntent.putExtra(TopicListActivity.ARG_ITEM_ID, id);
|
detailIntent.putExtra(TopicListActivity.ARG_ITEM_ID, id);
|
||||||
startActivity(detailIntent);
|
startActivity(detailIntent);
|
||||||
} else
|
} else if (mTwoPane) {
|
||||||
if (mTwoPane) {
|
if (listFragment instanceof ForumListFragment) {
|
||||||
if(listFragment instanceof ForumListFragment){
|
final Bundle arguments = new Bundle();
|
||||||
final Bundle arguments = new Bundle();
|
arguments.putString(ForumDetailFragment.ARG_ITEM_ID, id);
|
||||||
arguments.putString(ForumDetailFragment.ARG_ITEM_ID, id);
|
final ForumDetailFragment fragment = new ForumDetailFragment();
|
||||||
final ForumDetailFragment fragment = new ForumDetailFragment();
|
fragment.setArguments(arguments);
|
||||||
fragment.setArguments(arguments);
|
getSupportFragmentManager().beginTransaction().replace(R.id.forum_detail_container, fragment).commit();
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.forum_detail_container, fragment).commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
final Intent detailIntent = new Intent(this, ForumDetailActivity.class);
|
|
||||||
detailIntent.putExtra(ForumDetailFragment.ARG_ITEM_ID, id);
|
|
||||||
startActivity(detailIntent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
final Intent detailIntent = new Intent(this, ForumDetailActivity.class);
|
||||||
|
detailIntent.putExtra(ForumDetailFragment.ARG_ITEM_ID, id);
|
||||||
|
startActivity(detailIntent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
switch(item.getItemId()){
|
switch (item.getItemId()) {
|
||||||
case R.id.legal:
|
case R.id.legal:
|
||||||
startActivity(new Intent(this, LegalActivity.class));
|
startActivity(new Intent(this, LegalActivity.class));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import android.widget.AbsListView;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -66,14 +65,14 @@ public class ForumListFragment extends ListFragment {
|
|||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if(ForumContent.ITEMS.size() == 0)
|
if (ForumContent.ITEMS.size() == 0)
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ForumContent.getForum(getActivity());
|
ForumContent.getForum(getActivity());
|
||||||
getActivity().runOnUiThread(new Runnable(){
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run() {
|
||||||
setListAdapter(new ForumAdapter(getActivity()));
|
setListAdapter(new ForumAdapter(getActivity()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,15 +25,16 @@ import android.webkit.WebView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a super simple web activity to display legal information to the user
|
* This is a super simple web activity to display legal information to the user
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class LegalActivity extends Activity {
|
public class LegalActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.leagal_activity);
|
setContentView(R.layout.leagal_activity);
|
||||||
WebView wv = (WebView) findViewById(R.id.webview);
|
final WebView wv = (WebView) findViewById(R.id.webview);
|
||||||
wv.loadUrl("file:///android_asset/legal.html");
|
wv.loadUrl("file:///android_asset/legal.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,145 +21,158 @@ package org.RickBarrette.osj.forum;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A convince class for logging with log level constraints
|
* A convince class for logging with log level constraints
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class Log {
|
public class Log {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a DEBUG log message
|
* Send a DEBUG log message
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void d(String tag, String log){
|
public static void d(final String tag, final String log) {
|
||||||
if(Constraints.DEBUG)
|
if (Constraints.DEBUG)
|
||||||
android.util.Log.d(tag, log);
|
android.util.Log.d(tag, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a DEBUG log message and log the exception.
|
* Send a DEBUG log message and log the exception.
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @param e
|
* @param e
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void d(String tag, String log, Throwable e){
|
public static void d(final String tag, final String log, final Throwable e) {
|
||||||
if(Constraints.DEBUG)
|
if (Constraints.DEBUG)
|
||||||
android.util.Log.d(tag, log, e);
|
android.util.Log.d(tag, log, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a ERROR log message
|
* Send a ERROR log message
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void e(String tag, String log){
|
public static void e(final String tag, final String log) {
|
||||||
if(Constraints.ERROR)
|
if (Constraints.ERROR)
|
||||||
android.util.Log.e(tag, log);
|
android.util.Log.e(tag, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a ERROR log message and log the exception.
|
* Send a ERROR log message and log the exception.
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @param e
|
* @param e
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void e(String tag, String log, Throwable e){
|
public static void e(final String tag, final String log, final Throwable e) {
|
||||||
if(Constraints.ERROR)
|
if (Constraints.ERROR)
|
||||||
android.util.Log.e(tag, log, e);
|
android.util.Log.e(tag, log, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a INFO log message
|
* Send a INFO log message
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void i(String tag, String log){
|
public static void i(final String tag, final String log) {
|
||||||
if(Constraints.INFO)
|
if (Constraints.INFO)
|
||||||
android.util.Log.i(tag, log);
|
android.util.Log.i(tag, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a INFO log message and log the exception.
|
* Send a INFO log message and log the exception.
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @param e
|
* @param e
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void i(String tag, String log, Throwable e){
|
public static void i(final String tag, final String log, final Throwable e) {
|
||||||
if(Constraints.INFO)
|
if (Constraints.INFO)
|
||||||
android.util.Log.i(tag, log, e);
|
android.util.Log.i(tag, log, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a VERBOSE log message
|
* Send a VERBOSE log message
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void v(String tag, String log){
|
public static void v(final String tag, final String log) {
|
||||||
if(Constraints.VERBOSE)
|
if (Constraints.VERBOSE)
|
||||||
android.util.Log.v(tag, log);
|
android.util.Log.v(tag, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a VERBOSE log message and log the exception.
|
* Send a VERBOSE log message and log the exception.
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @param e
|
* @param e
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void v(String tag, String log, Throwable e){
|
public static void v(final String tag, final String log, final Throwable e) {
|
||||||
if(Constraints.VERBOSE)
|
if (Constraints.VERBOSE)
|
||||||
android.util.Log.v(tag, log, e);
|
android.util.Log.v(tag, log, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a WARNING log message
|
* Send a WARNING log message
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void w(String tag, String log){
|
public static void w(final String tag, final String log) {
|
||||||
if(Constraints.WARNING)
|
if (Constraints.WARNING)
|
||||||
android.util.Log.w(tag, log);
|
android.util.Log.w(tag, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a WARNING log message and log the exception.
|
* Send a WARNING log message and log the exception.
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @param e
|
* @param e
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void w(String tag, String log, Throwable e){
|
public static void w(final String tag, final String log, final Throwable e) {
|
||||||
if(Constraints.WARNING)
|
if (Constraints.WARNING)
|
||||||
android.util.Log.w(tag, log, e);
|
android.util.Log.w(tag, log, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a WTF log message
|
* Send a WTF log message
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void wtf(String tag, String log){
|
public static void wtf(final String tag, final String log) {
|
||||||
if(Constraints.WTF)
|
if (Constraints.WTF)
|
||||||
android.util.Log.wtf(tag, log);
|
android.util.Log.wtf(tag, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a WTF log message and log the exception.
|
* Send a WTF log message and log the exception.
|
||||||
|
*
|
||||||
* @param tag
|
* @param tag
|
||||||
* @param log
|
* @param log
|
||||||
* @param e
|
* @param e
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void wtf(String tag, String log, Throwable e){
|
public static void wtf(final String tag, final String log, final Throwable e) {
|
||||||
if(Constraints.WTF)
|
if (Constraints.WTF)
|
||||||
android.util.Log.wtf(tag, log, e);
|
android.util.Log.wtf(tag, log, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ import android.support.v4.app.FragmentActivity;
|
|||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
public class TopicDetailActivity extends FragmentActivity implements OnItemSelectedListener{
|
public class TopicDetailActivity extends FragmentActivity implements OnItemSelectedListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
@@ -46,6 +46,12 @@ public class TopicDetailActivity extends FragmentActivity implements OnItemSelec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemSelected(final Fragment listFragment, final String id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||||
if (item.getItemId() == android.R.id.home) {
|
if (item.getItemId() == android.R.id.home) {
|
||||||
@@ -55,10 +61,4 @@ public class TopicDetailActivity extends FragmentActivity implements OnItemSelec
|
|||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemSelected(Fragment listFragment, String id) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import android.widget.AbsListView;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
|
||||||
public class TopicDetailFragment extends ListFragment {
|
public class TopicDetailFragment extends ListFragment {
|
||||||
|
|
||||||
public static final String ARG_ITEM_ID = "item_id";
|
public static final String ARG_ITEM_ID = "item_id";
|
||||||
@@ -48,10 +47,11 @@ public class TopicDetailFragment extends ListFragment {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
|
* @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(final Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
if (!(activity instanceof OnItemSelectedListener))
|
if (!(activity instanceof OnItemSelectedListener))
|
||||||
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
||||||
@@ -65,16 +65,16 @@ public class TopicDetailFragment extends ListFragment {
|
|||||||
if (getArguments().containsKey(ARG_ITEM_ID))
|
if (getArguments().containsKey(ARG_ITEM_ID))
|
||||||
mItem = TopicContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
|
mItem = TopicContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
|
||||||
|
|
||||||
if(mItem == null)
|
if (mItem == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
|
|
||||||
new Thread( new Runnable(){
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run() {
|
||||||
ThreadContent.getThread((String) mItem.content.get("topic_id"), 0, 0, getActivity());
|
ThreadContent.getThread((String) mItem.content.get("topic_id"), 0, 0, getActivity());
|
||||||
getActivity().runOnUiThread(new Runnable(){
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run() {
|
||||||
setListAdapter(new ThreadAdapter(getActivity()));
|
setListAdapter(new ThreadAdapter(getActivity()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -84,15 +84,16 @@ public class TopicDetailFragment extends ListFragment {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView, android.view.View, int, long)
|
*
|
||||||
|
* @see android.support.v4.app.ListFragment#onListItemClick(android.widget.ListView,
|
||||||
|
* android.view.View, int, long)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
|
||||||
super.onListItemClick(l, v, position, id);
|
super.onListItemClick(l, v, position, id);
|
||||||
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position).id);
|
mCallbacks.onItemSelected(this, TopicContent.ITEMS.get(position).id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(final Bundle outState) {
|
public void onSaveInstanceState(final Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class TopicListActivity extends FragmentActivity implements OnItemSelecte
|
|||||||
((TopicListFragment) getSupportFragmentManager().findFragmentById(R.id.topic_list)).setActivateOnItemClick(true);
|
((TopicListFragment) getSupportFragmentManager().findFragmentById(R.id.topic_list)).setActivateOnItemClick(true);
|
||||||
|
|
||||||
final Bundle arguments = new Bundle();
|
final Bundle arguments = new Bundle();
|
||||||
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, this.getIntent().getExtras().getString(ARG_ITEM_ID));
|
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, getIntent().getExtras().getString(ARG_ITEM_ID));
|
||||||
final TopicDetailFragment fragment = new TopicDetailFragment();
|
final TopicDetailFragment fragment = new TopicDetailFragment();
|
||||||
fragment.setArguments(arguments);
|
fragment.setArguments(arguments);
|
||||||
getSupportFragmentManager().beginTransaction().replace(R.id.topic_detail_container, fragment).commit();
|
getSupportFragmentManager().beginTransaction().replace(R.id.topic_detail_container, fragment).commit();
|
||||||
@@ -54,7 +54,7 @@ public class TopicListActivity extends FragmentActivity implements OnItemSelecte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(final Fragment listFragment, final String id) {
|
public void onItemSelected(final Fragment listFragment, final String id) {
|
||||||
if(listFragment instanceof TopicListFragment)
|
if (listFragment instanceof TopicListFragment)
|
||||||
if (mTwoPane) {
|
if (mTwoPane) {
|
||||||
final Bundle arguments = new Bundle();
|
final Bundle arguments = new Bundle();
|
||||||
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, id);
|
arguments.putString(TopicDetailFragment.ARG_ITEM_ID, id);
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ import android.widget.AbsListView;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
|
||||||
public class TopicListFragment extends ListFragment {
|
public class TopicListFragment extends ListFragment {
|
||||||
|
|
||||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This adapter will be used to populate a list view with forum entries
|
* This adapter will be used to populate a list view with forum entries
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ForumAdapter extends BaseAdapter {
|
public class ForumAdapter extends BaseAdapter {
|
||||||
@@ -40,10 +41,11 @@ public class ForumAdapter extends BaseAdapter {
|
|||||||
TextView description;
|
TextView description;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ForumAdapter
|
* Creates a new ForumAdapter
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public ForumAdapter(final Context context) {
|
public ForumAdapter(final Context context) {
|
||||||
@@ -52,6 +54,7 @@ public class ForumAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getCount()
|
* @see android.widget.Adapter#getCount()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -61,28 +64,32 @@ public class ForumAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getItem(int)
|
* @see android.widget.Adapter#getItem(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public ForumItem getItem(int position) {
|
public ForumItem getItem(final int position) {
|
||||||
return ForumContent.ITEMS.get(position);
|
return ForumContent.ITEMS.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getItemId(int)
|
* @see android.widget.Adapter#getItemId(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(final int position) {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
|
*
|
||||||
|
* @see android.widget.Adapter#getView(int, android.view.View,
|
||||||
|
* android.view.ViewGroup)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, final ViewGroup parent) {
|
||||||
// A ViewHolder keeps references to children views to avoid unnecessary
|
// A ViewHolder keeps references to children views to avoid unnecessary
|
||||||
// calls to findViewById() on each row.
|
// calls to findViewById() on each row.
|
||||||
ViewHolder holder;
|
ViewHolder holder;
|
||||||
@@ -108,7 +115,6 @@ public class ForumAdapter extends BaseAdapter {
|
|||||||
// and the ImageView.
|
// and the ImageView.
|
||||||
holder = (ViewHolder) convertView.getTag();
|
holder = (ViewHolder) convertView.getTag();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bind the data efficiently with the holder. Remember that you should
|
* Bind the data efficiently with the holder. Remember that you should
|
||||||
* always call setChecked() after calling setOnCheckedChangedListener.
|
* always call setChecked() after calling setOnCheckedChangedListener.
|
||||||
|
|||||||
@@ -30,15 +30,16 @@ import org.xmlrpc.android.XMLRPCException;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to maintain an instance of a forum's content data
|
* This class is used to maintain an instance of a forum's content data
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ForumContent {
|
public class ForumContent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Forum Object
|
* This Forum Object
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static class ForumItem {
|
public static class ForumItem {
|
||||||
@@ -49,6 +50,7 @@ public class ForumContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Forum Item
|
* Creates a new Forum Item
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param content
|
* @param content
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -57,17 +59,18 @@ public class ForumContent {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
|
||||||
for(Object key: content.keySet())
|
for (final Object key : content.keySet())
|
||||||
Log.v(TAG, key.toString());
|
Log.v(TAG, key.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This gets all the categories and sub-forums
|
* This gets all the categories and sub-forums
|
||||||
|
*
|
||||||
* @return array of HashMap
|
* @return array of HashMap
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public Object[] getChildren(){
|
public Object[] getChildren() {
|
||||||
return (Object[]) this.content.get("child");
|
return (Object[]) content.get("child");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,6 +88,7 @@ public class ForumContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new Forum Item to the list
|
* Adds a new Forum Item to the list
|
||||||
|
*
|
||||||
* @param item
|
* @param item
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@@ -95,10 +99,11 @@ public class ForumContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads the forum from the Internet
|
* Downloads the forum from the Internet
|
||||||
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void getForum(Context context){
|
public static void getForum(final Context context) {
|
||||||
ITEMS.clear();
|
ITEMS.clear();
|
||||||
ITEM_MAP.clear();
|
ITEM_MAP.clear();
|
||||||
|
|
||||||
@@ -107,15 +112,14 @@ public class ForumContent {
|
|||||||
Object[] result = null;
|
Object[] result = null;
|
||||||
try {
|
try {
|
||||||
result = (Object[]) client.call("get_forum", true);
|
result = (Object[]) client.call("get_forum", true);
|
||||||
} catch (XMLRPCException e) {
|
} catch (final XMLRPCException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result!= null){
|
if (result != null)
|
||||||
for(int i = 0; i < result.length; i++){
|
for (int i = 0; i < result.length; i++) {
|
||||||
HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
final HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
||||||
addItem(new ForumItem(Integer.valueOf(i).toString(), contentHash));
|
addItem(new ForumItem(Integer.valueOf(i).toString(), contentHash));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,13 +23,16 @@ import android.support.v4.app.Fragment;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a simple on item selcted callback for list fragments
|
* This is a simple on item selcted callback for list fragments
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public interface OnItemSelectedListener {
|
public interface OnItemSelectedListener {
|
||||||
/**
|
/**
|
||||||
* Called when a list item from a list fragment is selected
|
* Called when a list item from a list fragment is selected
|
||||||
|
*
|
||||||
* @param listFragment
|
* @param listFragment
|
||||||
* @param id of selected item
|
* @param id
|
||||||
|
* of selected item
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void onItemSelected(final Fragment listFragment, final String id);
|
public void onItemSelected(final Fragment listFragment, final String id);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This adapter will be used to display sub-forums to the user
|
* This adapter will be used to display sub-forums to the user
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class SubForumAdapter extends BaseAdapter {
|
public class SubForumAdapter extends BaseAdapter {
|
||||||
@@ -40,25 +41,26 @@ public class SubForumAdapter extends BaseAdapter {
|
|||||||
TextView title;
|
TextView title;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
private Object[] mSubForums;
|
private final Object[] mSubForums;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public SubForumAdapter(Context context, int position) {
|
public SubForumAdapter(final Context context, final int position) {
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
mSubForums = ForumContent.ITEMS.get(position).getChildren();
|
mSubForums = ForumContent.ITEMS.get(position).getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getCount()
|
* @see android.widget.Adapter#getCount()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
if(mSubForums != null)
|
if (mSubForums != null)
|
||||||
return mSubForums.length;
|
return mSubForums.length;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
@@ -66,28 +68,32 @@ public class SubForumAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getItem(int)
|
* @see android.widget.Adapter#getItem(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HashMap<?,?> getItem(int position) {
|
public HashMap<?, ?> getItem(final int position) {
|
||||||
return (HashMap<?,?>) mSubForums[position];
|
return (HashMap<?, ?>) mSubForums[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getItemId(int)
|
* @see android.widget.Adapter#getItemId(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(final int position) {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
|
*
|
||||||
|
* @see android.widget.Adapter#getView(int, android.view.View,
|
||||||
|
* android.view.ViewGroup)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, final ViewGroup parent) {
|
||||||
// A ViewHolder keeps references to children views to avoid unnecessary
|
// A ViewHolder keeps references to children views to avoid unnecessary
|
||||||
// calls to findViewById() on each row.
|
// calls to findViewById() on each row.
|
||||||
ViewHolder holder;
|
ViewHolder holder;
|
||||||
@@ -112,7 +118,6 @@ public class SubForumAdapter extends BaseAdapter {
|
|||||||
// and the ImageView.
|
// and the ImageView.
|
||||||
holder = (ViewHolder) convertView.getTag();
|
holder = (ViewHolder) convertView.getTag();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bind the data efficiently with the holder. Remember that you should
|
* Bind the data efficiently with the holder. Remember that you should
|
||||||
* always call setChecked() after calling setOnCheckedChangedListener.
|
* always call setChecked() after calling setOnCheckedChangedListener.
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This adapter will be used to populte a list view with post from a thread
|
* This adapter will be used to populte a list view with post from a thread
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ThreadAdapter extends BaseAdapter {
|
public class ThreadAdapter extends BaseAdapter {
|
||||||
@@ -44,13 +45,14 @@ public class ThreadAdapter extends BaseAdapter {
|
|||||||
QuickContactBadge badage;
|
QuickContactBadge badage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new ThreadAdapter
|
* Creates a new ThreadAdapter
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public ThreadAdapter(Context context) {
|
public ThreadAdapter(final Context context) {
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +72,8 @@ public class ThreadAdapter extends BaseAdapter {
|
|||||||
* @see android.widget.Adapter#getItem(int)
|
* @see android.widget.Adapter#getItem(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HashMap<?, ?> getItem(int position) {
|
public HashMap<?, ?> getItem(final int position) {
|
||||||
return (HashMap<?, ?>) ThreadContent.ITEMS.get(position).content;
|
return ThreadContent.ITEMS.get(position).content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -80,7 +82,7 @@ public class ThreadAdapter extends BaseAdapter {
|
|||||||
* @see android.widget.Adapter#getItemId(int)
|
* @see android.widget.Adapter#getItemId(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(final int position) {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ public class ThreadAdapter extends BaseAdapter {
|
|||||||
* android.view.ViewGroup)
|
* android.view.ViewGroup)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, final ViewGroup parent) {
|
||||||
// A ViewHolder keeps references to children views to avoid unnecessary
|
// A ViewHolder keeps references to children views to avoid unnecessary
|
||||||
// calls to findViewById() on each row.
|
// calls to findViewById() on each row.
|
||||||
ViewHolder holder;
|
ViewHolder holder;
|
||||||
|
|||||||
@@ -30,15 +30,16 @@ import org.xmlrpc.android.XMLRPCException;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to maintain an instance of a thread's data content
|
* This class is used to maintain an instance of a thread's data content
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class ThreadContent {
|
public class ThreadContent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Forum Object
|
* This Forum Object
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static class ThreadItem {
|
public static class ThreadItem {
|
||||||
@@ -48,6 +49,7 @@ public class ThreadContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Topic Item
|
* Creates a new Topic Item
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param content
|
* @param content
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -56,7 +58,7 @@ public class ThreadContent {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
|
||||||
for(Object key: content.keySet())
|
for (final Object key : content.keySet())
|
||||||
Log.v(TAG, key.toString());
|
Log.v(TAG, key.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,6 +68,7 @@ public class ThreadContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new Forum Item to the list
|
* Adds a new Forum Item to the list
|
||||||
|
*
|
||||||
* @param item
|
* @param item
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@@ -76,13 +79,14 @@ public class ThreadContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This downloads a thread for a specific topic
|
* This downloads a thread for a specific topic
|
||||||
|
*
|
||||||
* @param topicId
|
* @param topicId
|
||||||
* @param startNumber
|
* @param startNumber
|
||||||
* @param lastNumber
|
* @param lastNumber
|
||||||
* @param context
|
* @param context
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void getThread(String topicId, int startNumber, int lastNumber, final Context context){
|
public static void getThread(final String topicId, final int startNumber, final int lastNumber, final Context context) {
|
||||||
final XMLRPCClient client = XMLRPCClient.getClient(context);
|
final XMLRPCClient client = XMLRPCClient.getClient(context);
|
||||||
|
|
||||||
ITEMS.clear();
|
ITEMS.clear();
|
||||||
@@ -90,17 +94,16 @@ public class ThreadContent {
|
|||||||
|
|
||||||
Object[] result = null;
|
Object[] result = null;
|
||||||
try {
|
try {
|
||||||
result = (Object[]) ((HashMap<?,?>) client.call("get_thread", topicId, startNumber, lastNumber)).get("posts");
|
result = (Object[]) ((HashMap<?, ?>) client.call("get_thread", topicId, startNumber, lastNumber)).get("posts");
|
||||||
} catch (XMLRPCException e) {
|
} catch (final XMLRPCException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result!= null){
|
if (result != null)
|
||||||
for(int i = 0; i < result.length; i++){
|
for (int i = 0; i < result.length; i++) {
|
||||||
HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
final HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
||||||
addItem(new ThreadItem(Integer.valueOf(i).toString(), contentHash));
|
addItem(new ThreadItem(Integer.valueOf(i).toString(), contentHash));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This adapter will be used to display topics to the user
|
* This adapter will be used to display topics to the user
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class TopicAdapter extends BaseAdapter {
|
public class TopicAdapter extends BaseAdapter {
|
||||||
@@ -45,7 +46,7 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
QuickContactBadge badage;
|
QuickContactBadge badage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -57,6 +58,7 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getCount()
|
* @see android.widget.Adapter#getCount()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -66,28 +68,32 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getItem(int)
|
* @see android.widget.Adapter#getItem(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HashMap<?,?> getItem(int position) {
|
public HashMap<?, ?> getItem(final int position) {
|
||||||
return (HashMap<?,?>) TopicContent.ITEMS.get(position).content;
|
return TopicContent.ITEMS.get(position).content;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see android.widget.Adapter#getItemId(int)
|
* @see android.widget.Adapter#getItemId(int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(final int position) {
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
|
*
|
||||||
|
* @see android.widget.Adapter#getView(int, android.view.View,
|
||||||
|
* android.view.ViewGroup)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, final ViewGroup parent) {
|
||||||
// A ViewHolder keeps references to children views to avoid unnecessary
|
// A ViewHolder keeps references to children views to avoid unnecessary
|
||||||
// calls to findViewById() on each row.
|
// calls to findViewById() on each row.
|
||||||
ViewHolder holder;
|
ViewHolder holder;
|
||||||
@@ -116,7 +122,6 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
// and the ImageView.
|
// and the ImageView.
|
||||||
holder = (ViewHolder) convertView.getTag();
|
holder = (ViewHolder) convertView.getTag();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Bind the data efficiently with the holder. Remember that you should
|
* Bind the data efficiently with the holder. Remember that you should
|
||||||
* always call setChecked() after calling setOnCheckedChangedListener.
|
* always call setChecked() after calling setOnCheckedChangedListener.
|
||||||
@@ -125,7 +130,7 @@ public class TopicAdapter extends BaseAdapter {
|
|||||||
holder.title.setText(new String((byte[]) getItem(position).get("topic_title")));
|
holder.title.setText(new String((byte[]) getItem(position).get("topic_title")));
|
||||||
holder.user.setText(new String((byte[]) getItem(position).get("topic_author_name")));
|
holder.user.setText(new String((byte[]) getItem(position).get("topic_author_name")));
|
||||||
holder.lastestPost.setText(new String((byte[]) getItem(position).get("short_content")));
|
holder.lastestPost.setText(new String((byte[]) getItem(position).get("short_content")));
|
||||||
holder.newPosts.setVisibility(((Boolean) getItem(position).get("new_post") ? View.VISIBLE : View.GONE));
|
holder.newPosts.setVisibility((Boolean) getItem(position).get("new_post") ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,15 +30,16 @@ import org.xmlrpc.android.XMLRPCException;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is used to maintain an instance of a topic's content data
|
* This class is used to maintain an instance of a topic's content data
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public class TopicContent {
|
public class TopicContent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This Forum Object
|
* This Forum Object
|
||||||
|
*
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static class TopicItem {
|
public static class TopicItem {
|
||||||
@@ -48,6 +49,7 @@ public class TopicContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Topic Item
|
* Creates a new Topic Item
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @param content
|
* @param content
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -56,7 +58,7 @@ public class TopicContent {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
this.content = content;
|
this.content = content;
|
||||||
|
|
||||||
for(Object key: content.keySet())
|
for (final Object key : content.keySet())
|
||||||
Log.v(TAG, key.toString());
|
Log.v(TAG, key.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,6 +68,7 @@ public class TopicContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new Forum Item to the list
|
* Adds a new Forum Item to the list
|
||||||
|
*
|
||||||
* @param item
|
* @param item
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@@ -76,11 +79,12 @@ public class TopicContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This gets all the topics for the current forum item
|
* This gets all the topics for the current forum item
|
||||||
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @return
|
* @return
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public static void getTopics(String forumId, final Context context){
|
public static void getTopics(final String forumId, final Context context) {
|
||||||
final XMLRPCClient client = XMLRPCClient.getClient(context);
|
final XMLRPCClient client = XMLRPCClient.getClient(context);
|
||||||
|
|
||||||
ITEMS.clear();
|
ITEMS.clear();
|
||||||
@@ -88,16 +92,15 @@ public class TopicContent {
|
|||||||
|
|
||||||
Object[] result = null;
|
Object[] result = null;
|
||||||
try {
|
try {
|
||||||
result = (Object[]) ((HashMap<?,?>) client.call("get_topic", forumId, 0, 0)).get("topics");
|
result = (Object[]) ((HashMap<?, ?>) client.call("get_topic", forumId, 0, 0)).get("topics");
|
||||||
} catch (XMLRPCException e) {
|
} catch (final XMLRPCException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result!= null){
|
if (result != null)
|
||||||
for(int i = 0; i < result.length; i++){
|
for (int i = 0; i < result.length; i++) {
|
||||||
HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
final HashMap<?, ?> contentHash = (HashMap<?, ?>) result[i];
|
||||||
addItem(new TopicItem(Integer.valueOf(i).toString(), contentHash));
|
addItem(new TopicItem(Integer.valueOf(i).toString(), contentHash));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,15 +31,12 @@ class Base64Coder {
|
|||||||
private static char[] map1 = new char[64];
|
private static char[] map1 = new char[64];
|
||||||
static {
|
static {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (char c = 'A'; c <= 'Z'; c++) {
|
for (char c = 'A'; c <= 'Z'; c++)
|
||||||
map1[i++] = c;
|
map1[i++] = c;
|
||||||
}
|
for (char c = 'a'; c <= 'z'; c++)
|
||||||
for (char c = 'a'; c <= 'z'; c++) {
|
|
||||||
map1[i++] = c;
|
map1[i++] = c;
|
||||||
}
|
for (char c = '0'; c <= '9'; c++)
|
||||||
for (char c = '0'; c <= '9'; c++) {
|
|
||||||
map1[i++] = c;
|
map1[i++] = c;
|
||||||
}
|
|
||||||
map1[i++] = '+';
|
map1[i++] = '+';
|
||||||
map1[i++] = '/';
|
map1[i++] = '/';
|
||||||
}
|
}
|
||||||
@@ -47,24 +44,81 @@ class Base64Coder {
|
|||||||
// Mapping table from Base64 characters to 6-bit nibbles.
|
// Mapping table from Base64 characters to 6-bit nibbles.
|
||||||
private static byte[] map2 = new byte[128];
|
private static byte[] map2 = new byte[128];
|
||||||
static {
|
static {
|
||||||
for (int i = 0; i < map2.length; i++) {
|
for (int i = 0; i < map2.length; i++)
|
||||||
map2[i] = -1;
|
map2[i] = -1;
|
||||||
}
|
for (int i = 0; i < 64; i++)
|
||||||
for (int i = 0; i < 64; i++) {
|
|
||||||
map2[map1[i]] = (byte) i;
|
map2[map1[i]] = (byte) i;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes a string into Base64 format. No blanks or line breaks are
|
* Decodes a byte array from Base64 format. No blanks or line breaks are
|
||||||
* inserted.
|
* allowed within the Base64 encoded data.
|
||||||
|
*
|
||||||
|
* @param in
|
||||||
|
* a character array containing the Base64 encoded data.
|
||||||
|
* @return An array containing the decoded data bytes.
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* if the input is not valid Base64 encoded data.
|
||||||
|
*/
|
||||||
|
static byte[] decode(final char[] in) {
|
||||||
|
int iLen = in.length;
|
||||||
|
if (iLen % 4 != 0)
|
||||||
|
throw new IllegalArgumentException("Length of Base64 encoded input string is not a multiple of 4.");
|
||||||
|
while (iLen > 0 && in[iLen - 1] == '=')
|
||||||
|
iLen--;
|
||||||
|
final int oLen = iLen * 3 / 4;
|
||||||
|
final byte[] out = new byte[oLen];
|
||||||
|
int ip = 0;
|
||||||
|
int op = 0;
|
||||||
|
while (ip < iLen) {
|
||||||
|
final int i0 = in[ip++];
|
||||||
|
final int i1 = in[ip++];
|
||||||
|
final int i2 = ip < iLen ? in[ip++] : 'A';
|
||||||
|
final int i3 = ip < iLen ? in[ip++] : 'A';
|
||||||
|
if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127)
|
||||||
|
throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
|
||||||
|
final int b0 = map2[i0];
|
||||||
|
final int b1 = map2[i1];
|
||||||
|
final int b2 = map2[i2];
|
||||||
|
final int b3 = map2[i3];
|
||||||
|
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0)
|
||||||
|
throw new IllegalArgumentException("Illegal character in Base64 encoded data.");
|
||||||
|
final int o0 = b0 << 2 | b1 >>> 4;
|
||||||
|
final int o1 = (b1 & 0xf) << 4 | b2 >>> 2;
|
||||||
|
final int o2 = (b2 & 3) << 6 | b3;
|
||||||
|
out[op++] = (byte) o0;
|
||||||
|
if (op < oLen)
|
||||||
|
out[op++] = (byte) o1;
|
||||||
|
if (op < oLen)
|
||||||
|
out[op++] = (byte) o2;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a byte array from Base64 format.
|
||||||
*
|
*
|
||||||
* @param s
|
* @param s
|
||||||
* a String to be encoded.
|
* a Base64 String to be decoded.
|
||||||
* @return A String with the Base64 encoded data.
|
* @return An array containing the decoded data bytes.
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* if the input is not valid Base64 encoded data.
|
||||||
*/
|
*/
|
||||||
static String encodeString(String s) {
|
static byte[] decode(final String s) {
|
||||||
return new String(encode(s.getBytes()));
|
return decode(s.toCharArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decodes a string from Base64 format.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* a Base64 String to be decoded.
|
||||||
|
* @return A String containing the decoded data.
|
||||||
|
* @throws IllegalArgumentException
|
||||||
|
* if the input is not valid Base64 encoded data.
|
||||||
|
*/
|
||||||
|
static String decodeString(final String s) {
|
||||||
|
return new String(decode(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,7 +129,7 @@ class Base64Coder {
|
|||||||
* an array containing the data bytes to be encoded.
|
* an array containing the data bytes to be encoded.
|
||||||
* @return A character array with the Base64 encoded data.
|
* @return A character array with the Base64 encoded data.
|
||||||
*/
|
*/
|
||||||
static char[] encode(byte[] in) {
|
static char[] encode(final byte[] in) {
|
||||||
return encode(in, in.length);
|
return encode(in, in.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,20 +143,21 @@ class Base64Coder {
|
|||||||
* number of bytes to process in <code>in</code>.
|
* number of bytes to process in <code>in</code>.
|
||||||
* @return A character array with the Base64 encoded data.
|
* @return A character array with the Base64 encoded data.
|
||||||
*/
|
*/
|
||||||
static char[] encode(byte[] in, int iLen) {
|
static char[] encode(final byte[] in, final int iLen) {
|
||||||
int oDataLen = (iLen * 4 + 2) / 3; // output length without padding
|
final int oDataLen = (iLen * 4 + 2) / 3; // output length without
|
||||||
int oLen = ((iLen + 2) / 3) * 4; // output length including padding
|
// padding
|
||||||
char[] out = new char[oLen];
|
final int oLen = (iLen + 2) / 3 * 4; // output length including padding
|
||||||
|
final char[] out = new char[oLen];
|
||||||
int ip = 0;
|
int ip = 0;
|
||||||
int op = 0;
|
int op = 0;
|
||||||
while (ip < iLen) {
|
while (ip < iLen) {
|
||||||
int i0 = in[ip++] & 0xff;
|
final int i0 = in[ip++] & 0xff;
|
||||||
int i1 = ip < iLen ? in[ip++] & 0xff : 0;
|
final int i1 = ip < iLen ? in[ip++] & 0xff : 0;
|
||||||
int i2 = ip < iLen ? in[ip++] & 0xff : 0;
|
final int i2 = ip < iLen ? in[ip++] & 0xff : 0;
|
||||||
int o0 = i0 >>> 2;
|
final int o0 = i0 >>> 2;
|
||||||
int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
|
final int o1 = (i0 & 3) << 4 | i1 >>> 4;
|
||||||
int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
|
final int o2 = (i1 & 0xf) << 2 | i2 >>> 6;
|
||||||
int o3 = i2 & 0x3F;
|
final int o3 = i2 & 0x3F;
|
||||||
out[op++] = map1[o0];
|
out[op++] = map1[o0];
|
||||||
out[op++] = map1[o1];
|
out[op++] = map1[o1];
|
||||||
out[op] = op < oDataLen ? map1[o2] : '=';
|
out[op] = op < oDataLen ? map1[o2] : '=';
|
||||||
@@ -114,83 +169,15 @@ class Base64Coder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes a string from Base64 format.
|
* Encodes a string into Base64 format. No blanks or line breaks are
|
||||||
|
* inserted.
|
||||||
*
|
*
|
||||||
* @param s
|
* @param s
|
||||||
* a Base64 String to be decoded.
|
* a String to be encoded.
|
||||||
* @return A String containing the decoded data.
|
* @return A String with the Base64 encoded data.
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the input is not valid Base64 encoded data.
|
|
||||||
*/
|
*/
|
||||||
static String decodeString(String s) {
|
static String encodeString(final String s) {
|
||||||
return new String(decode(s));
|
return new String(encode(s.getBytes()));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decodes a byte array from Base64 format.
|
|
||||||
*
|
|
||||||
* @param s
|
|
||||||
* a Base64 String to be decoded.
|
|
||||||
* @return An array containing the decoded data bytes.
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the input is not valid Base64 encoded data.
|
|
||||||
*/
|
|
||||||
static byte[] decode(String s) {
|
|
||||||
return decode(s.toCharArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decodes a byte array from Base64 format. No blanks or line breaks are
|
|
||||||
* allowed within the Base64 encoded data.
|
|
||||||
*
|
|
||||||
* @param in
|
|
||||||
* a character array containing the Base64 encoded data.
|
|
||||||
* @return An array containing the decoded data bytes.
|
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the input is not valid Base64 encoded data.
|
|
||||||
*/
|
|
||||||
static byte[] decode(char[] in) {
|
|
||||||
int iLen = in.length;
|
|
||||||
if (iLen % 4 != 0) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Length of Base64 encoded input string is not a multiple of 4.");
|
|
||||||
}
|
|
||||||
while (iLen > 0 && in[iLen - 1] == '=') {
|
|
||||||
iLen--;
|
|
||||||
}
|
|
||||||
int oLen = (iLen * 3) / 4;
|
|
||||||
byte[] out = new byte[oLen];
|
|
||||||
int ip = 0;
|
|
||||||
int op = 0;
|
|
||||||
while (ip < iLen) {
|
|
||||||
int i0 = in[ip++];
|
|
||||||
int i1 = in[ip++];
|
|
||||||
int i2 = ip < iLen ? in[ip++] : 'A';
|
|
||||||
int i3 = ip < iLen ? in[ip++] : 'A';
|
|
||||||
if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Illegal character in Base64 encoded data.");
|
|
||||||
}
|
|
||||||
int b0 = map2[i0];
|
|
||||||
int b1 = map2[i1];
|
|
||||||
int b2 = map2[i2];
|
|
||||||
int b3 = map2[i3];
|
|
||||||
if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Illegal character in Base64 encoded data.");
|
|
||||||
}
|
|
||||||
int o0 = (b0 << 2) | (b1 >>> 4);
|
|
||||||
int o1 = ((b1 & 0xf) << 4) | (b2 >>> 2);
|
|
||||||
int o2 = ((b2 & 3) << 6) | b3;
|
|
||||||
out[op++] = (byte) o0;
|
|
||||||
if (op < oLen) {
|
|
||||||
out[op++] = (byte) o1;
|
|
||||||
}
|
|
||||||
if (op < oLen) {
|
|
||||||
out[op++] = (byte) o2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dummy constructor.
|
// Dummy constructor.
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public interface IXMLRPCSerializer {
|
|||||||
|
|
||||||
String DATETIME_FORMAT = "yyyyMMdd'T'HH:mm:ss";
|
String DATETIME_FORMAT = "yyyyMMdd'T'HH:mm:ss";
|
||||||
|
|
||||||
void serialize(XmlSerializer serializer, Object object) throws IOException;
|
|
||||||
Object deserialize(XmlPullParser parser) throws XmlPullParserException, IOException;
|
Object deserialize(XmlPullParser parser) throws XmlPullParserException, IOException;
|
||||||
|
|
||||||
|
void serialize(XmlSerializer serializer, Object object) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,13 +8,23 @@ public class MethodCall {
|
|||||||
String methodName;
|
String methodName;
|
||||||
ArrayList<Object> params = new ArrayList<Object>();
|
ArrayList<Object> params = new ArrayList<Object>();
|
||||||
|
|
||||||
public String getMethodName() { return methodName; }
|
public String getMethodName() {
|
||||||
void setMethodName(String methodName) { this.methodName = methodName; }
|
return methodName;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<Object> getParams() { return params; }
|
public ArrayList<Object> getParams() {
|
||||||
void setParams(ArrayList<Object> params) { this.params = params; }
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTopic() {
|
public String getTopic() {
|
||||||
return (String)params.get(TOPIC);
|
return (String) params.get(TOPIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMethodName(final String methodName) {
|
||||||
|
this.methodName = methodName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setParams(final ArrayList<Object> params) {
|
||||||
|
this.params = params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,66 +37,180 @@ import android.content.Context;
|
|||||||
* XMLRPCClient allows to call remote XMLRPC method.
|
* XMLRPCClient allows to call remote XMLRPC method.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* The following table shows how XML-RPC types are mapped to java call parameters/response values.
|
* The following table shows how XML-RPC types are mapped to java call
|
||||||
|
* parameters/response values.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <table border="2" align="center" cellpadding="5">
|
* <table border="2" align="center" cellpadding="5">
|
||||||
* <thead><tr><th>XML-RPC Type</th><th>Call Parameters</th><th>Call Response</th></tr></thead>
|
* <thead>
|
||||||
|
* <tr>
|
||||||
|
* <th>XML-RPC Type</th>
|
||||||
|
* <th>Call Parameters</th>
|
||||||
|
* <th>Call Response</th>
|
||||||
|
* </tr>
|
||||||
|
* </thead>
|
||||||
*
|
*
|
||||||
* <tbody>
|
* <tbody>
|
||||||
* <td>int, i4</td><td>byte<br />Byte<br />short<br />Short<br />int<br />Integer</td><td>int<br />Integer</td>
|
* <td>int, i4</td>
|
||||||
|
* <td>byte<br />
|
||||||
|
* Byte<br />
|
||||||
|
* short<br />
|
||||||
|
* Short<br />
|
||||||
|
* int<br />
|
||||||
|
* Integer</td>
|
||||||
|
* <td>int<br />
|
||||||
|
* Integer</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>i8</td><td>long<br />Long</td><td>long<br />Long</td>
|
* <td>i8</td>
|
||||||
|
* <td>long<br />
|
||||||
|
* Long</td>
|
||||||
|
* <td>long<br />
|
||||||
|
* Long</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>double</td><td>float<br />Float<br />double<br />Double</td><td>double<br />Double</td>
|
* <td>double</td>
|
||||||
|
* <td>float<br />
|
||||||
|
* Float<br />
|
||||||
|
* double<br />
|
||||||
|
* Double</td>
|
||||||
|
* <td>double<br />
|
||||||
|
* Double</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>string</td><td>String</td><td>String</td>
|
* <td>string</td>
|
||||||
|
* <td>String</td>
|
||||||
|
* <td>String</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>boolean</td><td>boolean<br />Boolean</td><td>boolean<br />Boolean</td>
|
* <td>boolean</td>
|
||||||
|
* <td>boolean<br />
|
||||||
|
* Boolean</td>
|
||||||
|
* <td>boolean<br />
|
||||||
|
* Boolean</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>dateTime.iso8601</td><td>java.util.Date<br />java.util.Calendar</td><td>java.util.Date</td>
|
* <td>dateTime.iso8601</td>
|
||||||
|
* <td>java.util.Date<br />
|
||||||
|
* java.util.Calendar</td>
|
||||||
|
* <td>java.util.Date</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>base64</td><td>byte[]</td><td>byte[]</td>
|
* <td>base64</td>
|
||||||
|
* <td>byte[]</td>
|
||||||
|
* <td>byte[]</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>array</td><td>java.util.List<Object><br />Object[]</td><td>Object[]</td>
|
* <td>array</td>
|
||||||
|
* <td>java.util.List<Object><br />
|
||||||
|
* Object[]</td>
|
||||||
|
* <td>Object[]</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
* <td>struct</td><td>java.util.Map<String, Object></td><td>java.util.Map<String, Object></td>
|
* <td>struct</td>
|
||||||
|
* <td>java.util.Map<String, Object></td>
|
||||||
|
* <td>java.util.Map<String, Object></td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* </tbody>
|
* </tbody>
|
||||||
* </table>
|
* </table>
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* You can also pass as a parameter any object implementing XMLRPCSerializable interface. In this
|
* You can also pass as a parameter any object implementing XMLRPCSerializable
|
||||||
* case your object overrides getSerializable() telling how to serialize to XMLRPC protocol
|
* interface. In this case your object overrides getSerializable() telling how
|
||||||
|
* to serialize to XMLRPC protocol
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class XMLRPCClient extends XMLRPCCommon {
|
public class XMLRPCClient extends XMLRPCCommon {
|
||||||
private HttpClient client;
|
/**
|
||||||
private HttpPost postMethod;
|
* Creates an XML RPC Client
|
||||||
private HttpParams httpParams;
|
*
|
||||||
|
* @param Context
|
||||||
|
* @return XMLRPCClient
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static XMLRPCClient getClient(final Context context) {
|
||||||
|
if (Constraints.TESTING)
|
||||||
|
return new XMLRPCClient(context.getString(R.string.test_server), context.getString(R.string.test_username), context.getString(R.string.test_password));
|
||||||
|
else
|
||||||
|
return new XMLRPCClient(context.getString(R.string.osj_server), context.getString(R.string.test_username), context.getString(R.string.test_password));
|
||||||
|
}
|
||||||
|
|
||||||
|
private final HttpClient client;
|
||||||
|
private final HttpPost postMethod;
|
||||||
|
private final HttpParams httpParams;
|
||||||
// These variables used in the code inspired by erickok in issue #6
|
// These variables used in the code inspired by erickok in issue #6
|
||||||
private boolean httpPreAuth = false;
|
private boolean httpPreAuth = false;
|
||||||
private String username = "";
|
private String username = "";
|
||||||
|
|
||||||
private String password = "";
|
private String password = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XMLRPCClient constructor. Creates new instance based on server URI
|
* Convenience constructor. Creates new instance based on server String
|
||||||
* (Code contributed by sgayda2 from issue #17, and by erickok from ticket #10)
|
* address
|
||||||
*
|
*
|
||||||
* @param XMLRPC server URI
|
* @param XMLRPC
|
||||||
|
* server address
|
||||||
*/
|
*/
|
||||||
public XMLRPCClient(URI uri) {
|
public XMLRPCClient(final String url) {
|
||||||
SchemeRegistry registry = new SchemeRegistry();
|
this(URI.create(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience constructor. Creates new instance based on server String
|
||||||
|
* address
|
||||||
|
*
|
||||||
|
* @param XMLRPC
|
||||||
|
* server address
|
||||||
|
* @param HttpClient
|
||||||
|
* to use
|
||||||
|
*/
|
||||||
|
public XMLRPCClient(final String url, final HttpClient client) {
|
||||||
|
this(URI.create(url), client);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience constructor. Creates new instance based on server String
|
||||||
|
* address
|
||||||
|
*
|
||||||
|
* @param XMLRPC
|
||||||
|
* server address
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Username
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Password
|
||||||
|
*/
|
||||||
|
public XMLRPCClient(final String url, final String username, final String password) {
|
||||||
|
this(URI.create(url), username, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience constructor. Creates new instance based on server String
|
||||||
|
* address
|
||||||
|
*
|
||||||
|
* @param XMLRPC
|
||||||
|
* server address
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Username
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Password
|
||||||
|
* @param HttpClient
|
||||||
|
* to use
|
||||||
|
*/
|
||||||
|
public XMLRPCClient(final String url, final String username, final String password, final HttpClient client) {
|
||||||
|
this(URI.create(url), username, password, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XMLRPCClient constructor. Creates new instance based on server URI (Code
|
||||||
|
* contributed by sgayda2 from issue #17, and by erickok from ticket #10)
|
||||||
|
*
|
||||||
|
* @param XMLRPC
|
||||||
|
* server URI
|
||||||
|
*/
|
||||||
|
public XMLRPCClient(final URI uri) {
|
||||||
|
final SchemeRegistry registry = new SchemeRegistry();
|
||||||
registry.register(new Scheme("http", new PlainSocketFactory(), 80));
|
registry.register(new Scheme("http", new PlainSocketFactory(), 80));
|
||||||
registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
|
||||||
|
|
||||||
@@ -108,18 +222,20 @@ public class XMLRPCClient extends XMLRPCCommon {
|
|||||||
// two second delay between sending http POST request and POST body
|
// two second delay between sending http POST request and POST body
|
||||||
httpParams = postMethod.getParams();
|
httpParams = postMethod.getParams();
|
||||||
HttpProtocolParams.setUseExpectContinue(httpParams, false);
|
HttpProtocolParams.setUseExpectContinue(httpParams, false);
|
||||||
this.client = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, registry), httpParams);
|
client = new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, registry), httpParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XMLRPCClient constructor. Creates new instance based on server URI
|
* XMLRPCClient constructor. Creates new instance based on server URI (Code
|
||||||
* (Code contributed by sgayda2 from issue #17)
|
* contributed by sgayda2 from issue #17)
|
||||||
*
|
*
|
||||||
* @param XMLRPC server URI
|
* @param XMLRPC
|
||||||
* @param HttpClient to use
|
* server URI
|
||||||
|
* @param HttpClient
|
||||||
|
* to use
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public XMLRPCClient(URI uri, HttpClient client) {
|
public XMLRPCClient(final URI uri, final HttpClient client) {
|
||||||
postMethod = new HttpPost(uri);
|
postMethod = new HttpPost(uri);
|
||||||
postMethod.addHeader("Content-Type", "text/xml");
|
postMethod.addHeader("Content-Type", "text/xml");
|
||||||
|
|
||||||
@@ -132,163 +248,164 @@ public class XMLRPCClient extends XMLRPCCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Amends user agent
|
* Convenience constructor. Creates new instance based on server String
|
||||||
* (Code contributed by mortenholdflod from issue #28)
|
* address
|
||||||
*
|
*
|
||||||
* @param userAgent defining the new User Agent string
|
* @param XMLRPC
|
||||||
|
* server address
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Username
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Password
|
||||||
*/
|
*/
|
||||||
public void setUserAgent(String userAgent) {
|
public XMLRPCClient(final URI uri, final String username, final String password) {
|
||||||
postMethod.removeHeaders("User-Agent");
|
this(uri);
|
||||||
postMethod.addHeader("User-Agent", userAgent);
|
|
||||||
|
((DefaultHttpClient) client).getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM),
|
||||||
|
new UsernamePasswordCredentials(username, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience constructor. Creates new instance based on server String address
|
* Convenience constructor. Creates new instance based on server String
|
||||||
* @param XMLRPC server address
|
* address
|
||||||
|
*
|
||||||
|
* @param XMLRPC
|
||||||
|
* server address
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Username
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Password
|
||||||
|
* @param HttpClient
|
||||||
|
* to use
|
||||||
*/
|
*/
|
||||||
public XMLRPCClient(String url) {
|
public XMLRPCClient(final URI uri, final String username, final String password, final HttpClient client) {
|
||||||
this(URI.create(url));
|
this(uri, client);
|
||||||
|
|
||||||
|
((DefaultHttpClient) this.client).getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM),
|
||||||
|
new UsernamePasswordCredentials(username, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience constructor. Creates new instance based on server String address
|
* Convenience XMLRPCClient constructor. Creates new instance based on
|
||||||
* @param XMLRPC server address
|
* server URL
|
||||||
* @param HttpClient to use
|
*
|
||||||
|
* @param XMLRPC
|
||||||
|
* server URL
|
||||||
*/
|
*/
|
||||||
public XMLRPCClient(String url, HttpClient client) {
|
public XMLRPCClient(final URL url) {
|
||||||
this(URI.create(url), client);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience XMLRPCClient constructor. Creates new instance based on server URL
|
|
||||||
* @param XMLRPC server URL
|
|
||||||
*/
|
|
||||||
public XMLRPCClient(URL url) {
|
|
||||||
this(URI.create(url.toExternalForm()));
|
this(URI.create(url.toExternalForm()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience XMLRPCClient constructor. Creates new instance based on server URL
|
* Convenience XMLRPCClient constructor. Creates new instance based on
|
||||||
* @param XMLRPC server URL
|
* server URL
|
||||||
* @param HttpClient to use
|
*
|
||||||
|
* @param XMLRPC
|
||||||
|
* server URL
|
||||||
|
* @param HttpClient
|
||||||
|
* to use
|
||||||
*/
|
*/
|
||||||
public XMLRPCClient(URL url, HttpClient client) {
|
public XMLRPCClient(final URL url, final HttpClient client) {
|
||||||
this(URI.create(url.toExternalForm()), client);
|
this(URI.create(url.toExternalForm()), client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience constructor. Creates new instance based on server String address
|
* Convenience constructor. Creates new instance based on server String
|
||||||
* @param XMLRPC server address
|
* address
|
||||||
* @param HTTP Server - Basic Authentication - Username
|
*
|
||||||
* @param HTTP Server - Basic Authentication - Password
|
* @param XMLRPC
|
||||||
|
* server url
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Username
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Password
|
||||||
*/
|
*/
|
||||||
public XMLRPCClient(URI uri, String username, String password) {
|
public XMLRPCClient(final URL url, final String username, final String password) {
|
||||||
this(uri);
|
|
||||||
|
|
||||||
((DefaultHttpClient) client).getCredentialsProvider().setCredentials(
|
|
||||||
new AuthScope(uri.getHost(), uri.getPort(),AuthScope.ANY_REALM),
|
|
||||||
new UsernamePasswordCredentials(username, password));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience constructor. Creates new instance based on server String address
|
|
||||||
* @param XMLRPC server address
|
|
||||||
* @param HTTP Server - Basic Authentication - Username
|
|
||||||
* @param HTTP Server - Basic Authentication - Password
|
|
||||||
* @param HttpClient to use
|
|
||||||
*/
|
|
||||||
public XMLRPCClient(URI uri, String username, String password, HttpClient client) {
|
|
||||||
this(uri, client);
|
|
||||||
|
|
||||||
((DefaultHttpClient) this.client).getCredentialsProvider().setCredentials(
|
|
||||||
new AuthScope(uri.getHost(), uri.getPort(),AuthScope.ANY_REALM),
|
|
||||||
new UsernamePasswordCredentials(username, password));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience constructor. Creates new instance based on server String address
|
|
||||||
* @param XMLRPC server address
|
|
||||||
* @param HTTP Server - Basic Authentication - Username
|
|
||||||
* @param HTTP Server - Basic Authentication - Password
|
|
||||||
*/
|
|
||||||
public XMLRPCClient(String url, String username, String password) {
|
|
||||||
this(URI.create(url), username, password);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience constructor. Creates new instance based on server String address
|
|
||||||
* @param XMLRPC server address
|
|
||||||
* @param HTTP Server - Basic Authentication - Username
|
|
||||||
* @param HTTP Server - Basic Authentication - Password
|
|
||||||
* @param HttpClient to use
|
|
||||||
*/
|
|
||||||
public XMLRPCClient(String url, String username, String password, HttpClient client) {
|
|
||||||
this(URI.create(url), username, password, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience constructor. Creates new instance based on server String address
|
|
||||||
* @param XMLRPC server url
|
|
||||||
* @param HTTP Server - Basic Authentication - Username
|
|
||||||
* @param HTTP Server - Basic Authentication - Password
|
|
||||||
*/
|
|
||||||
public XMLRPCClient(URL url, String username, String password) {
|
|
||||||
this(URI.create(url.toExternalForm()), username, password);
|
this(URI.create(url.toExternalForm()), username, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience constructor. Creates new instance based on server String address
|
* Convenience constructor. Creates new instance based on server String
|
||||||
* @param XMLRPC server url
|
* address
|
||||||
* @param HTTP Server - Basic Authentication - Username
|
*
|
||||||
* @param HTTP Server - Basic Authentication - Password
|
* @param XMLRPC
|
||||||
* @param HttpClient to use
|
* server url
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Username
|
||||||
|
* @param HTTP
|
||||||
|
* Server - Basic Authentication - Password
|
||||||
|
* @param HttpClient
|
||||||
|
* to use
|
||||||
*/
|
*/
|
||||||
public XMLRPCClient(URL url, String username, String password, HttpClient client) {
|
public XMLRPCClient(final URL url, final String username, final String password, final HttpClient client) {
|
||||||
this(URI.create(url.toExternalForm()), username, password, client);
|
this(URI.create(url.toExternalForm()), username, password, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets basic authentication on web request using plain credentials
|
* Convenience method call with no parameters
|
||||||
* @param username The plain text username
|
|
||||||
* @param password The plain text password
|
|
||||||
* @param doPreemptiveAuth Select here whether to authenticate without it being requested first by the server.
|
|
||||||
*/
|
|
||||||
public void setBasicAuthentication(String username, String password, boolean doPreemptiveAuth) {
|
|
||||||
// This code required to trigger the patch created by erickok in issue #6
|
|
||||||
if(doPreemptiveAuth = true) {
|
|
||||||
this.httpPreAuth = doPreemptiveAuth;
|
|
||||||
this.username = username;
|
|
||||||
this.password = password;
|
|
||||||
} else {
|
|
||||||
((DefaultHttpClient) client).getCredentialsProvider().setCredentials(new AuthScope(postMethod.getURI().getHost(), postMethod.getURI().getPort(), AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convenience Constructor: Sets basic authentication on web request using plain credentials
|
|
||||||
* @param username The plain text username
|
|
||||||
* @param password The plain text password
|
|
||||||
*/
|
|
||||||
public void setBasicAuthentication(String username, String password) {
|
|
||||||
setBasicAuthentication(username, password, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call method with optional parameters. This is general method.
|
|
||||||
* If you want to call your method with 0-8 parameters, you can use more
|
|
||||||
* convenience call() methods
|
|
||||||
*
|
*
|
||||||
* @param method name of method to call
|
* @param method
|
||||||
* @param params parameters to pass to method (may be null if method has no parameters)
|
* name of method to call
|
||||||
|
* @return deserialized method return value
|
||||||
|
* @throws XMLRPCException
|
||||||
|
*/
|
||||||
|
public Object call(final String method) throws XMLRPCException {
|
||||||
|
return callEx(method, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method call. This method replace countless other convenience
|
||||||
|
* methods
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
* name of method to call
|
||||||
|
* @param params
|
||||||
|
* method's parameters
|
||||||
|
* @return deserialized method return value
|
||||||
|
* @throws XMLRPCException
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public Object call(final String method, final Object... params) throws XMLRPCException {
|
||||||
|
return callEx(method, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method call with a vectorized parameter (Code contributed by
|
||||||
|
* jahbromo from issue #14)
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
* name of method to call
|
||||||
|
* @param paramsv
|
||||||
|
* vector of method's parameter
|
||||||
|
* @return deserialized method return value
|
||||||
|
* @throws XMLRPCException
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Object call(final String method, final Vector paramsv) throws XMLRPCException {
|
||||||
|
final Object[] params = new Object[paramsv.size()];
|
||||||
|
for (int i = 0; i < paramsv.size(); i++)
|
||||||
|
params[i] = paramsv.elementAt(i);
|
||||||
|
return callEx(method, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call method with optional parameters. This is general method. If you want
|
||||||
|
* to call your method with 0-8 parameters, you can use more convenience
|
||||||
|
* call() methods
|
||||||
|
*
|
||||||
|
* @param method
|
||||||
|
* name of method to call
|
||||||
|
* @param params
|
||||||
|
* parameters to pass to method (may be null if method has no
|
||||||
|
* parameters)
|
||||||
* @return deserialized method return value
|
* @return deserialized method return value
|
||||||
* @throws XMLRPCException
|
* @throws XMLRPCException
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Object callEx(String method, Object[] params) throws XMLRPCException {
|
public Object callEx(final String method, final Object[] params) throws XMLRPCException {
|
||||||
try {
|
try {
|
||||||
// prepare POST body
|
// prepare POST body
|
||||||
String body = methodCall(method, params);
|
final String body = methodCall(method, params);
|
||||||
|
|
||||||
// set POST body
|
// set POST body
|
||||||
HttpEntity entity = new StringEntity(body);
|
HttpEntity entity = new StringEntity(body);
|
||||||
@@ -296,81 +413,83 @@ public class XMLRPCClient extends XMLRPCCommon {
|
|||||||
|
|
||||||
// This code slightly tweaked from the code by erickok in issue #6
|
// This code slightly tweaked from the code by erickok in issue #6
|
||||||
// Force preemptive authentication
|
// Force preemptive authentication
|
||||||
// This makes sure there is an 'Authentication: ' header being send before trying and failing and retrying
|
// This makes sure there is an 'Authentication: ' header being send
|
||||||
|
// before trying and failing and retrying
|
||||||
// by the basic authentication mechanism of DefaultHttpClient
|
// by the basic authentication mechanism of DefaultHttpClient
|
||||||
if(this.httpPreAuth == true) {
|
if (httpPreAuth == true) {
|
||||||
String auth = this.username + ":" + this.password;
|
final String auth = username + ":" + password;
|
||||||
postMethod.addHeader("Authorization", "Basic " + Base64Coder.encode(auth.getBytes()).toString());
|
postMethod.addHeader("Authorization", "Basic " + Base64Coder.encode(auth.getBytes()).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
//Log.d(Tag.LOG, "ros HTTP POST");
|
// Log.d(Tag.LOG, "ros HTTP POST");
|
||||||
// execute HTTP POST request
|
// execute HTTP POST request
|
||||||
HttpResponse response = client.execute(postMethod);
|
final HttpResponse response = client.execute(postMethod);
|
||||||
//Log.d(Tag.LOG, "ros HTTP POSTed");
|
// Log.d(Tag.LOG, "ros HTTP POSTed");
|
||||||
|
|
||||||
// check status code
|
// check status code
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
final int statusCode = response.getStatusLine().getStatusCode();
|
||||||
//Log.d(Tag.LOG, "ros status code:" + statusCode);
|
// Log.d(Tag.LOG, "ros status code:" + statusCode);
|
||||||
if (statusCode != HttpStatus.SC_OK) {
|
if (statusCode != HttpStatus.SC_OK)
|
||||||
throw new XMLRPCException("HTTP status code: " + statusCode + " != " + HttpStatus.SC_OK, statusCode);
|
throw new XMLRPCException("HTTP status code: " + statusCode + " != " + HttpStatus.SC_OK, statusCode);
|
||||||
}
|
|
||||||
|
|
||||||
// parse response stuff
|
// parse response stuff
|
||||||
//
|
//
|
||||||
// setup pull parser
|
// setup pull parser
|
||||||
XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
|
final XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
|
||||||
entity = response.getEntity();
|
entity = response.getEntity();
|
||||||
Reader reader = new InputStreamReader(new BufferedInputStream(entity.getContent()));
|
final Reader reader = new InputStreamReader(new BufferedInputStream(entity.getContent()));
|
||||||
// for testing purposes only
|
// for testing purposes only
|
||||||
// reader = new StringReader("<?xml version='1.0'?><methodResponse><params><param><value>\n\n\n</value></param></params></methodResponse>");
|
// reader = new
|
||||||
|
// StringReader("<?xml version='1.0'?><methodResponse><params><param><value>\n\n\n</value></param></params></methodResponse>");
|
||||||
pullParser.setInput(reader);
|
pullParser.setInput(reader);
|
||||||
|
|
||||||
// lets start pulling...
|
// lets start pulling...
|
||||||
pullParser.nextTag();
|
pullParser.nextTag();
|
||||||
pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_RESPONSE);
|
pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_RESPONSE);
|
||||||
|
|
||||||
pullParser.nextTag(); // either Tag.PARAMS (<params>) or Tag.FAULT (<fault>)
|
pullParser.nextTag(); // either Tag.PARAMS (<params>) or Tag.FAULT
|
||||||
String tag = pullParser.getName();
|
// (<fault>)
|
||||||
|
final String tag = pullParser.getName();
|
||||||
if (tag.equals(Tag.PARAMS)) {
|
if (tag.equals(Tag.PARAMS)) {
|
||||||
// normal response
|
// normal response
|
||||||
pullParser.nextTag(); // Tag.PARAM (<param>)
|
pullParser.nextTag(); // Tag.PARAM (<param>)
|
||||||
pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
|
pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
|
||||||
pullParser.nextTag(); // Tag.VALUE (<value>)
|
pullParser.nextTag(); // Tag.VALUE (<value>)
|
||||||
// no parser.require() here since its called in XMLRPCSerializer.deserialize() below
|
// no parser.require() here since its called in
|
||||||
|
// XMLRPCSerializer.deserialize() below
|
||||||
|
|
||||||
// deserialize result
|
// deserialize result
|
||||||
Object obj = iXMLRPCSerializer.deserialize(pullParser);
|
final Object obj = iXMLRPCSerializer.deserialize(pullParser);
|
||||||
entity.consumeContent();
|
entity.consumeContent();
|
||||||
return obj;
|
return obj;
|
||||||
} else
|
} else if (tag.equals(Tag.FAULT)) {
|
||||||
if (tag.equals(Tag.FAULT)) {
|
|
||||||
// fault response
|
// fault response
|
||||||
pullParser.nextTag(); // Tag.VALUE (<value>)
|
pullParser.nextTag(); // Tag.VALUE (<value>)
|
||||||
// no parser.require() here since its called in XMLRPCSerializer.deserialize() below
|
// no parser.require() here since its called in
|
||||||
|
// XMLRPCSerializer.deserialize() below
|
||||||
|
|
||||||
// deserialize fault result
|
// deserialize fault result
|
||||||
Map<String, Object> map = (Map<String, Object>) iXMLRPCSerializer.deserialize(pullParser);
|
final Map<String, Object> map = (Map<String, Object>) iXMLRPCSerializer.deserialize(pullParser);
|
||||||
String faultString = (String) map.get(Tag.FAULT_STRING);
|
final String faultString = (String) map.get(Tag.FAULT_STRING);
|
||||||
int faultCode = (Integer) map.get(Tag.FAULT_CODE);
|
final int faultCode = (Integer) map.get(Tag.FAULT_CODE);
|
||||||
entity.consumeContent();
|
entity.consumeContent();
|
||||||
throw new XMLRPCFault(faultString, faultCode);
|
throw new XMLRPCFault(faultString, faultCode);
|
||||||
} else {
|
} else {
|
||||||
entity.consumeContent();
|
entity.consumeContent();
|
||||||
throw new XMLRPCException("Bad tag <" + tag + "> in XMLRPC response - neither <params> nor <fault>");
|
throw new XMLRPCException("Bad tag <" + tag + "> in XMLRPC response - neither <params> nor <fault>");
|
||||||
}
|
}
|
||||||
} catch (XMLRPCException e) {
|
} catch (final XMLRPCException e) {
|
||||||
// catch & propagate XMLRPCException/XMLRPCFault
|
// catch & propagate XMLRPCException/XMLRPCFault
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
// wrap any other Exception(s) around XMLRPCException
|
// wrap any other Exception(s) around XMLRPCException
|
||||||
throw new XMLRPCException(e);
|
throw new XMLRPCException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String methodCall(String method, Object[] params)
|
private String methodCall(final String method, final Object[] params) throws IllegalArgumentException, IllegalStateException, IOException {
|
||||||
throws IllegalArgumentException, IllegalStateException, IOException {
|
final StringWriter bodyWriter = new StringWriter();
|
||||||
StringWriter bodyWriter = new StringWriter();
|
|
||||||
serializer.setOutput(bodyWriter);
|
serializer.setOutput(bodyWriter);
|
||||||
serializer.startDocument(null, null);
|
serializer.startDocument(null, null);
|
||||||
serializer.startTag(null, Tag.METHOD_CALL);
|
serializer.startTag(null, Tag.METHOD_CALL);
|
||||||
@@ -386,55 +505,50 @@ public class XMLRPCClient extends XMLRPCCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method call with no parameters
|
* Convenience Constructor: Sets basic authentication on web request using
|
||||||
|
* plain credentials
|
||||||
*
|
*
|
||||||
* @param method name of method to call
|
* @param username
|
||||||
* @return deserialized method return value
|
* The plain text username
|
||||||
* @throws XMLRPCException
|
* @param password
|
||||||
|
* The plain text password
|
||||||
*/
|
*/
|
||||||
public Object call(String method) throws XMLRPCException {
|
public void setBasicAuthentication(final String username, final String password) {
|
||||||
return callEx(method, null);
|
setBasicAuthentication(username, password, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method call with a vectorized parameter
|
* Sets basic authentication on web request using plain credentials
|
||||||
* (Code contributed by jahbromo from issue #14)
|
*
|
||||||
* @param method name of method to call
|
* @param username
|
||||||
* @param paramsv vector of method's parameter
|
* The plain text username
|
||||||
* @return deserialized method return value
|
* @param password
|
||||||
* @throws XMLRPCException
|
* The plain text password
|
||||||
|
* @param doPreemptiveAuth
|
||||||
|
* Select here whether to authenticate without it being requested
|
||||||
|
* first by the server.
|
||||||
*/
|
*/
|
||||||
|
public void setBasicAuthentication(final String username, final String password, boolean doPreemptiveAuth) {
|
||||||
public Object call(String method, Vector paramsv) throws XMLRPCException {
|
// This code required to trigger the patch created by erickok in issue
|
||||||
Object[] params = new Object [paramsv.size()];
|
// #6
|
||||||
for (int i=0; i<paramsv.size(); i++) {
|
if (doPreemptiveAuth = true) {
|
||||||
params[i]=paramsv.elementAt(i);
|
httpPreAuth = doPreemptiveAuth;
|
||||||
}
|
this.username = username;
|
||||||
return callEx(method, params);
|
this.password = password;
|
||||||
|
} else
|
||||||
|
((DefaultHttpClient) client).getCredentialsProvider()
|
||||||
|
.setCredentials(new AuthScope(postMethod.getURI().getHost(), postMethod.getURI().getPort(), AuthScope.ANY_REALM),
|
||||||
|
new UsernamePasswordCredentials(username, password));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method call. This method replace countless other convenience methods
|
* Amends user agent (Code contributed by mortenholdflod from issue #28)
|
||||||
* @param method name of method to call
|
*
|
||||||
* @param params method's parameters
|
* @param userAgent
|
||||||
* @return deserialized method return value
|
* defining the new User Agent string
|
||||||
* @throws XMLRPCException
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
*/
|
||||||
public Object call(String method, Object... params) throws XMLRPCException {
|
public void setUserAgent(final String userAgent) {
|
||||||
return callEx(method, params);
|
postMethod.removeHeaders("User-Agent");
|
||||||
}
|
postMethod.addHeader("User-Agent", userAgent);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an XML RPC Client
|
|
||||||
* @param Context
|
|
||||||
* @return XMLRPCClient
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public static XMLRPCClient getClient(Context context) {
|
|
||||||
if(Constraints.TESTING)
|
|
||||||
return new XMLRPCClient(context.getString(R.string.test_server), context.getString(R.string.test_username), context.getString(R.string.test_password));
|
|
||||||
else
|
|
||||||
return new XMLRPCClient(context.getString(R.string.osj_server), context.getString(R.string.test_username), context.getString(R.string.test_password));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,27 +16,28 @@ class XMLRPCCommon {
|
|||||||
iXMLRPCSerializer = new XMLRPCSerializer();
|
iXMLRPCSerializer = new XMLRPCSerializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void serializeParams(final Object... params) throws IllegalArgumentException, IllegalStateException, IOException {
|
||||||
* Sets custom IXMLRPCSerializer serializer (in case when server doesn't support
|
|
||||||
* standard XMLRPC protocol)
|
|
||||||
*
|
|
||||||
* @param serializer custom serializer
|
|
||||||
*/
|
|
||||||
public void setSerializer(IXMLRPCSerializer serializer) {
|
|
||||||
iXMLRPCSerializer = serializer;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void serializeParams(Object... params) throws IllegalArgumentException, IllegalStateException, IOException {
|
|
||||||
if (params != null && params.length != 0) {
|
if (params != null && params.length != 0) {
|
||||||
// set method params
|
// set method params
|
||||||
serializer.startTag(null, Tag.PARAMS);
|
serializer.startTag(null, Tag.PARAMS);
|
||||||
for (int i=0; i<params.length; i++) {
|
for (final Object param : params) {
|
||||||
serializer.startTag(null, Tag.PARAM).startTag(null, IXMLRPCSerializer.TAG_VALUE);
|
serializer.startTag(null, Tag.PARAM).startTag(null, IXMLRPCSerializer.TAG_VALUE);
|
||||||
iXMLRPCSerializer.serialize(serializer, params[i]);
|
iXMLRPCSerializer.serialize(serializer, param);
|
||||||
serializer.endTag(null, IXMLRPCSerializer.TAG_VALUE).endTag(null, Tag.PARAM);
|
serializer.endTag(null, IXMLRPCSerializer.TAG_VALUE).endTag(null, Tag.PARAM);
|
||||||
}
|
}
|
||||||
serializer.endTag(null, Tag.PARAMS);
|
serializer.endTag(null, Tag.PARAMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets custom IXMLRPCSerializer serializer (in case when server doesn't
|
||||||
|
* support standard XMLRPC protocol)
|
||||||
|
*
|
||||||
|
* @param serializer
|
||||||
|
* custom serializer
|
||||||
|
*/
|
||||||
|
public void setSerializer(final IXMLRPCSerializer serializer) {
|
||||||
|
iXMLRPCSerializer = serializer;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ public class XMLRPCException extends Exception {
|
|||||||
|
|
||||||
private int httpStatusCode = HttpStatus.SC_OK;
|
private int httpStatusCode = HttpStatus.SC_OK;
|
||||||
|
|
||||||
public XMLRPCException(Exception e) {
|
public XMLRPCException(final Exception e) {
|
||||||
super(e);
|
super(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XMLRPCException(String string) {
|
public XMLRPCException(final String string) {
|
||||||
super(string);
|
super(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XMLRPCException(String string, int httpStatusCode) {
|
public XMLRPCException(final String string, final int httpStatusCode) {
|
||||||
this(string);
|
this(string);
|
||||||
this.httpStatusCode = httpStatusCode;
|
this.httpStatusCode = httpStatusCode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,20 +5,20 @@ public class XMLRPCFault extends XMLRPCException {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 5676562456612956519L;
|
private static final long serialVersionUID = 5676562456612956519L;
|
||||||
private String faultString;
|
private final String faultString;
|
||||||
private int faultCode;
|
private final int faultCode;
|
||||||
|
|
||||||
public XMLRPCFault(String faultString, int faultCode) {
|
public XMLRPCFault(final String faultString, final int faultCode) {
|
||||||
super("XMLRPC Fault: " + faultString + " [code " + faultCode + "]");
|
super("XMLRPC Fault: " + faultString + " [code " + faultCode + "]");
|
||||||
this.faultString = faultString;
|
this.faultString = faultString;
|
||||||
this.faultCode = faultCode;
|
this.faultCode = faultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFaultString() {
|
|
||||||
return faultString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getFaultCode() {
|
public int getFaultCode() {
|
||||||
return faultCode;
|
return faultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFaultString() {
|
||||||
|
return faultString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package org.xmlrpc.android;
|
package org.xmlrpc.android;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to pass any XMLRPCSerializable object as input parameter.
|
* Allows to pass any XMLRPCSerializable object as input parameter. When
|
||||||
* When implementing getSerializable() you should return
|
* implementing getSerializable() you should return one of XMLRPC primitive
|
||||||
* one of XMLRPC primitive types (or another XMLRPCSerializable: be careful not going into
|
* types (or another XMLRPCSerializable: be careful not going into recursion by
|
||||||
* recursion by passing this object reference!)
|
* passing this object reference!)
|
||||||
*/
|
*/
|
||||||
public interface XMLRPCSerializable {
|
public interface XMLRPCSerializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets XMLRPC serialization object
|
* Gets XMLRPC serialization object
|
||||||
* @return object to serialize This object is most likely one of XMLRPC primitive types,
|
*
|
||||||
* however you can return also another XMLRPCSerializable
|
* @return object to serialize This object is most likely one of XMLRPC
|
||||||
|
* primitive types, however you can return also another
|
||||||
|
* XMLRPCSerializable
|
||||||
*/
|
*/
|
||||||
Object getSerializable();
|
Object getSerializable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,69 +23,162 @@ import org.xmlpull.v1.XmlSerializer;
|
|||||||
class XMLRPCSerializer implements IXMLRPCSerializer {
|
class XMLRPCSerializer implements IXMLRPCSerializer {
|
||||||
static SimpleDateFormat dateFormat = new SimpleDateFormat(DATETIME_FORMAT);
|
static SimpleDateFormat dateFormat = new SimpleDateFormat(DATETIME_FORMAT);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object deserialize(final XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||||
|
parser.require(XmlPullParser.START_TAG, null, TAG_VALUE);
|
||||||
|
|
||||||
|
if (parser.isEmptyElementTag())
|
||||||
|
// degenerated <value />, return empty string
|
||||||
|
return "";
|
||||||
|
|
||||||
|
Object obj;
|
||||||
|
boolean hasType = true;
|
||||||
|
String typeNodeName = null;
|
||||||
|
try {
|
||||||
|
parser.nextTag();
|
||||||
|
typeNodeName = parser.getName();
|
||||||
|
if (typeNodeName.equals(TAG_VALUE) && parser.getEventType() == XmlPullParser.END_TAG)
|
||||||
|
// empty <value></value>, return empty string
|
||||||
|
return "";
|
||||||
|
|
||||||
|
} catch (final XmlPullParserException e) {
|
||||||
|
hasType = false;
|
||||||
|
}
|
||||||
|
if (hasType) {
|
||||||
|
// This code submitted by mattias.ellback in issue #19
|
||||||
|
if (typeNodeName.equals(TYPE_NULL)) {
|
||||||
|
parser.nextTag();
|
||||||
|
obj = null;
|
||||||
|
} else if (typeNodeName.equals(TYPE_INT) || typeNodeName.equals(TYPE_I4)) {
|
||||||
|
final String value = parser.nextText();
|
||||||
|
obj = Integer.parseInt(value);
|
||||||
|
} else if (typeNodeName.equals(TYPE_I8)) {
|
||||||
|
final String value = parser.nextText();
|
||||||
|
obj = Long.parseLong(value);
|
||||||
|
} else if (typeNodeName.equals(TYPE_DOUBLE)) {
|
||||||
|
final String value = parser.nextText();
|
||||||
|
obj = Double.parseDouble(value);
|
||||||
|
} else if (typeNodeName.equals(TYPE_BOOLEAN)) {
|
||||||
|
final String value = parser.nextText();
|
||||||
|
obj = value.equals("1") ? Boolean.TRUE : Boolean.FALSE;
|
||||||
|
} else if (typeNodeName.equals(TYPE_STRING))
|
||||||
|
obj = parser.nextText();
|
||||||
|
else if (typeNodeName.equals(TYPE_DATE_TIME_ISO8601)) {
|
||||||
|
final String value = parser.nextText();
|
||||||
|
try {
|
||||||
|
obj = dateFormat.parseObject(value);
|
||||||
|
} catch (final ParseException e) {
|
||||||
|
throw new IOException("Cannot deserialize dateTime " + value);
|
||||||
|
}
|
||||||
|
} else if (typeNodeName.equals(TYPE_BASE64)) {
|
||||||
|
final String value = parser.nextText();
|
||||||
|
final BufferedReader reader = new BufferedReader(new StringReader(value));
|
||||||
|
String line;
|
||||||
|
final StringBuffer sb = new StringBuffer();
|
||||||
|
while ((line = reader.readLine()) != null)
|
||||||
|
sb.append(line);
|
||||||
|
obj = Base64Coder.decode(sb.toString());
|
||||||
|
} else if (typeNodeName.equals(TYPE_ARRAY)) {
|
||||||
|
parser.nextTag(); // TAG_DATA (<data>)
|
||||||
|
parser.require(XmlPullParser.START_TAG, null, TAG_DATA);
|
||||||
|
|
||||||
|
parser.nextTag();
|
||||||
|
final List<Object> list = new ArrayList<Object>();
|
||||||
|
while (parser.getName().equals(TAG_VALUE)) {
|
||||||
|
list.add(deserialize(parser));
|
||||||
|
parser.nextTag();
|
||||||
|
}
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, TAG_DATA);
|
||||||
|
parser.nextTag(); // TAG_ARRAY (</array>)
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, TYPE_ARRAY);
|
||||||
|
obj = list.toArray();
|
||||||
|
} else if (typeNodeName.equals(TYPE_STRUCT)) {
|
||||||
|
parser.nextTag();
|
||||||
|
final Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
while (parser.getName().equals(TAG_MEMBER)) {
|
||||||
|
String memberName = null;
|
||||||
|
Object memberValue = null;
|
||||||
|
while (true) {
|
||||||
|
parser.nextTag();
|
||||||
|
final String name = parser.getName();
|
||||||
|
if (name.equals(TAG_NAME))
|
||||||
|
memberName = parser.nextText();
|
||||||
|
else if (name.equals(TAG_VALUE))
|
||||||
|
memberValue = deserialize(parser);
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (memberName != null && memberValue != null)
|
||||||
|
map.put(memberName, memberValue);
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, TAG_MEMBER);
|
||||||
|
parser.nextTag();
|
||||||
|
}
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, TYPE_STRUCT);
|
||||||
|
obj = map;
|
||||||
|
} else
|
||||||
|
throw new IOException("Cannot deserialize " + parser.getName());
|
||||||
|
} else
|
||||||
|
// TYPE_STRING (<string>) is not required
|
||||||
|
obj = parser.getText();
|
||||||
|
parser.nextTag(); // TAG_VALUE (</value>)
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, TAG_VALUE);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void serialize(XmlSerializer serializer, Object object) throws IOException {
|
public void serialize(final XmlSerializer serializer, final Object object) throws IOException {
|
||||||
// This code supplied by mattias.ellback as part of issue #19
|
// This code supplied by mattias.ellback as part of issue #19
|
||||||
if (object == null){
|
if (object == null)
|
||||||
serializer.startTag(null, TYPE_NULL).endTag(null, TYPE_NULL);
|
serializer.startTag(null, TYPE_NULL).endTag(null, TYPE_NULL);
|
||||||
} else
|
else
|
||||||
// check for scalar types:
|
// check for scalar types:
|
||||||
if (object instanceof Integer || object instanceof Short || object instanceof Byte) {
|
if (object instanceof Integer || object instanceof Short || object instanceof Byte)
|
||||||
serializer.startTag(null, TYPE_I4).text(object.toString()).endTag(null, TYPE_I4);
|
serializer.startTag(null, TYPE_I4).text(object.toString()).endTag(null, TYPE_I4);
|
||||||
} else
|
else if (object instanceof Long)
|
||||||
if (object instanceof Long) {
|
|
||||||
serializer.startTag(null, TYPE_I8).text(object.toString()).endTag(null, TYPE_I8);
|
serializer.startTag(null, TYPE_I8).text(object.toString()).endTag(null, TYPE_I8);
|
||||||
} else
|
else if (object instanceof Double || object instanceof Float)
|
||||||
if (object instanceof Double || object instanceof Float) {
|
|
||||||
serializer.startTag(null, TYPE_DOUBLE).text(object.toString()).endTag(null, TYPE_DOUBLE);
|
serializer.startTag(null, TYPE_DOUBLE).text(object.toString()).endTag(null, TYPE_DOUBLE);
|
||||||
} else
|
else if (object instanceof Boolean) {
|
||||||
if (object instanceof Boolean) {
|
final Boolean bool = (Boolean) object;
|
||||||
Boolean bool = (Boolean) object;
|
final String boolStr = bool.booleanValue() ? "1" : "0";
|
||||||
String boolStr = bool.booleanValue() ? "1" : "0";
|
|
||||||
serializer.startTag(null, TYPE_BOOLEAN).text(boolStr).endTag(null, TYPE_BOOLEAN);
|
serializer.startTag(null, TYPE_BOOLEAN).text(boolStr).endTag(null, TYPE_BOOLEAN);
|
||||||
} else
|
} else if (object instanceof String)
|
||||||
if (object instanceof String) {
|
|
||||||
serializer.startTag(null, TYPE_STRING).text(object.toString()).endTag(null, TYPE_STRING);
|
serializer.startTag(null, TYPE_STRING).text(object.toString()).endTag(null, TYPE_STRING);
|
||||||
} else
|
else if (object instanceof Date || object instanceof Calendar) {
|
||||||
if (object instanceof Date || object instanceof Calendar) {
|
final String dateStr = dateFormat.format(object);
|
||||||
String dateStr = dateFormat.format(object);
|
|
||||||
serializer.startTag(null, TYPE_DATE_TIME_ISO8601).text(dateStr).endTag(null, TYPE_DATE_TIME_ISO8601);
|
serializer.startTag(null, TYPE_DATE_TIME_ISO8601).text(dateStr).endTag(null, TYPE_DATE_TIME_ISO8601);
|
||||||
} else
|
} else if (object instanceof byte[]) {
|
||||||
if (object instanceof byte[] ){
|
final String value = new String(Base64Coder.encode((byte[]) object));
|
||||||
String value = new String(Base64Coder.encode((byte[])object));
|
|
||||||
serializer.startTag(null, TYPE_BASE64).text(value).endTag(null, TYPE_BASE64);
|
serializer.startTag(null, TYPE_BASE64).text(value).endTag(null, TYPE_BASE64);
|
||||||
} else
|
} else if (object instanceof List) {
|
||||||
if (object instanceof List) {
|
|
||||||
serializer.startTag(null, TYPE_ARRAY).startTag(null, TAG_DATA);
|
serializer.startTag(null, TYPE_ARRAY).startTag(null, TAG_DATA);
|
||||||
List<Object> list = (List<Object>) object;
|
final List<Object> list = (List<Object>) object;
|
||||||
Iterator<Object> iter = list.iterator();
|
final Iterator<Object> iter = list.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Object o = iter.next();
|
final Object o = iter.next();
|
||||||
serializer.startTag(null, TAG_VALUE);
|
serializer.startTag(null, TAG_VALUE);
|
||||||
serialize(serializer, o);
|
serialize(serializer, o);
|
||||||
serializer.endTag(null, TAG_VALUE);
|
serializer.endTag(null, TAG_VALUE);
|
||||||
}
|
}
|
||||||
serializer.endTag(null, TAG_DATA).endTag(null, TYPE_ARRAY);
|
serializer.endTag(null, TAG_DATA).endTag(null, TYPE_ARRAY);
|
||||||
} else
|
} else if (object instanceof Object[]) {
|
||||||
if (object instanceof Object[]) {
|
|
||||||
serializer.startTag(null, TYPE_ARRAY).startTag(null, TAG_DATA);
|
serializer.startTag(null, TYPE_ARRAY).startTag(null, TAG_DATA);
|
||||||
Object[] objects = (Object[]) object;
|
final Object[] objects = (Object[]) object;
|
||||||
for (int i=0; i<objects.length; i++) {
|
for (final Object o : objects) {
|
||||||
Object o = objects[i];
|
|
||||||
serializer.startTag(null, TAG_VALUE);
|
serializer.startTag(null, TAG_VALUE);
|
||||||
serialize(serializer, o);
|
serialize(serializer, o);
|
||||||
serializer.endTag(null, TAG_VALUE);
|
serializer.endTag(null, TAG_VALUE);
|
||||||
}
|
}
|
||||||
serializer.endTag(null, TAG_DATA).endTag(null, TYPE_ARRAY);
|
serializer.endTag(null, TAG_DATA).endTag(null, TYPE_ARRAY);
|
||||||
} else
|
} else if (object instanceof Map) {
|
||||||
if (object instanceof Map) {
|
|
||||||
serializer.startTag(null, TYPE_STRUCT);
|
serializer.startTag(null, TYPE_STRUCT);
|
||||||
Map<String, Object> map = (Map<String, Object>) object;
|
final Map<String, Object> map = (Map<String, Object>) object;
|
||||||
Iterator<Entry<String, Object>> iter = map.entrySet().iterator();
|
final Iterator<Entry<String, Object>> iter = map.entrySet().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Entry<String, Object> entry = iter.next();
|
final Entry<String, Object> entry = iter.next();
|
||||||
String key = entry.getKey();
|
final String key = entry.getKey();
|
||||||
Object value = entry.getValue();
|
final Object value = entry.getValue();
|
||||||
|
|
||||||
serializer.startTag(null, TAG_MEMBER);
|
serializer.startTag(null, TAG_MEMBER);
|
||||||
serializer.startTag(null, TAG_NAME).text(key).endTag(null, TAG_NAME);
|
serializer.startTag(null, TAG_NAME).text(key).endTag(null, TAG_NAME);
|
||||||
@@ -95,132 +188,10 @@ class XMLRPCSerializer implements IXMLRPCSerializer {
|
|||||||
serializer.endTag(null, TAG_MEMBER);
|
serializer.endTag(null, TAG_MEMBER);
|
||||||
}
|
}
|
||||||
serializer.endTag(null, TYPE_STRUCT);
|
serializer.endTag(null, TYPE_STRUCT);
|
||||||
} else
|
} else if (object instanceof XMLRPCSerializable) {
|
||||||
if (object instanceof XMLRPCSerializable) {
|
final XMLRPCSerializable serializable = (XMLRPCSerializable) object;
|
||||||
XMLRPCSerializable serializable = (XMLRPCSerializable) object;
|
|
||||||
serialize(serializer, serializable.getSerializable());
|
serialize(serializer, serializable.getSerializable());
|
||||||
} else {
|
} else
|
||||||
throw new IOException("Cannot serialize " + object);
|
throw new IOException("Cannot serialize " + object);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object deserialize(XmlPullParser parser) throws XmlPullParserException, IOException {
|
|
||||||
parser.require(XmlPullParser.START_TAG, null, TAG_VALUE);
|
|
||||||
|
|
||||||
if (parser.isEmptyElementTag()) {
|
|
||||||
// degenerated <value />, return empty string
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
Object obj;
|
|
||||||
boolean hasType = true;
|
|
||||||
String typeNodeName = null;
|
|
||||||
try {
|
|
||||||
parser.nextTag();
|
|
||||||
typeNodeName = parser.getName();
|
|
||||||
if (typeNodeName.equals(TAG_VALUE) && parser.getEventType() == XmlPullParser.END_TAG) {
|
|
||||||
// empty <value></value>, return empty string
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
hasType = false;
|
|
||||||
}
|
|
||||||
if (hasType) {
|
|
||||||
// This code submitted by mattias.ellback in issue #19
|
|
||||||
if (typeNodeName.equals(TYPE_NULL)){
|
|
||||||
parser.nextTag();
|
|
||||||
obj = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (typeNodeName.equals(TYPE_INT) || typeNodeName.equals(TYPE_I4)) {
|
|
||||||
String value = parser.nextText();
|
|
||||||
obj = Integer.parseInt(value);
|
|
||||||
} else
|
|
||||||
if (typeNodeName.equals(TYPE_I8)) {
|
|
||||||
String value = parser.nextText();
|
|
||||||
obj = Long.parseLong(value);
|
|
||||||
} else
|
|
||||||
if (typeNodeName.equals(TYPE_DOUBLE)) {
|
|
||||||
String value = parser.nextText();
|
|
||||||
obj = Double.parseDouble(value);
|
|
||||||
} else
|
|
||||||
if (typeNodeName.equals(TYPE_BOOLEAN)) {
|
|
||||||
String value = parser.nextText();
|
|
||||||
obj = value.equals("1") ? Boolean.TRUE : Boolean.FALSE;
|
|
||||||
} else
|
|
||||||
if (typeNodeName.equals(TYPE_STRING)) {
|
|
||||||
obj = parser.nextText();
|
|
||||||
} else
|
|
||||||
if (typeNodeName.equals(TYPE_DATE_TIME_ISO8601)) {
|
|
||||||
String value = parser.nextText();
|
|
||||||
try {
|
|
||||||
obj = dateFormat.parseObject(value);
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new IOException("Cannot deserialize dateTime " + value);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
if (typeNodeName.equals(TYPE_BASE64)) {
|
|
||||||
String value = parser.nextText();
|
|
||||||
BufferedReader reader = new BufferedReader(new StringReader(value));
|
|
||||||
String line;
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
sb.append(line);
|
|
||||||
}
|
|
||||||
obj = Base64Coder.decode(sb.toString());
|
|
||||||
} else
|
|
||||||
if (typeNodeName.equals(TYPE_ARRAY)) {
|
|
||||||
parser.nextTag(); // TAG_DATA (<data>)
|
|
||||||
parser.require(XmlPullParser.START_TAG, null, TAG_DATA);
|
|
||||||
|
|
||||||
parser.nextTag();
|
|
||||||
List<Object> list = new ArrayList<Object>();
|
|
||||||
while (parser.getName().equals(TAG_VALUE)) {
|
|
||||||
list.add(deserialize(parser));
|
|
||||||
parser.nextTag();
|
|
||||||
}
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, TAG_DATA);
|
|
||||||
parser.nextTag(); // TAG_ARRAY (</array>)
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, TYPE_ARRAY);
|
|
||||||
obj = list.toArray();
|
|
||||||
} else
|
|
||||||
if (typeNodeName.equals(TYPE_STRUCT)) {
|
|
||||||
parser.nextTag();
|
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
|
||||||
while (parser.getName().equals(TAG_MEMBER)) {
|
|
||||||
String memberName = null;
|
|
||||||
Object memberValue = null;
|
|
||||||
while (true) {
|
|
||||||
parser.nextTag();
|
|
||||||
String name = parser.getName();
|
|
||||||
if (name.equals(TAG_NAME)) {
|
|
||||||
memberName = parser.nextText();
|
|
||||||
} else
|
|
||||||
if (name.equals(TAG_VALUE)) {
|
|
||||||
memberValue = deserialize(parser);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (memberName != null && memberValue != null) {
|
|
||||||
map.put(memberName, memberValue);
|
|
||||||
}
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, TAG_MEMBER);
|
|
||||||
parser.nextTag();
|
|
||||||
}
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, TYPE_STRUCT);
|
|
||||||
obj = map;
|
|
||||||
} else {
|
|
||||||
throw new IOException("Cannot deserialize " + parser.getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TYPE_STRING (<string>) is not required
|
|
||||||
obj = parser.getText();
|
|
||||||
}
|
|
||||||
parser.nextTag(); // TAG_VALUE (</value>)
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, TAG_VALUE);
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,25 +16,34 @@ import android.util.Log;
|
|||||||
|
|
||||||
public class XMLRPCServer extends XMLRPCCommon {
|
public class XMLRPCServer extends XMLRPCCommon {
|
||||||
|
|
||||||
private static final String CRLF = "\r\n";
|
private static final String CRLF = "\r\n";
|
||||||
private static final String RESPONSE =
|
private static final String RESPONSE = "HTTP/1.1 200 OK" + CRLF + "Connection: close" + CRLF + "Content-Type: text/xml" + CRLF + "Content-Length: ";
|
||||||
"HTTP/1.1 200 OK" + CRLF +
|
|
||||||
"Connection: close" + CRLF +
|
|
||||||
"Content-Type: text/xml" + CRLF +
|
|
||||||
"Content-Length: ";
|
|
||||||
private static final String NEWLINES = CRLF + CRLF;
|
private static final String NEWLINES = CRLF + CRLF;
|
||||||
private XMLRPCSerializer iXMLRPCSerializer;
|
private final XMLRPCSerializer iXMLRPCSerializer;
|
||||||
|
|
||||||
public XMLRPCServer() {
|
public XMLRPCServer() {
|
||||||
iXMLRPCSerializer = new XMLRPCSerializer();
|
iXMLRPCSerializer = new XMLRPCSerializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodCall readMethodCall(Socket socket) throws IOException, XmlPullParserException
|
private String methodResponse(final Object value) throws IllegalArgumentException, IllegalStateException, IOException {
|
||||||
{
|
final StringWriter bodyWriter = new StringWriter();
|
||||||
MethodCall methodCall = new MethodCall();
|
serializer.setOutput(bodyWriter);
|
||||||
InputStream inputStream = socket.getInputStream();
|
serializer.startDocument(null, null);
|
||||||
|
serializer.startTag(null, Tag.METHOD_RESPONSE);
|
||||||
|
|
||||||
XmlPullParser pullParser = xmlPullParserFromSocket(inputStream);
|
serializeParams(value);
|
||||||
|
|
||||||
|
serializer.endTag(null, Tag.METHOD_RESPONSE);
|
||||||
|
serializer.endDocument();
|
||||||
|
|
||||||
|
return bodyWriter.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MethodCall readMethodCall(final Socket socket) throws IOException, XmlPullParserException {
|
||||||
|
final MethodCall methodCall = new MethodCall();
|
||||||
|
final InputStream inputStream = socket.getInputStream();
|
||||||
|
|
||||||
|
final XmlPullParser pullParser = xmlPullParserFromSocket(inputStream);
|
||||||
|
|
||||||
pullParser.nextTag();
|
pullParser.nextTag();
|
||||||
pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_CALL);
|
pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_CALL);
|
||||||
@@ -47,12 +56,13 @@ public class XMLRPCServer extends XMLRPCCommon {
|
|||||||
pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAMS);
|
pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAMS);
|
||||||
pullParser.nextTag(); // possible optional <param> or </params>
|
pullParser.nextTag(); // possible optional <param> or </params>
|
||||||
|
|
||||||
while (pullParser.getName().equals(Tag.PARAM)) { // <param>
|
while (pullParser.getName().equals(Tag.PARAM)) { // <param>
|
||||||
//Log.d(Tag.LOG, "type=" + pullParser.getEventType() + ", tag=" + pullParser.getName());
|
// Log.d(Tag.LOG, "type=" + pullParser.getEventType() + ", tag=" +
|
||||||
|
// pullParser.getName());
|
||||||
pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
|
pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
|
||||||
pullParser.nextTag(); // <value>
|
pullParser.nextTag(); // <value>
|
||||||
|
|
||||||
Object param = iXMLRPCSerializer.deserialize(pullParser);
|
final Object param = iXMLRPCSerializer.deserialize(pullParser);
|
||||||
methodCall.params.add(param); // add to return value
|
methodCall.params.add(param); // add to return value
|
||||||
|
|
||||||
pullParser.nextTag();
|
pullParser.nextTag();
|
||||||
@@ -63,21 +73,11 @@ public class XMLRPCServer extends XMLRPCCommon {
|
|||||||
return methodCall;
|
return methodCall;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlPullParser xmlPullParserFromSocket(InputStream socketInputStream) throws IOException, XmlPullParserException {
|
public void respond(final Socket socket, final Object value) throws IOException {
|
||||||
String line;
|
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(socketInputStream));
|
|
||||||
while ((line = br.readLine()) != null && line.length() > 0); // eat the HTTP POST headers
|
|
||||||
|
|
||||||
XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
|
final String content = methodResponse(value);
|
||||||
pullParser.setInput(br);
|
final String response = RESPONSE + content.length() + NEWLINES + content;
|
||||||
return pullParser;
|
final OutputStream outputStream = socket.getOutputStream();
|
||||||
}
|
|
||||||
|
|
||||||
public void respond(Socket socket, Object value) throws IOException {
|
|
||||||
|
|
||||||
String content = methodResponse(value);
|
|
||||||
String response = RESPONSE + (content.length()) + NEWLINES + content;
|
|
||||||
OutputStream outputStream = socket.getOutputStream();
|
|
||||||
outputStream.write(response.getBytes());
|
outputStream.write(response.getBytes());
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
@@ -85,17 +85,14 @@ public class XMLRPCServer extends XMLRPCCommon {
|
|||||||
Log.d(Tag.LOG, "response:" + response);
|
Log.d(Tag.LOG, "response:" + response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String methodResponse(Object value) throws IllegalArgumentException, IllegalStateException, IOException {
|
XmlPullParser xmlPullParserFromSocket(final InputStream socketInputStream) throws IOException, XmlPullParserException {
|
||||||
StringWriter bodyWriter = new StringWriter();
|
String line;
|
||||||
serializer.setOutput(bodyWriter);
|
final BufferedReader br = new BufferedReader(new InputStreamReader(socketInputStream));
|
||||||
serializer.startDocument(null, null);
|
while ((line = br.readLine()) != null && line.length() > 0)
|
||||||
serializer.startTag(null, Tag.METHOD_RESPONSE);
|
; // eat the HTTP POST headers
|
||||||
|
|
||||||
serializeParams(value);
|
final XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
|
||||||
|
pullParser.setInput(br);
|
||||||
serializer.endTag(null, Tag.METHOD_RESPONSE);
|
return pullParser;
|
||||||
serializer.endDocument();
|
|
||||||
|
|
||||||
return bodyWriter.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user