Package com.bitpass.css.wrapper

Source Code of com.bitpass.css.wrapper.BitPassAdapter

// $Header: /usr/local/cvs/bpcss/app/com/bitpass/css/wrapper/BitPassAdapter.java,v 1.72 2005/07/27 01:49:35 ebuswell Exp $

package com.bitpass.css.wrapper;

import com.bitpass.css.hibernate.DataAccount;
import com.bitpass.css.misc.Initable;
import com.bitpass.css.misc.InitableException;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcClient;
import org.apache.xmlrpc.XmlRpcClientLite;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.commons.lang.StringEscapeUtils;
import java.util.Properties;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import java.util.Arrays;
import java.util.Comparator;
import java.util.TreeSet;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Locale;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Random;
import java.security.SecureRandom;
import java.io.IOException;
import java.net.MalformedURLException;

/**
* Handles all communication with the BitPass API XML-RPC server.
*/
public class BitPassAdapter implements Initable {

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////    CONSTANTS         /////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * The name of the properties files for this class; default location is the class's directory.
     */
    private final static String PROPERTIES_FILENAME = "BitPassAdapter.properties";

    private final static String PROP_USE_LITE_CLIENT = "USE_LITE_CLIENT";
    private final static String PROP_SERVER_URL = "SERVER_URL";

    /**
     * Form constants.
     */
    public final static String LIST_CONTENT_SHOW_ALL = "ALL";
    public final static String LIST_CONTENT_SHOW_PUBLISHED = "PUBLISHED";
    public final static String LIST_CONTENT_SHOW_PREVIEW = "PREVIEW";
    public final static String LIST_CONTENT_SHOW_ENABLED = "ENABLED";
    public final static String LIST_CONTENT_SHOW_DISABLED = "DISABLED";
    public final static String LIST_CONTENT_SORT_REGTIME = "REGTIME";
    public final static String LIST_CONTENT_SORT_MODTIME = "MODTIME";
    public final static String LIST_CONTENT_SORT_PRICE = "PRICE";
    public final static String LIST_CONTENT_SORT_EXPIRES = "EXPIRES";
    public final static String LIST_CONTENT_SORT_PATH = "PATH";
    public final static String LIST_CONTENT_SORT_LINK_TXT = "LINK_TXT";
    public final static Integer LIST_CONTENT_ORDER_ASC = new Integer( 0 );
    public final static Integer LIST_CONTENT_ORDER_DESC = new Integer( 1 );

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////    Properties        /////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * Whether or not to use the lite version of the XmlRpcClient.
     */
    private boolean P_USE_LITE_CLIENT = false;

    /**
     * The BitPass server URL.
     */
    private String P_SERVER_URL;

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////    MEMBERS           /////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * The Logger instance.
     */
    protected static Logger logger;

    /**
     * The XML-RPC client.
     */
    protected XmlRpcClient client;

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////    CONSTRUCTORS      /////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    /**
     * The singleton instance.
     */
    public static final BitPassAdapter instance = new BitPassAdapter();

    /**
     * Singleton constructor.
     */
    private BitPassAdapter() {

        // Set the logger for this class.
        logger = Logger.getLogger( this.getClass() );
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////    Initable Interface ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public void init() throws InitableException {

        String tmpS;

        // Load the properties from a file.
        Properties props = new Properties();
        try {
            props.load( BitPassAdapter.class.getResourceAsStream( PROPERTIES_FILENAME ) );
        } catch( NullPointerException e ) {
            logger.error( "Could not find properties file " + PROPERTIES_FILENAME );
        } catch( IOException e ) {
            logger.error( "Error reading properties file " + PROPERTIES_FILENAME + ": " + e.toString() );
        }

        //
        // Set the property values as constants on the object.
        //

        //
        tmpS = props.getProperty( PROP_USE_LITE_CLIENT );
        P_USE_LITE_CLIENT = tmpS != null && tmpS.trim().equals( "1" );

        //
        try {
            P_SERVER_URL = props.getProperty( PROP_SERVER_URL ).trim();
        } catch( NullPointerException e ) {
            logger.error( "No SERVER_URL property set in " + PROPERTIES_FILENAME );
            throw new InitableException( "No SERVER_URL property set in " + PROPERTIES_FILENAME );
        }

        //
        // Get the XML-RPC client.
        //
        try {
            if( P_USE_LITE_CLIENT ) {
                client = new XmlRpcClientLite( P_SERVER_URL );
            } else {
                client = new XmlRpcClient( P_SERVER_URL );
            }
        } catch( MalformedURLException e ) {
            logger.error( "Could not connect to " + P_SERVER_URL + ": " + e.toString() );
            throw new InitableException( "Could not connect to " + P_SERVER_URL + ": " + e.toString() );
        }

        // Done.
        logger.info( "BitPassAdapter initialized successfully." );
    }

    public void kill() throws InitableException {
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   list items in the registry  /////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Object[] listcnt( String account ) throws BitPassAdapterException {
        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );

        // Make the connection.
        Hashtable result = callXmlRpc("list-contents", args);

        Object ret[] = new Object[2];
        ret[0] = toInteger(result.get("count"));
        List items = new ArrayList();
        ret[1] = items;
        for(int i = 1; result.containsKey("item" + String.valueOf(i)); i++) {
            Hashtable obj;
            obj = (Hashtable) result.get("item" + String.valueOf(i));
            ContentItem item = parseContentItem(obj);
            items.add(item);
        }
        return(ret);
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   list items in the registry for Pagination  //////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    class ListcntComp implements Comparator {
  public final int REGTIME = 0;
  public final int MODTIME = 1;
  public final int PRICE = 3;
  public final int EXPIRES = 4;
  public final int PATH = 5;
  public final int LINK_TXT = 6;
  int method;
  int reverse = 0;
  public ListcntComp(String sort, boolean reverse) {
      this.reverse = reverse ? -1 : 1;
      if(sort.equals(LIST_CONTENT_SORT_MODTIME)) {
    method = MODTIME;
      } else if(sort.equals(LIST_CONTENT_SORT_PRICE)) {
    method = PRICE;
      } else if(sort.equals(LIST_CONTENT_SORT_EXPIRES)) {
    method = EXPIRES;
      } else if(sort.equals(LIST_CONTENT_SORT_PATH)) {
    method = PATH;
      } else if(sort.equals(LIST_CONTENT_SORT_LINK_TXT)) {
    method = LINK_TXT;
      } else { //if(sort.equals(LIST_CONTENT_SORT_REGTIME)) {
    //regtime is default
    method = REGTIME;
      }
  }
  public int compare(Object o1, Object o2) {
      int ret = 0;
      switch(method) {
      case MODTIME:
      case REGTIME:
    return(0);
      case PRICE:
    return(((ContentItem) o1).get_price().compareTo(((ContentItem) o2).get_price()) * reverse);
      case EXPIRES:
    ret = ((ContentItem) o1).get_exp_d().compareTo(((ContentItem) o2).get_exp_d());
    if(ret == 0) { ret = ((ContentItem) o1).get_exp_h().compareTo(((ContentItem) o2).get_exp_h()); }
    else { return(ret * reverse); }
    if(ret == 0) { ret = ((ContentItem) o1).get_exp_m().compareTo(((ContentItem) o2).get_exp_m()); }
    return(ret * reverse);
      case PATH:
    return(((ContentItem) o1).get_path().compareTo(((ContentItem) o2).get_path()) * reverse);
      case LINK_TXT:
    return(((ContentItem) o1).get_linktxt().compareTo(((ContentItem) o2).get_linktxt()) * reverse);
      }
      return ret;
  }
  public boolean equals(Object obj) {
      return false;
  }
    }

    /**
     * Returns an empty array if start is beyond end.
     * Returns entire list if either start or numrecords is less than 0 or NULL.
     */
    public Object[] listcnt( String account, String show, String sort, Integer dir, Integer start, Integer numrecords ) throws BitPassAdapterException {

        Object[] ret = listcnt( account );
  List items = (List) ret[1];

  // sort:
  Object[] temp = new Object[items.size()];
  items.toArray(temp);
  Arrays.sort(temp, new ListcntComp(sort, LIST_CONTENT_ORDER_DESC.equals(dir)));
  items = new ArrayList();
  for(int i = 0; i < temp.length; i++)
      items.add(temp[i]);
 
  if(LIST_CONTENT_ORDER_ASC.equals(dir) &&
     (sort.equals(LIST_CONTENT_SORT_MODTIME) || sort.equals(LIST_CONTENT_SORT_REGTIME))) {
      // we can't do these, so we have to do a manual reverse
      List newitems = new ArrayList();
      for(int i = items.size() - 1; i >= 0; i--)
    newitems.add(items.get(i));
      items = (List) newitems;
  }
  // remove everything which is not shown:
  if(show.equals(LIST_CONTENT_SHOW_PUBLISHED)) {
      Iterator i = items.iterator();
      while(i.hasNext()) {
    ContentItem item = (ContentItem) i.next();
    if(item.get_stat().intValue() < 1) {
        i.remove();
    }
      }
  } else if(show.equals(LIST_CONTENT_SHOW_PREVIEW)) {
      Iterator i = items.iterator();
      while(i.hasNext()) {
    ContentItem item = (ContentItem) i.next();
    if(item.get_stat().intValue() > 0) {
        i.remove();
    }
      }
  } else if(show.equals(LIST_CONTENT_SHOW_ENABLED)) {
      Iterator i = items.iterator();
      while(i.hasNext()) {
    ContentItem item = (ContentItem) i.next();
    if(item.get_available().intValue() < 1) {
        i.remove();
    }
      }
  } else if(show.equals(LIST_CONTENT_SHOW_DISABLED)) {
      Iterator i = items.iterator();
      while(i.hasNext()) {
    ContentItem item = (ContentItem) i.next();
    if(item.get_available().intValue() > 0) {
        i.remove();
    }
      }
  }
  // otherwise show all

  Integer count = new Integer(items.size())
 
        try {

            int beg = start.intValue();
            if( beg >= count.intValue() ) return new Object[] { count, new ArrayList() }; // Return an empty array if start is beyond end.
            int end = beg + numrecords.intValue();
            if( beg < 0 || end < beg ) return new Object[] { count, items }; // Return entire array if either start or numrecords is less than 0.
            if( end > count.intValue() ) end = count.intValue();

            // Done.
            return new Object[] { count, new ArrayList( items.subList( beg, end ) ) };

        } catch( NullPointerException e ) {

            return new Object[] { count, items };

        }

    }

    // This is the version we should eventually be using:
    public Object[] listcnt( Account account, String show, String sort, Integer dir, Integer start, Integer numrecords ) throws BitPassAdapterException {
        String s_account = ":" + account.get_p_id().toString() + "::::";
    return listcnt(s_account, show, sort, dir, start, numrecords);
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   list Reference items in the registry  ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

//     public ArrayList listref( String pubid, String passwd ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         args.addElement( struct );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( "listref", args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         //
//         if( result != null && result instanceof Hashtable ) {
//             logger.debug( result.toString() );

//             Object obj;
//             ReferralItem item;
//             String key;
//             for( Iterator i = ( (Hashtable)result ).values().iterator(); i.hasNext(); ) {
//                 obj = i.next();
//                 if( obj instanceof Hashtable ) {
//                     item=new ReferralItem();
//                     ret.add( item );

//                     for( Iterator j = ( (Hashtable)obj ).keySet().iterator(); j.hasNext(); ) {
//                         key = (String)j.next();
//                         if( key.equals( "MAX_CLK" ) ) {
//                             item.set_max_clk( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         } else if( key.equals( "PRICE" ) ) {
//                             item.set_price( toDouble( ( (Hashtable)obj ).get( key ) ) );
//                         } else if( key.equals( "I_ID" ) ) {
//                             item.set_i_id( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "REF_URL" ) ) {
//                             item.set_ref( toString( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "ICON_SET" ) ) {
//                             item.set_iconset( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "LINK_TXT" ) ) {
//                             item.set_linktxt( toString( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "EXPIRES" ) ) {
//                             int time = toInteger(((Hashtable) obj).get(key)).intValue(); // Total Minutes
//                             item.set_exp_m(new Integer(time % 60));
//                             time -= time % 60;
//                             time /= 60; // Total Hours
//                             item.set_exp_h(new Integer(time % 24));
//                             time -= time % 24;
//                             time /= 24; // Total Days
//                             item.set_exp_d(new Integer(time));
//                         }else if( key.equals( "IDSTR" ) ) {
//                             item.set_idstr( toString( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "ENABLED" ) ) {
//                             item.set_available( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "STATUS" ) ) {
//                             item.set_stat( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         }
//                     }
//                 }
//             }

//         } else {
//             logger.warn( "Received null or non-hashtable result in listref." );
//         }

//         // Done.
//         return ret;
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   list Donation items in the registry   ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

//     public ArrayList listdnt( String pubid, String passwd ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         args.addElement( struct );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( "listdnt", args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         //
//         if( result != null && result instanceof Hashtable ) {
//             logger.debug( result.toString() );

//             Object obj;
//             DonationItem item;
//             String key;
//             for( Iterator i = ( (Hashtable)result ).values().iterator(); i.hasNext(); ) {
//                 obj = i.next();
//                 if( obj instanceof Hashtable ) {
//                     item = new DonationItem();
//                     ret.add( item );
//                     for( Iterator j = ( (Hashtable)obj ).keySet().iterator(); j.hasNext(); ) {
//                         key = (String)j.next();
//                         if( key.equals( "MAX_CLK" ) ) {
//                             item.set_max_clk( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         } else if( key.equals( "PRICE" ) ) {
//                             item.set_price( toDouble( ( (Hashtable)obj ).get( key ) ) );
//                         } else if( key.equals( "I_ID" ) ) {
//                             item.set_i_id( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "PATH" ) ) {
//                             item.set_path( toString( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "ICON_SET" ) ) {
//                             item.set_iconset( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "LINK_TXT" ) ) {
//                             item.set_linktxt( toString( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "EXPIRES" ) ) {
//                             int time = toInteger(((Hashtable) obj).get(key)).intValue(); // Total Minutes
//                             item.set_exp_m(new Integer(time % 60));
//                             time -= time % 60;
//                             time /= 60; // Total Hours
//                             item.set_exp_h(new Integer(time % 24));
//                             time -= time % 24;
//                             time /= 24; // Total Days
//                             item.set_exp_d(new Integer(time));
//                         }else if( key.equals( "TOTAL" ) ) {
//                             item.set_total( toDouble( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "ENABLED" ) ) {
//                             item.set_available( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "STATUS" ) ) {
//                             item.set_stat( toInteger( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "GOAL" ) ) {
//                             item.set_goal( toString( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "MIN_AMOUNT" ) ) {
//                             item.set_min_amount( toDouble( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "MAX_AMOUNT" ) ) {
//                             item.set_max_amount( toDouble( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "DESTINATION" ) ) {
//                             item.set_desturl( toString( ( (Hashtable)obj ).get( key ) ) );
//                         }else if( key.equals( "MULTIPLE" ) ) {
//                             item.set_multi( toString( ( (Hashtable)obj ).get( key ) ) );
//                         }
//                     }
//                 }
//             }

//         } else {
//             logger.warn( "Received null or non-hashtable result in listdnt." );
//         }

//         // Done.
//         return ret;
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   view items in the registry   ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public ContentItem viewcnt( String account, String i_id ) throws BitPassAdapterException {

        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "i_id", i_id );

        // Make the connection.
        Hashtable result = callXmlRpc("view-content", args);

        // remove the RESULT key
        result.remove("RESULT");

        ContentItem item = parseContentItem(result);
        return(item);
    }

    public ContentItem viewcnt( Account account, String i_id ) throws BitPassAdapterException {
        String s_account = ":" + account.get_p_id().toString() + ":" + "" + ":::" + "";
    return viewcnt(s_account, i_id);
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   view Reference items in the registry  ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

//     public ArrayList viewref( String pubid, String passwd, String i_id ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         struct.put( "i_id", i_id );
//         args.addElement( struct );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( "viewref", args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         //
//         if( result != null && result instanceof Hashtable ) {
//             logger.debug( result.toString() );

//             Object obj;
//             ReferralItem item;
//             item = new ReferralItem();
//             ret.add( item );
//             int j= 0;
//             for( Iterator i = ( (Hashtable)result ).values().iterator(); i.hasNext(); j++) {

//                 obj = i.next();
//                 logger.error(obj.getClass().getName());
//                 switch( j ) {
//                     case 0: item.set_max_clk( toInteger( obj ) ); break;
//                     case 1: item.set_price( toDouble( obj ) ); break;
//                     case 2: item.set_i_id( toInteger( obj ) ); break;
//                     case 3: item.set_ref( toString( obj ) ); break;
//                     case 4: item.set_iconset( toInteger( obj ) ); break;
//                     case 5: item.set_linktxt( toString( obj ) ); break;
//                     case 6: int time = toInteger(obj).intValue(); // Total Minutes
//                         item.set_exp_m(new Integer(time % 60));
//                         time -= time % 60;
//                         time /= 60; // Total Hours
//                         item.set_exp_h(new Integer(time % 24));
//                         time -= time % 24;
//                         time /= 24; // Total Days
//                         item.set_exp_d(new Integer(time));
//                         item.set_exp_h( toInteger( obj ) );
//                         break;
//                     case 7: item.set_idstr( toString( obj ) ); break;
//                     case 8: item.set_available( toInteger( obj ) ); break;
//                     case 9: item.set_stat( toInteger( obj ) ); break;
//                 }
//             }

//         } else {
//             logger.warn( "Received null or non-hashtable result in viewref." );
//         }

//         // Done.
//         return ret;
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   list Donation items in the registry   ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

//     public ArrayList viewdnt( String pubid, String passwd, String i_id ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         struct.put( "i_id", i_id );
//         args.addElement( struct );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( "viewdnt", args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         //
//         if( result != null && result instanceof Hashtable ) {
//             logger.debug( result.toString() );

//             Object obj;
//             DonationItem item;
//             item = new DonationItem();
//             ret.add( item );
//             int j = 0;
//             for( Iterator i = ( (Hashtable)result ).values().iterator(); i.hasNext(); j++) {

//                 obj = i.next();
//                 logger.error(obj.getClass().getName());

//                 switch( j ) {
//                     case 0: item.set_max_clk( toInteger( obj ) ); break;
//                     case 1: item.set_price( toDouble( obj ) ); break;
//                     case 2: item.set_i_id( toInteger( obj ) ); break;
//                     case 3: item.set_path( toString( obj ) ); break;
//                     case 4: item.set_iconset( toInteger( obj ) ); break;
//                     case 5: item.set_linktxt( toString( obj ) ); break;
//                     case 6: int time = toInteger(obj).intValue(); // Total Minutes
//                         item.set_exp_m(new Integer(time % 60));
//                         time -= time % 60;
//                         time /= 60; // Total Hours
//                         item.set_exp_h(new Integer(time % 24));
//                         time -= time % 24;
//                         time /= 24; // Total Days
//                         item.set_exp_d(new Integer(time));
//                         item.set_exp_h( toInteger( obj ) );
//                         break;
//                     case 7: item.set_total( toDouble( obj ) ); break;
//                     case 8: item.set_available( toInteger( obj ) ); break;
//                     case 9: item.set_stat( toInteger( obj ) ); break;
//                     case 10: item.set_goal( toString( obj ));  break;
//                     case 11: item.set_min_amount( toDouble( obj ));  break;
//                     case 12: item.set_max_amount( toDouble( obj ));  break;
//                     case 13: item.set_desturl( toString( obj ));  break;
//                     case 14: item.set_multi( toString( obj ));  break;
//                 }
//             }

//         } else {
//             logger.warn( "Received null or non-hashtable result in viewdnt." );
//         }

//         // Done.
//         return ret;
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   delete the item from the registry   ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Integer delcnt( String account, String i_id ) throws BitPassAdapterException {

        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "i_id", i_id );

        // Make the connection.
        Hashtable result = callXmlRpc("delete-item", args);

        return (Integer) result.get("RESULT");
    }

    public Integer delcnt(Account account, String i_id) throws BitPassAdapterException {
        String s_account = ":" + account.get_p_id().toString() + "::::";
    return delcnt(s_account, i_id);
    }
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   delete the Reference item from the registry   ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

//     public Integer delref( String pubid, String passwd,String i_id ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         struct.put( "i_id", i_id );
//         args.addElement( struct );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( "delref", args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         //
//         if( result != null && result instanceof Hashtable ) {
//             logger.debug( result.toString() );

//             Object obj;
//             ReferralItem item;
//             item= new ReferralItem();
//             ret.remove( item );
//             return new Integer("1");
//         } else {
//             logger.warn( "Received null or non-hashtable result in delref." );
//             return new Integer("0");
//         }

//         // Done.
//         //return ret;
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////   delete the Donation item from the registry   ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

//     public Integer deldnt( String pubid, String passwd,String i_id ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         struct.put( "i_id", i_id );
//         args.addElement( struct );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( "deldnt", args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         //
//         if( result != null && result instanceof Hashtable ) {
//             logger.debug( result.toString() );

//             Object obj;
//             DonationItem item;
//             item= new DonationItem();
//             ret.remove( item );
//             return new Integer("1");
//         } else {
//             logger.warn( "Received null or non-hashtable result in deldnt." );
//             return new Integer("0");
//         }

//         // Done.
//         //return ret;
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////  Add/edit item from the registry   //////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Integer addcnt( Account account, ContentItem item ) throws BitPassAdapterException {
        String s_account = ":" + account.get_p_id().toString() + "::::";
    return addcnt(s_account, item);
    }
    public Integer addcnt( String account, ContentItem item ) throws BitPassAdapterException {
        return addcnt(
            account,
            toString( item.get_path(), null ),
            toString( item.get_linktxt(), null ),
            toString( item.get_name(), null ),
            toString( item.get_price(), null ),
            toString( item.get_iconset(), null ),
            toString( item.get_icon_align(), null ),
            toString( item.get_exp_d(), null ),
            toString( item.get_exp_h(), null ),
            toString( item.get_exp_m(), null ),
            toString( item.get_max_clk(), null ),
            toString( item.get_cssurl(), null ),
            toString( item.get_preview(), null ),
            toString( item.get_target(), null ),
            toString( item.get_available(), null ),
            toString( item.get_licensecode(), null ),
            toString( item.get_incqstr(), null ),
            toString( item.get_currency(), null )
        );
    }

    public Integer updatecnt( Account account, ContentItem item ) throws BitPassAdapterException {
        String s_account = ":" + account.get_p_id().toString() + "::::";
    return updatecnt(s_account, item);
    }

    public Integer updatecnt( String account, ContentItem item ) throws BitPassAdapterException {
        return updatecnt(
            account,
            toString( item.get_i_id(), null ),
            toString( item.get_path(), null ),
            toString( item.get_linktxt(), null ),
            toString( item.get_name(), null ),
            toString( item.get_price(), null ),
            toString( item.get_iconset(), null ),
            toString( item.get_icon_align(), null ),
            toString( item.get_exp_d(), null ),
            toString( item.get_exp_h(), null ),
            toString( item.get_exp_m(), null ),
            toString( item.get_max_clk(), null ),
            toString( item.get_cssurl(), null ),
            toString( item.get_preview(), null ),
            toString( item.get_target(), null ),
            toString( item.get_available(), null ),
            toString( item.get_licensecode(), null ),
            toString( item.get_stat(), null ),
            toString( item.get_incqstr(), null ),
            toString( item.get_currency(), null )
        );
    }

    public Integer addcnt(
        String account,
        String path,
        String linktxt,
        String name,
        String price,
        String iconset,
        String icon_align,
        String exp_d,
        String exp_h,
        String exp_m,
        String max_clk,
        String cssurl,
        String preview,
        String target,
        String available,
        String licensecode,
        String incqstr,
        String currency
    ) throws BitPassAdapterException {
        return _AddUpdateContent(
            "add-content",
            account,
            null,
            path,
            linktxt,
            name,
            price,
            iconset,
            icon_align,
            exp_d,
            exp_h,
            exp_m,
            max_clk,
            cssurl,
            preview,
            target,
            toString(available, "0"),
            licensecode,
            null,
            toString(incqstr, "0"),
            currency
        );
    }

    public Integer updatecnt(
        String account,
        String i_id,
        String path,
        String linktxt,
        String name,
        String price,
        String iconset,
        String icon_align,
        String exp_d,
        String exp_h,
        String exp_m,
        String max_clk,
        String cssurl,
        String preview,
        String target,
        String available,
        String licensecode,
        String stat,
        String incqstr,
        String currency
    ) throws BitPassAdapterException {
        return _AddUpdateContent(
            "update-content",
            account,
            i_id,
            path,
            linktxt,
            name,
            price,
            iconset,
            icon_align,
            exp_d,
            exp_h,
            exp_m,
            max_clk,
            cssurl,
            preview,
            target,
            toString(available, "0"),
            licensecode,
            stat,
            toString(incqstr, "0"),
            currency
        );
    }

    private Integer _AddUpdateContent(
        String cmd,
        String account,
        String i_id,
        String path,
        String linktxt,
        String name,
        String price,
        String iconset,
        String icon_align,
        String exp_d,
        String exp_h,
        String exp_m,
        String max_clk,
        String cssurl,
        String preview,
        String target,
        String available,
        String licensecode,
        String stat,
        String incqstr,
        String currency
    ) throws BitPassAdapterException {

        ArrayList ret = new ArrayList();

        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        if(i_id != null) args.put( "i_id", i_id );
        if(path != null) args.put( "path", path );
        if(linktxt != null) args.put( "linktxt", linktxt );
        if(name != null) args.put( "name", name );
        if(price != null) args.put( "price", price );
        if(iconset != null) args.put( "iconset", iconset );
        if(icon_align != null) args.put( "icon_align", icon_align );
        if(exp_d != null) args.put( "exp_d", exp_d );
        if(exp_h != null) args.put( "exp_h", exp_h );
        if(exp_m != null) args.put( "exp_m", exp_m );
        if(max_clk != null) args.put( "max_clk", max_clk );
        if(cssurl != null) args.put( "cssurl", cssurl );
        if(preview != null) args.put( "preview", preview );
        if(target != null) args.put( "target", target );
        if(available != null) args.put( "available", available );
        if(licensecode != null) args.put( "licensecode", licensecode );
        if(stat != null) args.put( "stat", stat );
        if(incqstr != null) args.put( "incqstr", incqstr );
        if(currency != null) args.put( "currency", currency );

        // Make the connection.
        Hashtable result = callXmlRpc( cmd, args );

        return((Integer) (((Hashtable) result).get("RESULT")));

    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////   Add / Edit the Referral item from the registry   /////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

// public Integer addref( String pubid, String passwd, ReferralItem item ) throws BitPassAdapterException {

//         return addref( pubid, passwd,  toString( item.get_ref(), null ), toString( item.get_name(), null ), toString( item.get_price(), null ),
//             toString( item.get_iconset(), null ), toString( item.get_icon_align(), null ), toString( item.get_exp_d(), null ),
//             toString( item.get_exp_h(), null ), toString( item.get_exp_m(), null ), toString( item.get_max_clk(), null ),
//             toString( item.get_linktxt(), null ), toString( item.get_cssurl(), null ), toString( item.get_target(), null ) );
//     }

// public Integer updateref( String pubid, String passwd, ReferralItem item ) throws BitPassAdapterException {

//         return updateref( pubid, passwd, toString( item.get_i_id(), null ), toString( item.get_ref(), null ), toString( item.get_name(), null ),
//             toString( item.get_price(), null ), toString( item.get_iconset(), null ), toString( item.get_icon_align(), null ),
//             toString( item.get_exp_d(), null ), toString( item.get_exp_h(), null ), toString( item.get_exp_m(), null ),
//             toString( item.get_max_clk(), null ), toString( item.get_linktxt(), null ), toString( item.get_cssurl(), null ),
//             toString( item.get_target(), null ), toString( item.get_available(), null ), toString( item.get_stat(), null )  );
//     }

// public Integer addref( String pubid, String passwd, String ref, String name, String price, String iconset, String icon_align, String exp_d,                                     String exp_h, String exp_m, String max_clk, String linktxt, String cssurl, String target ) throws                                                                    BitPassAdapterException {

//      return _AddUpdateContent( "addref", pubid,  passwd, null, ref, name, price, iconset, icon_align, exp_d, exp_h, exp_m,
//             max_clk, linktxt, cssurl, target, null, null );
//     }

// public Integer updateref( String pubid, String passwd, String i_id, String ref, String name, String price, String iconset, String icon_align, String exp_d, String exp_h, String exp_m, String max_clk, String linktxt, String cssurl, String target, String available, String stat ) throws BitPassAdapterException {

//      return _AddUpdateContent( "updateref", pubid, passwd, i_id, ref, name, price, iconset, icon_align, exp_d, exp_h, exp_m,
//             max_clk, linktxt, cssurl, target, available, stat );
//     }

// private Integer _AddUpdateContent( String cmd, String pubid, String passwd, String i_id, String ref, String name, String price,
// String iconset, String icon_align, String exp_d, String exp_h, String exp_m, String max_clk, String linktxt, String cssurl, String target, String available, String stat ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         if(i_id != null) struct.put( "i_id", i_id );
//         if(ref != null) struct.put( "ref", ref );
//         if(name != null) struct.put( "name", name );
//         if(price != null) struct.put( "price", price );
//         if(iconset != null) struct.put( "iconset", iconset );
//         if(icon_align != null) struct.put( "icon_align", icon_align );
//         if(exp_d != null) struct.put( "exp_d", exp_d );
//         if(exp_h != null) struct.put( "exp_h", exp_h );
//         if(exp_m != null) struct.put( "exp_m", exp_m );
//         if(max_clk != null) struct.put( "max_clk", max_clk );
//         if(linktxt != null) struct.put( "linktxt", linktxt );
//      if(cssurl != null) struct.put( "cssurl", cssurl );
//         if(target != null) struct.put( "target", target );
//         if(available != null) struct.put( "available", available ); else struct.put( "available", "0" );
//         if(stat != null) struct.put( "stat", stat ); else struct.put( "stat", "0" );

//         args.addElement( struct );

//         logger.info( args );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( cmd, args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         Integer integer;
//         if( result != null && result instanceof Hashtable ) {
//             return((Integer) (((Hashtable) result).get("RESULT")));
//         } else {
//             logger.warn( "Received null or non-hashtable result in addcnt." );
//             return new Integer("0");
//         }
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////   Add /Edit the Donation item from the registry  ///////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

// public Integer adddnt( String pubid, String passwd, DonationItem item ) throws BitPassAdapterException {

//         return adddnt( pubid, passwd, toString( item.get_path(), null ), toString( item.get_linktxt(), null ), toString( item.get_amount(), null ), toString( item.get_goal(), null ), toString( item.get_min_amount(), null ), toString( item.get_max_amount(), null ), toString( item.get_exp_d(), null ), toString( item.get_exp_h(), null ), toString( item.get_exp_m(), null ), toString( item.get_max_clk(), null ),
//         toString( item.get_desturl(), null ), toString( item.get_target(), null ), toString( item.get_multi(), null ), toString( item.get_available(), null ) );
//     }

// public Integer updatednt( String pubid, String passwd, DonationItem item ) throws BitPassAdapterException {

//         return updatednt( pubid, passwd, toString( item.get_i_id(), null ), toString( item.get_path(), null ), toString( item.get_linktxt(), null ), toString( item.get_amount(), null ), toString( item.get_goal(), null ), toString( item.get_min_amount(), null ), toString( item.get_max_amount(), null ), toString( item.get_exp_d(), null ), toString( item.get_exp_h(), null ), toString( item.get_exp_m(), null ),
//         toString( item.get_max_clk(), null )  );
//     }

// public Integer adddnt( String pubid, String passwd, String path, String linktxt, String amount, String goal, String min_amount, String max_amount, String exp_d, String exp_h, String exp_m, String max_clk,String desturl, String target, String multi, String available ) throws BitPassAdapterException {

//      return _AddUpdateDonation( "addref", pubid,  passwd, null, path, linktxt, amount, goal, min_amount, max_amount, exp_d, exp_h, exp_m, max_clk, desturl, target, multi, available );
//     }

// public Integer updatednt( String pubid, String passwd, String i_id, String path, String linktxt, String amount, String goal, String min_amount, String max_amount, String exp_d, String exp_h, String exp_m, String max_clk ) throws BitPassAdapterException {

//      return _AddUpdateDonation( "updatednt", pubid, passwd, i_id, path, linktxt, amount, goal, min_amount, max_amount, exp_d, exp_h, exp_m, max_clk, null, null, null,null );
//     }

// private Integer _AddUpdateDonation( String cmd, String pubid, String passwd, String i_id, String path, String linktxt, String amount, String goal, String min_amount, String max_amount, String exp_d, String exp_h, String exp_m, String max_clk, String desturl, String target, String multi, String available ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         if(i_id != null) struct.put( "i_id", i_id );
//         if(path != null) struct.put( "path", path );
//         if(linktxt != null) struct.put( "linktxt", linktxt );
//         if(amount != null) struct.put( "amount", amount );
//         if(goal != null) struct.put( "goal", goal );
//         if(min_amount != null) struct.put( "min_amount", min_amount );
//         if(max_amount != null) struct.put( "max_amount", max_amount );
//         if(exp_d != null) struct.put( "exp_d", exp_d );
//         if(exp_h != null) struct.put( "exp_h", exp_h );
//         if(exp_m != null) struct.put( "exp_m", exp_m );
//         if(max_clk != null) struct.put( "max_clk", max_clk );
//      if(desturl != null) struct.put( "desturl", desturl );
//         if(target != null) struct.put( "target", target );
//         if(multi != null) struct.put( "multi", multi ); else struct.put( "multi", "0" );
//      if(available != null) struct.put( "available", available ); else struct.put( "available", "0" );


//         args.addElement( struct );

//         logger.info( args );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( cmd, args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         Integer integer;
//         if( result != null && result instanceof Hashtable ) {
//             return((Integer) (((Hashtable) result).get("RESULT")));
//         } else {
//             logger.warn( "Received null or non-hashtable result in addcnt." );
//             return new Integer("0");
//         }
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////  List Complaints   ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public String parseReasonCode(Integer code) {
  switch (code.intValue()) {
  case 0:
      return "Didn't get the content";
  case 1:
      return "Copyright infringement";
  case 2:
      return "False advertisement";
  case 3:
      return "Not Satisfied";
  case 4:
      return "Didn't purchase";
  case 10:
      return "Other";
  default:
      logger.info("Found unknown dispute reason code: " + code.toString());
      return "Other";
  }
    }

    public String parseStatusCode(Integer code) {
  switch (code.intValue()) {
  case 0:
      return "PENDING";
  case 1:
      return "REFUNDED";
  case 2:
      return "RENEWED";
  case 10:
      return "REFUSED";
  case 20:
      return "CLOSED";
  default:
      logger.info("Found unknown dispute status code: " + code.toString());
      return "PENDING";
  }
    }

    public Object[] getdisputes(String account, String status, String limit_offset, String limit, String from, String to, String sort, String direction) throws BitPassAdapterException {
  // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
  args.put( "from", from );
  args.put( "to", to );
  args.put( "limit", limit );
  args.put( "limit_offset", limit_offset );
  args.put( "sortby", sort );
  args.put( "sortdirection", direction );
  if(status != null) args.put( "status", status );

        // Make the connection.
        Hashtable result = callXmlRpc("list-disputes", args);

  List cplist = new ArrayList();
  Vector items = (Vector) result.get("disputes");
        for(int i = 0; i < items.size(); i++) {
            Hashtable obj;
            obj = (Hashtable) items.get(i);
      Complaint complaint = new Complaint();
      complaint.set_request_time(parseDate(toString(obj.get("RTIME"))));
      complaint.set_txn(new Transaction());
      complaint.get_txn().set_amount(toDouble(obj.get("AMOUNT")));
      complaint.get_txn().set_currency(toString(obj.get("CURRENCY")));
      complaint.set_item(new ContentItem());
      ((ContentItem) complaint.get_item()).set_name(toString(obj.get("NAME")));
      // price really doesn't make sense any other way; still set it for compatability, though.
      ((ContentItem) complaint.get_item()).set_price(complaint.get_txn().get_amount());
      ((ContentItem) complaint.get_item()).set_currency(complaint.get_txn().get_currency());     
      ((ContentItem) complaint.get_item()).set_linktxt(toString(((Hashtable) ((Hashtable) obj.get("CONTEXT")).get("ITEM")).get("LINK_TXT")));
      complaint.set_reason(parseReasonCode(toInteger(obj.get("REASON"))));
      complaint.set_message(toString(obj.get("MSG")));
      complaint.set_cpid(toInteger(obj.get("D_ID")));
      complaint.set_status(parseStatusCode(toInteger(obj.get("STATUS"))));
      cplist.add(complaint);
        }
  return new Object[] { toInteger(result.get("total_disputes")), cplist };
    }

    public Object[] listcp(Account account, String show, String sort, Integer dir,
                       Integer start, Integer numrecords, String from, String to) throws BitPassAdapterException {
  String s_account = ":" + account.get_p_id() + "::::";
  String s_show = null;
  if(show.equals("pending")) {
      s_show = "0";
  } else if(show.equals("refunded")) {
      s_show = "1";
  } else if(show.equals("renewed")) {
      s_show = "2";
  } else if(show.equals("refused")) {
      s_show = "10";
  } else if(show.equals("closed")) {
      s_show = "20";
  } else if(show.equals("all")) {
      s_show = null;
  }
  if(from.equals("")) from = "2003/06/23"; // Magic date
  if(to.equals("")) {
      Calendar calendar = new GregorianCalendar();
      calendar.setTime(new Date());
      to = unparseDate(new Integer(calendar.get(Calendar.YEAR)),
           new Integer(calendar.get(Calendar.MONTH) + 1),
           new Integer(calendar.get(Calendar.DAY_OF_MONTH)));
  }
        return getdisputes(s_account, s_show, toString(start), toString(numrecords), from, to, sort, dir.intValue() > 0 ? "ASC" : "DESC" );
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////  View Complaint   /////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Complaint viewcp(String account, String cpid) throws BitPassAdapterException {
  // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
  args.put( "d_id", cpid );

        // Make the connection.
        Hashtable result = callXmlRpc("get-dispute", args);
  result = (Hashtable) result.get("dispute");

        Complaint complaint = new Complaint();
        complaint.set_txn(new Transaction());
        complaint.get_txn().set_purchase_type(toString(result.get("ITEM_TYPE")));
        complaint.get_txn().set_txntime(
      parseDate(toString(((Hashtable) ((Hashtable) result.get("CONTEXT")).get("OFFER")).get("TIME_CREATED")))
  );
        complaint.get_txn().set_amount(toDouble(result.get("AMOUNT")));
  complaint.get_txn().set_currency(toString(result.get("CURRENCY")));
        complaint.set_s_email(toString(result.get("USRID")));
        complaint.set_item(new ContentItem());
        ((ContentItem) complaint.get_item()).set_name(toString(result.get("NAME")));
        ((ContentItem) complaint.get_item()).set_price(
      toDouble(((Hashtable) ((Hashtable) result.get("CONTEXT")).get("ITEM")).get("PRICE"))
  );
        ((ContentItem) complaint.get_item()).set_currency(
      toString(((Hashtable) ((Hashtable) result.get("CONTEXT")).get("ITEM")).get("CURRENCY"))
  );

        complaint.set_pass_issued(parseDate(toString(result.get("TIME_ISSUE"))));
        complaint.set_visit_time(parseDate(toString(result.get("LAST_VISIT"))));
        complaint.set_visit_number(toInteger(result.get("CLK_CNT")));
        complaint.set_visit_allowed(
      toInteger(((Hashtable) ((Hashtable) result.get("CONTEXT")).get("ITEM")).get("MAX_CLK"))
  );
  if(complaint.get_visit_number().intValue() > complaint.get_visit_allowed().intValue()) {
      complaint.set_pass_expired(new Boolean(true));
  } else if(parseDate(toString(result.get("TIME_EXPIRE"))).getTime() < (new Date()).getTime() ) {
      complaint.set_pass_expired(new Boolean(true));
  } else {
      complaint.set_pass_expired(new Boolean(false));
  }
        complaint.set_request_time(parseDate(toString(result.get("RTIME"))));
        complaint.set_reason(parseReasonCode(toInteger(result.get("REASON"))));
        complaint.set_request(toInteger(result.get("REQUEST")));
        complaint.set_message(toString(result.get("MSG")));
        complaint.set_status(parseStatusCode(toInteger(result.get("STATUS"))));
  if(! complaint.get_status().equals("PENDING")) {
      complaint.set_response(toString(result.get("RSP")));
      complaint.set_response_time(parseDate(toString(result.get("TIME_RSP"))));
  }
        complaint.get_txn().set_refunded(new Boolean(complaint.get_status().equals("REFUNDED")));

        return complaint;
    }

    public Complaint viewcp(Account account, Integer cpid) throws BitPassAdapterException {
  String s_account = ":" + account.get_p_id() + "::::";
  return viewcp(s_account, cpid.toString());
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////  Resolve Complaint   //////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Integer resolvecp(String account, String cpid, String action, String msg, String session) throws BitPassAdapterException {
        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "d_id", cpid );
        args.put( "action", action );
        args.put( "msg", msg );
        args.put( "session", session );

        // Make the connection.
        Hashtable result = callXmlRpc("process-complaint", args);
        return(toInteger(result.get("RESULT")));
    }

    public Integer resolvecp(Account account, Integer cpid, String action, String message) throws BitPassAdapterException {
        logger.info("{ cpid = " + cpid.toString() + ", action = " + action + ", message = " + message + "}");
        String s_account = ":" + account.get_p_id().toString() + "::::";
        String i_action;
        if(action.equals("CLOSE")) {
            i_action = "20";
        } else if(action.equals("REFUSE")) {
            i_action = "10";
        } else if(action.equals("REFUND")) {
            i_action = "1";
        } else {
            throw new BitPassAdapterException("Value for action is invalid.");
        }
        return resolvecp(s_account, toString(cpid), i_action, message, "DUMMY SESSION");
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////  Site Information   ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Integer siteinfo( Account account, Site site ) throws BitPassAdapterException {
  String s_account = ":" + account.get_p_id() + "::::";
        return siteinfo(s_account,
      site.get_name(),
      site.get_description(),
      site.get_url(),
      "1");
    }

    public Integer siteinfo( String account, String name, String descr, String url, String available) throws BitPassAdapterException {

        ArrayList ret = new ArrayList();

        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "name", name );
        args.put( "descr", descr );
        args.put( "url", url );
        args.put( "available", available );

  Hashtable result = callXmlRpc("update-siteinfo", args);
 
  return toInteger(result.get("RESULT"));
    }


//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  Get Site Information   /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Site getsiteinfo( String account ) throws BitPassAdapterException {

        Site ret = new Site();

        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );

        // Make the connection.
        Hashtable result = callXmlRpc( "get-siteinfo", args );

        result.remove("RESULT");
        for(Iterator j = result.keySet().iterator(); j.hasNext();) {
            String key = (String)j.next();
            if(key.equals("url")) {
                ret.set_url(toString(result.get(key)));
            } else if(key.equals("name")) {
                ret.set_name(toString(result.get(key)));
            } else if(key.equals("available")) {
                ret.set_available(toString(result.get(key)).equals("1") ? Boolean.TRUE : Boolean.FALSE);
            } else if(key.equals("descr")) {
                ret.set_description(toString(result.get(key)));
            } else {
                logger.info("Found unexpected key in site hash: " + key);
            }
        }

        return ret;
    }

    public Site getsiteinfo(Account account) throws BitPassAdapterException {
        String s_account = ":" + account.get_p_id().toString() + "::::";
        return getsiteinfo(s_account);
    }


//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  Get Earner Information   ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Earner getearnerinfo( String account ) throws BitPassAdapterException {

        Earner ret = new Earner();

        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );

        // Make the connection.
        Hashtable result = callXmlRpc("get-contact", args);

        result.remove("RESULT");
        for(Iterator j = result.keySet().iterator(); j.hasNext();) {
            String key = (String)j.next();
            if(key.equals("country")) {
                ret.set_country(toString(result.get(key)));
            } else if(key.equals("first")) {
                ret.set_fname(toString(result.get(key)));
            } else if(key.equals("mi")) {
                ret.set_mi(toString(result.get(key)));
            } else if(key.equals("last")) {
                ret.set_lname(toString(result.get(key)));
            } else if(key.equals("title")) {
                ret.set_title(toString(result.get(key)));
            } else if(key.equals("company")) {
                ret.set_company(toString(result.get(key)));
            } else if(key.equals("addr1")) {
                ret.set_address1(toString(result.get(key)));
            } else if(key.equals("addr2")) {
                ret.set_address2(toString(result.get(key)));
            } else if(key.equals("addr3")) {
                ret.set_address3(toString(result.get(key)));
            } else if(key.equals("city")) {
                ret.set_city(toString(result.get(key)));
            } else if(key.equals("postal")) {
                ret.set_postal(toString(result.get(key)));
            } else if(key.equals("province")) {
                ret.set_province(toString(result.get(key)));
            } else if(key.equals("country")) {
                ret.set_country(toString(result.get(key)));
            } else if(key.equals("phone")) {
                ret.set_phone(toString(result.get(key)));
            } else {
                logger.info("Found unexpected key in earner hash: " + key);
            }
        }

        return ret;
    }

    public Earner getearnerinfo(Account account) throws BitPassAdapterException {
        String s_account = ":" + account.get_p_id().toString() + "::::";
        return getearnerinfo(s_account);
    }

    public Integer updatecontact(String account,
                                 String name_f,
                                 String name_l,
                                 String name_m,
                                 String title,
                                 String company,
                                 String addr1,
                                 String addr2,
                                 String city,
                                 String state,
                                 String zip,
                                 String phone,
                                 String country) throws BitPassAdapterException {
        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "name_f", name_f );
        args.put( "name_l", name_l );
        args.put( "name_m", name_m );
        args.put( "title", title );
        args.put( "company", company );
        args.put( "addr1", addr1 );
        args.put( "addr2", addr2 );
        args.put( "city", city );
        args.put( "state", state );
        args.put( "zip", zip );
        args.put( "phone", phone );
        args.put( "country", country );

        // Make the connection.
        Hashtable result = callXmlRpc("update-contact", args);

        return new Integer(toString(result.get("RESULT")));
    }

    public Integer earnerinfo(Account account, Earner earner) throws BitPassAdapterException {
        String s_account = ":" + account.get_p_id().toString() + "::::";
        return updatecontact(s_account,
                             toString(earner.get_fname()),
                             toString(earner.get_lname()),
                             toString(earner.get_mi()),
                             toString(earner.get_title()),
                             toString(earner.get_company()),
                             toString(earner.get_address1()),
                             toString(earner.get_address2()),
                             toString(earner.get_city()),
                             toString(earner.get_province()),
                             toString(earner.get_postal()),
                             toString(earner.get_phone()),
                             toString(earner.get_country()));
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  I18nInfo   /////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public I18nInfo getlocalinfo(String account) throws BitPassAdapterException {
  Hashtable args = new Hashtable();
  args.put("account", account);
  Hashtable result = callXmlRpc("get-locale", args);
 
  I18nInfo ret = new I18nInfo();
  ret.set_country(toString(result.get("country")));
  ret.set_timezone(toString(result.get("timezone")));
  ret.set_language(toString(result.get("language")));

  return ret;
    }

    public Integer setlocalinfo(String account, String country, String language, String timezone) throws BitPassAdapterException {
  Hashtable args = new Hashtable();
  args.put("account", account);
  args.put("country", country);
  args.put("language", language);
  args.put("timezone", timezone);
  Hashtable result = callXmlRpc("set-locale", args);
 
  return toInteger(result.get("RESULT"));
    }

    public Integer setcurrency(String account, String currency) throws BitPassAdapterException {
  return new Integer(1);
    }

    public String getcurrency(String account) throws BitPassAdapterException {
  Hashtable args = new Hashtable();
  args.put("account", account);
  Hashtable result = callXmlRpc("get-currency", args);

  return toString(result.get("currency"));
    }

    public I18nInfo geti18ninfo(Account account) throws BitPassAdapterException {
  String s_account = ":" + account.get_p_id().toString() + "::::";
  I18nInfo ret = getlocalinfo(s_account);
  ret.set_currency(getcurrency(s_account));
  return ret;
    }

    public Integer seti18ninfo(Account account, I18nInfo info) throws BitPassAdapterException {
  String s_account = ":" + account.get_p_id().toString() + "::::";
  Integer ret = setlocalinfo(s_account,
           info.get_country(),
           info.get_language(),
           toString(info.get_timezone(), "US/Pacific")
           );
  if(ret.intValue() < 1) {
      return ret;
  }
  return setcurrency(s_account, info.get_currency());
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  New Earner   ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Integer newaccnt(String email, String password, String currency) throws BitPassAdapterException {
  Hashtable args = new Hashtable();
  args.put("email0", email);
  args.put("email1", email);
  args.put("pwd0", password);
  args.put("pwd1", password);
  args.put("type", "professional");
  args.put("interface", "1");
  args.put("currency", currency);

  Hashtable result = callXmlRpc("create-account", args);

  return toInteger(result.get("RESULT"))
    }

    public Integer newcontact(String account,
            String name_f,
            String name_l,
            String name_m,
            String title,
            String company,
            String addr1,
            String addr2,
            String city,
            String state,
            String zip,
            String phone,
            String country) throws BitPassAdapterException {
        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "name_f", name_f );
        args.put( "name_l", name_l );
        args.put( "name_m", name_m );
        args.put( "title", title );
        args.put( "company", company );
        args.put( "addr1", addr1 );
        args.put( "addr2", addr2 );
        args.put( "city", city );
        args.put( "state", state );
        args.put( "zip", zip );
        args.put( "phone", phone );
        args.put( "country", country );

        // Make the connection.
        Hashtable result = callXmlRpc("new-contact", args);

        return new Integer(toString(result.get("RESULT")));
    }

    public Integer newearner(Site site, Earner earner, I18nInfo info) throws BitPassAdapterException {
  // make a random password
  String password;
  {
      Random random = new SecureRandom();
      char bytestring[] = new char[7];
      for(int i = 0; i < 7; i++) {
    bytestring[i] = Character.forDigit(random.nextInt(Character.MAX_RADIX), Character.MAX_RADIX); // only 36.  oh well.
      }
      password = new String(bytestring);
  }
  // first create the account
  newaccnt(earner.get_email(), password, info.get_currency());
  // now get the p_id (why is this not returned?!?!?!)
  Integer p_id = authearner(earner.get_email(), password);
  String s_account = ":" + p_id.toString() + "::::";
  Account account = new Account();
  account.set_p_id(p_id);
        newcontact(s_account,
       toString(earner.get_fname()),
       toString(earner.get_lname()),
       toString(earner.get_mi()),
       toString(earner.get_title()),
       toString(earner.get_company()),
       toString(earner.get_address1()),
       toString(earner.get_address2()),
       toString(earner.get_city()),
       toString(earner.get_province()),
       toString(earner.get_postal()),
       toString(earner.get_phone()),
       toString(earner.get_country()));
  siteinfo(account, site);
  seti18ninfo(account, info);
  return p_id;
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  Get Earner Auth   //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    private static final int CSS_INTERFACE = 1;

    public Integer authearner(String pubid, String passwd) throws BitPassAdapterException {

        // Package the args.
        Vector args = new Vector();
        Hashtable struct = new Hashtable();
        struct.put( "pubid", pubid );
        struct.put( "passwd", passwd );

        logger.info("authenticate-earner" + struct.toString());

        args.addElement( struct );

        // Make the connection.
        Hashtable result = null;
        try {
            result = (Hashtable) client.execute( "authenticate-earner", args );
        } catch( XmlRpcException e ) {
            if(e.getMessage().equals("Incorrect password")) {
                return(new Integer(0));
            }
            throw new BitPassAdapterException( e );
        } catch( IOException e ) {
            throw new BitPassAdapterException( e );
        } catch( ClassCastException e ) {
            throw new BitPassAdapterException( e );
        }
        if(result == null) {
            throw new BitPassAdapterException( "Null result from xmlrpc" );
        }

        logger.info(result.toString());

        result.remove("RESULT");
        Integer ret = new Integer(0);
        for(Iterator j = result.keySet().iterator(); j.hasNext();) {
            String key = (String)j.next();
            if(key.equals("interface")) {
                if(Integer.parseInt(toString(result.get(key))) != CSS_INTERFACE) {
                    return(new Integer(0));
                }
            } else if(key.equals("p_id")) {
                ret = new Integer(toString(result.get(key)));
            } else if(key.equals("status")) {
                // Bit field with the the following values:
                // Trap - Hasn't agreed to TOS
                // File Reg - BitPass Studios Customer
                // RPC - Can use RPC
                // Custom Banner - Can use a custom banner
                // n/a
                // n/a
                // n/a
                // n/a
                //
                // n/a
                // n/a
                // n/a
                // n/a
                // n/a
                // Verified - Earner e-mail address has been verified
                // Active - Earner account is active and can sell
                // Login - Earner is allowed to Login
            } else {
                logger.info("Found unexpected key in authearner hash: " + key);
            }
        }
        return ret;
    }


//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  Gateway Information   //////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

//     public Integer gwconfig( String pubid, String passwd, String script, String gate, String basedir, String indexfname, String p3p) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );
//         struct.put( "script", script );
//         struct.put( "gate", gate );
//         struct.put( "basedir", basedir );
//         struct.put( "indexfname", indexfname );
//         struct.put( "p3p", p3p );

//         args.addElement( struct );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( "gwconfig", args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         //
//         if( result != null && result instanceof Hashtable ) {
//             logger.debug( result.toString() );

//             Gateway item;
//             Object obj;
//             item = new Gateway();
//             ret.add( item );
//             int j = 0;

//             for( Iterator i = ( (Hashtable)result ).values().iterator(); i.hasNext(); j++) {
//                 obj = i.next();
//                 logger.error(obj.getClass().getName());

//                 switch( j ) {
//                     case 0: item.set_script( toString( obj ) ); break;
//                     case 1: item.set_gate( toString( obj ) ); break;
//                     case 2: item.set_basedir( toString( obj ) ); break;
//                     case 3: item.set_indexfname( toString( obj ) ); break;
//                     case 4: item.set_p3p( toString( obj ) ); break;
//                 }
//             }
//             return new Integer("1");
//         } else {
//             logger.warn( "Received null or non-hashtable result in gwconfig." );
//             return new Integer("0");
//         }

//         // Done.
//       //  return new Integer("1");
//     }


//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  Get Gateway Information   /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

//     public ArrayList getgwconfig( String pubid, String passwd ) throws BitPassAdapterException {

//         ArrayList ret = new ArrayList();

//         // Package the args.
//         Vector args = new Vector();
//         Hashtable struct = new Hashtable();
//         struct.put( "pubid", pubid );
//         struct.put( "passwd", passwd );

//         args.addElement( struct );

//         // Make the connection.
//         Object result = null;
//         try {
//             result = client.execute( "getgwconfig", args );
//         } catch( XmlRpcException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         } catch( IOException e ) {
//             logger.error( e.toString() );
//             throw new BitPassAdapterException( e );
//         }

//         //
//         if( result != null && result instanceof Hashtable ) {
//             logger.debug( result.toString() );

//             Gateway item;
//             Object obj;
//             item = new Gateway();
//             ret.add( item );
//             int j = 0;

//             for( Iterator i = ( (Hashtable)result ).values().iterator(); i.hasNext(); j++) {
//                 obj = i.next();
//                 logger.error(obj.getClass().getName());

//                 switch( j ) {
//                     case 0: item.set_script( toString( obj ) ); break;
//                     case 1: item.set_gate( toString( obj ) ); break;
//                     case 2: item.set_basedir( toString( obj ) ); break;
//                     case 3: item.set_indexfname( toString( obj ) ); break;
//                     case 4: item.set_p3p( toString( obj ) ); break;
//                 }
//             }
//         } else {
//             logger.warn( "Received null or non-hashtable result in getgwconfig." );
//         }

//         // Done.
//         return ret;
//     }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  Get Sales Summary   ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
// Returns object[0 -> count (Integer), 1->total sales (Double), 2->total transactions (Integer), 3->List (Items), 4->Currency (String)]

    public Object[] fake_ssummary( Account account, String show, String sort, Integer dir, Integer start, Integer numrecords, String from, String to) throws BitPassAdapterException {
        return new Object[] { new Integer( 0 ), new Double( 0.0 ), new Integer( 0 ), new ArrayList(), "USD" };
//        Integer count = new Integer(4);
//        Double total_amount = new Double(24.90);
//        Integer total_count = new Integer(9);
//        List items = new ArrayList();
//        ContentItem item;
//
//        item = new ContentItem();
//        item.set_name("Scars");
//        item.set_i_id(new Integer(136));
//        item.set_price(new Double(0.50));
//        item.set_s_amount(new Double(2.00));
//        item.set_s_cnt(new Integer(4));
//        item.set_deleted(new Boolean(true));
//        items.add(item);
//
//        item = new ContentItem();
//        item.set_name("I am a content name");
//        item.set_i_id(new Integer(122));
//        item.set_price(new Double(2.88));
//        item.set_s_amount(new Double(0.50));
//        item.set_s_cnt(new Integer(2));
//        item.set_deleted(new Boolean(true));
//        items.add(item);
//
//        item = new ContentItem();
//        item.set_name("Ochun");
//        item.set_i_id(new Integer(135));
//        item.set_price(new Double(9.96));
//        item.set_s_amount(new Double(19.90));
//        item.set_s_cnt(new Integer(2));
//        items.add(item);
//
//        item = new ContentItem();
//        item.set_name("bifurcation");
//        item.set_i_id(new Integer(132));
//        item.set_price(new Double(2.50));
//        item.set_s_amount(new Double(2.50));
//        item.set_s_cnt(new Integer(1));
//        items.add(item);
//
//        Object ret[] = { count, total_amount, total_count, items, "USD" };
//        return ret;
    }

    // Returns object[0 -> count (Integer), 1->total sales (Double), 2->total transactions (Integer), 3->List (Items), 4->Currency (String)]
     public Object[] ssummary(String account, String p_id, String start, String numrecords, String from, String to) throws BitPassAdapterException {

         // Package the args.
         Hashtable struct = new Hashtable();
         struct.put( "account", account );
   struct.put( "p_id", p_id );
   struct.put( "from", from );
   struct.put( "to", to );
   struct.put( "item_type", "1");
         struct.put( "limit_offset", start );
         struct.put( "limit", numrecords );
  
   Hashtable result = callXmlRpc("summary-account", struct);
   Object[] ret = new Object[5];
   Vector items = (Vector) result.get("summary");
   List ret_items = new ArrayList();
   int total_cnt = 0;
   String currency = "USD";
   for(int k = 0; k < items.size(); k++) {
       Hashtable current = (Hashtable) items.get(k);
       ContentItem item = new ContentItem();
       item.set_name(toString(current.get("NAME")));
       item.set_i_id(toInteger(current.get("I_ID")));
       item.set_price(new Double(0));
       item.set_s_amount(toDouble(current.get("TOTAL_AMOUNT")));
       item.set_s_cnt(toInteger(current.get("TOTAL_COUNT")));
       total_cnt += item.get_s_cnt().intValue();
       item.set_deleted(new Boolean(toInteger(current.get("DELETED")).intValue() > 0));
       item.set_currency(toString(current.get("CURRENCY")));
       currency = item.get_currency();
       ret_items.add(item);
   }
   ret[0] = toInteger(result.get("total_count"));
   ret[1] = toDouble(result.get("total_amount_summary"));
   ret[2] = new Integer(total_cnt);
   ret[3] = ret_items;
   ret[4] = currency;
   return ret;
     }

    public Object[] ssummary( Account account, String show, String sort, Integer dir, Integer start, Integer numrecords, String from, String to) throws BitPassAdapterException {
        if(sort.equals("amount")) {
            // use ssummary
            String s_account = ":" + account.get_p_id().toString() + "::::";
            return ssummary(s_account, account.get_p_id().toString(), start.toString(), numrecords.toString(), from, to);
            // return fake_ssummary( account, show, sort, dir, start, numrecords, from, to);
        } else {
            // use blah...
            return fake_ssummary( account, show, sort, dir, start, numrecords, from, to);
        }
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////  Get Transaction History   //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public ArrayList txnhistory( String account, String from, String to, String ext, String sort, String direction ) throws BitPassAdapterException {

        ArrayList ret = new ArrayList();

        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "from", from );
        args.put( "to", to );
        args.put( "ext", ext );
        args.put( "sortby", sort );
        args.put( "sortdirection", direction );

        // Make the connection.
  Hashtable result;
  {
      String command = "history-transactions";
      logger.info(command + args.toString());
     
      Vector struct = new Vector();
      struct.addElement( args );
     
      // Make the connection.
      result = null;
      try {
    result = (Hashtable) client.execute( command, struct );
      } catch( XmlRpcException e ) {
    if(e.code == 0) {
        result = new Hashtable();
        result.put("count", "0");
    } else {
        throw new BitPassAdapterException( e );
    }
      } catch( IOException e ) {
    throw new BitPassAdapterException( e );
      } catch( ClassCastException e ) {
    throw new BitPassAdapterException( e );
      }
      if(result == null) {
    throw new BitPassAdapterException("Null result from xmlrpc");
      }
      logger.info(result.toString());
  }
      
        Transaction item;
        Vector header = (Vector) result.get("header");
  String zerofill = "0";
  int count = toInteger(result.get("count")).intValue();
  count -= count % 10;
  count /= 10;
  while(count > 0) {
      count -= count % 10;      
      count /= 10;
      zerofill += "0";
  }
        for(int i = 1;
            result.containsKey("line" + zerofill(String.valueOf(i), zerofill));
            i++) {
            Vector line = (Vector) result.get("line" + zerofill(String.valueOf(i), zerofill));
            item = new Transaction();
            item.set_item(new Item());
            ret.add( item );

            for(int k = 0; k < header.size(); k++) {
                String current = (String) header.get(k);
                if(current.equals("TYPE")) {
                    item.set_type(toString(line.elementAt(k)));
                    logger.info("TYPE = " + toString(line.elementAt(k)));
                } else if(current.equals("RECEIPT_ID")) {
                    item.set_txn_id(new Integer(Integer.parseInt(toString(line.elementAt(k)).replaceAll("'", ""), 16))); // hex string
                    logger.info("RECEIPT_ID = " + item.get_txn_id().toString());
                } else if(current.equals("SPENDER")) {
                    //
                } else if(current.equals("TXNTIME")) {
                    item.set_txntime(parseDate(toString(line.elementAt(k))));
                    logger.info("TXNTIME = " + toString(line.elementAt(k)));
                } else if(current.equals("AMOUNT")) {
                    item.set_amount(toDouble(line.elementAt(k)));
                    logger.info("AMOUNT = " + toDouble(line.elementAt(k)).toString());
                } else if(current.equals("TXNFEE")) {
                    item.set_txnfee(toDouble(line.elementAt(k)));
                    logger.info("TXNFEE = " + toDouble(line.elementAt(k)).toString());
                } else if(current.equals("ITEM_ID")) {
                    item.get_item().set_i_id(toInteger(line.elementAt(k)));
                    logger.info("ITEM_ID = " + toInteger(line.elementAt(k)).toString());
                } else if(current.equals("ITEM_TYPE")) {
                    item.get_item().set_type(toString(line.elementAt(k)));
                    if(item.get_item().get_type().equals("CONTENT")) {
                        item.set_item(new ContentItem(item.get_item()));
                    }
                    logger.info("ITEM_TYPE = " + toString(line.elementAt(k)));
                } else if(current.equals("DELETED")) {
                    item.get_item().set_deleted(new Boolean(toInteger(line.elementAt(k)).intValue() > 0));
                    logger.info("DELETED = " + (new Boolean(toInteger(line.elementAt(k)).intValue() > 0)).toString());
                } else if(current.equals("PATH")) {
                    //
                } else if(current.equals("PARAM")) {
                    //
                } else if(current.equals("ITR_ID")) {
                    //
                } else if(current.equals("CURRENCY")) {
                    item.get_item().set_currency(toString(line.elementAt(k)));
                    logger.info("CURRENCY = " + toString(line.elementAt(k)));
                } else {
                    logger.info("Found unexpected key " + current + "in txnhistory header.");
                }
            }
            item.set_settled(new Boolean(item.get_txnfee().doubleValue() > 0));
            item.set_refunded(new Boolean(false));
            //            item.set_txn_id(new Integer(1234));
        }

        // Done.
        return ret;
    }

    public Object[] txnhistory(Account account, String sort, Integer dir, Integer start,
                                Integer numrecords, String from, String to) throws BitPassAdapterException {
        try {
            logger.info("txnhistory: ( sort => " + sort + ", dir => " + dir.toString()
                        + ", start => " + start.toString() + ", numrecords => " + numrecords.toString()
                        + ", from => " + from + ", to => " + to + " )");
        } catch(Exception e) {
            logger.error(e.toString());
        }
        String s_account = ":" + account.get_p_id().toString() + "::::";
        ArrayList hist = txnhistory(s_account, from, to, "1", sort, dir.intValue() > 0 ? "ASC" : "DESC");
  Integer count = new Integer(hist.size());
        try {
            int beg = start.intValue();
            if( beg >= count.intValue()) return new Object[] { count, new ArrayList() }; // Return an empty array if start is beyond end.
            int end = beg + numrecords.intValue();
            if( beg < 0 || end < beg ) return new Object[] { count, hist }; // Return entire array if either start or numrecords is less than 0.
            if( end > count.intValue() ) end = count.intValue();

            return new Object[] { count, hist.subList( beg, end ) };

        } catch( NullPointerException e ) {

            return new Object[] { count, hist };

        }
    }


//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////   View Transaction Item     //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Item viewtxnitem(String account, String txn_id) throws BitPassAdapterException {
        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "r_id", txn_id );
  args.put( "ext", "1" );

        // Make the connection.
        Hashtable result = callXmlRpc("details-receipt", args);
  Vector header = (Vector) result.get("header");
  Vector line = (Vector) result.get("line1");
  Hashtable context = null;
  Integer deleted = null;
  for(int i = 0; i < header.size(); i++) {
      if(((String) header.get(i)).equals("CONTEXT")) {
    context = (Hashtable) line.get(i);
      } else if(((String) header.get(i)).equals("DELETED")) {
    deleted = toInteger(line.get(i));
      }
  }
  Hashtable htitem = (Hashtable) context.get("ITEM");
  htitem.putAll((Hashtable) context.get("CONTENT"));
  ContentItem item = parseContentItem(htitem);
  // items involved in transactions must have been published and enabled.
  item.set_stat(new Integer(1));
  item.set_available(new Integer(1));
  // iconset not included
  // s_cnt not included
  // target not included
        ((ContentItem) item).set_deleted(new Boolean(deleted.intValue() > 0));
  return item;
    }
   
    public Item viewtxnitem(Account account, Integer txn_id) throws BitPassAdapterException {
  String s_account = ":" + account.get_p_id().toString() + "::::";
        return viewtxnitem(s_account, toString(txn_id));
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////      View Transaction       //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Transaction viewtxn(String account, String txn_id) throws BitPassAdapterException {
        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "r_id", txn_id );
  args.put( "ext", "1" );

        // Make the connection.
        Hashtable result = callXmlRpc("details-receipt", args);
  Vector header = (Vector) result.get("header");
  Vector line = (Vector) result.get("line1");
        Transaction txn = new Transaction();
  Hashtable context = null;
  for(int i = 0; i < header.size(); i++) {
      if(((String) header.get(i)).equals("TYPE")) {
    txn.set_type(toString(line.get(i)));
      } else if(((String) header.get(i)).equals("TXNTIME")) {
    txn.set_txntime(parseDate(toString(line.get(i))));
      } else if(((String) header.get(i)).equals("AMOUNT")) {
    txn.set_amount(toDouble(line.get(i)));
      } else if(((String) header.get(i)).equals("CURRENCY")) {
    txn.set_currency(toString(line.get(i)));
      } else if(((String) header.get(i)).equals("TXNFEE")) {
    txn.set_txnfee(toDouble(line.get(i)));
      } else if(((String) header.get(i)).equals("CONTEXT")) {
    context = (Hashtable) line.get(i);
      }
  }
        txn.set_settled(new Boolean(txn.get_txnfee().doubleValue() > 0));

  // need ?
  txn.set_refunded(new Boolean(false));
  // still assuming this is always true
        txn.set_purchase_type("PASS");
  Hashtable htitem = (Hashtable) context.get("ITEM");
  htitem.putAll((Hashtable) context.get("CONTENT"));
        txn.set_item(parseContentItem(htitem));
        txn.set_txn_id(toInteger(txn_id));
  return txn;
    }

    public Transaction viewtxn(Account account, Integer txn_id) throws BitPassAdapterException {
  String s_account = ":" + account.get_p_id() + "::::";
        return viewtxn(s_account, txn_id.toString());
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////      Map Acquirer      ///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public Integer mapacquirer(String account, String aq_id) throws BitPassAdapterException {
        // Package the args.
        Hashtable args = new Hashtable();
        args.put( "account", account );
        args.put( "aq_id", aq_id );

        // Make the connection.
        Hashtable result = callXmlRpc("set-acquirer", args);
        return new Integer(toString(result.get("RESULT")));
    }

    public Integer mapacquirer(Integer p_id, Integer aq_id) throws BitPassAdapterException {
        String s_account = ":" + p_id.toString() + "::::";
        return mapacquirer(s_account, toString(aq_id));
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////     Util methods       ///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    protected Hashtable callXmlRpc(String command, Hashtable args) throws BitPassAdapterException {

        logger.info(command + args.toString());

        Vector struct = new Vector();
        struct.addElement( args );

        // Make the connection.
        Hashtable result = null;
        try {
            result = (Hashtable) client.execute( command, struct );
        } catch( XmlRpcException e ) {
            throw new BitPassAdapterException( e );
        } catch( IOException e ) {
            throw new BitPassAdapterException( e );
        } catch( ClassCastException e ) {
            throw new BitPassAdapterException( e );
        }
        if(result == null) {
            throw new BitPassAdapterException("Null result from xmlrpc");
        }

        logger.info(result.toString());

        return result;
    }

    protected ContentItem parseContentItem(Hashtable obj) {
    // this next line complains when I set the function to static.  Makes no difference, so...
    ContentItem item = new ContentItem();
    for( Iterator j = obj.keySet().iterator(); j.hasNext(); ) {
        String key = (String)j.next();
        if( key.equals( "MAX_CLK" ) ) {
            item.set_max_clk( toInteger( obj.get( key ) ) );
        } else if( key.equals( "PRICE" ) ) {
            item.set_price( toDouble( obj.get( key ) ) );
        } else if( key.equals( "I_ID" ) ) {
            item.set_i_id( toInteger( obj.get( key ) ) );
        } else if( key.equals( "STATUS" ) ) {
            item.set_stat( toInteger( obj.get( key ) ) );
        } else if( key.equals( "ICON_SET" ) ) {
            int iconset = toInteger( obj.get( key ) ).intValue();
            item.set_iconset( new Integer(iconset % 10));
            item.set_icon_align(iconset >= 10 ? new Integer( 1 ) : new Integer( 0 ) );
        } else if( key.equals( "LINK_TXT" ) ) {
            item.set_linktxt( toString( obj.get( key ) ) );
        } else if( key.equals( "EXPIRES" ) ) {
            int time = toInteger(obj.get(key)).intValue(); // Total Minutes
            item.set_exp_m(new Integer(time % 60));
            time -= time % 60;
            time /= 60; // Total Hours
            item.set_exp_h(new Integer(time % 24));
            time -= time % 24;
            time /= 24; // Total Days
            item.set_exp_d(new Integer(time));
        } else if( key.equals( "S_CNT" ) ) {
            item.set_s_cnt( toInteger( obj.get( key ) ) );
        } else if( key.equals( "PATH" ) ) {
            item.set_path( toString( obj.get( key ) ) );
        } else if( key.equals( "ENABLED" ) ) {
            item.set_available( toInteger( obj.get( key ) ) );
        } else if( key.equals( "NAME" ) ) {
            item.set_name( toString( obj.get( key ) ) );
        } else if( key.equals( "TARGET" )) {
            item.set_target( toString( obj.get( key ) ) );
        } else if( key.equals( "CURRENCY" )) {
            item.set_currency( toString( obj.get( key ) ) );
        } else {
            logger.info("Found unexpected key in item hash: " + key);
        }
    }
    return(item);
    }

    public static Integer toInteger( Object obj ) {
        if( obj instanceof Integer ) {
            return (Integer)obj;
        }
        try
        {
            return new Integer( obj.toString() );
        }
        catch(Exception e)
        {
            return new Integer( 0 );
        }
    }

    public static Double toDouble( Object obj ) {
        if( obj instanceof Double ) {
            return (Double)obj;
        }
        try
        {
            return new Double( obj.toString() );
        }
        catch(Exception e)
        {
            return new Double( 0 );
        }
    }

    public static String toString( Object obj ) {
        return toString( obj, "" );
    }

    public static String toString( Boolean bool ) {
        return toString( bool, "" );
    }

    public static String toString( Boolean bool, String def ) {
        if( bool != null )
        {
            return bool.booleanValue() ? "1" : "0";
        }
        return def;
    }

    public static String toString( Object obj, String def ) {
  String ret;
        if( obj instanceof String ) {
            ret = (String)obj;
        } else if( obj != null ) {
            ret = (String) obj.toString();
        } else {
      return def;
  }
  return StringEscapeUtils.unescapeXml(ret);
    }

    public static Date parseDate(String date) {
        Calendar cal = Calendar.getInstance(Locale.US);
        date = trimquotes(date);
        String val[] = date.split(" +");
        String ymd[] = val[0].split("[/-]");
        String hms[] = val[1].split(":");
  if(hms.length < 3) {
      hms = new String[] {hms[0], hms[1], "0"};
  }
        cal.set(Integer.parseInt(ymd[0]), Integer.parseInt(ymd[1]), Integer.parseInt(ymd[2]),
                Integer.parseInt(hms[0]), Integer.parseInt(hms[1]), Integer.parseInt(hms[2]));
        return cal.getTime();
    }

    public static String zerofill(String string, String zerofill) {
  return zerofill.substring(0, zerofill.length() - string.length()) + string;
    }
   
    public static String unparseDate(Integer year, Integer month, Integer day) {
        String zerofill = "00";
        String year_s = year.toString();
        String month_s = month.toString();
        String day_s = day.toString();
        month_s = zerofill(month_s, zerofill); //zerofill.substring(0, 2 - month_s.length()) + month_s;
        day_s = zerofill(day_s, zerofill); //zerofill.substring(0, 2 - day_s.length()) + day_s;
        return year_s + "/" + month_s + "/" + day_s;
    }

    public static String trimquotes(String string) {
        // Stupid java doesn't do \A and \z even though it says it does
        if(string.substring(0, 1).matches("['\"]")) {
            string = string.substring(1, string.length());
        }
        if(string.substring(string.length() - 1, string.length()).matches("['\"]")) {
            string = string.substring(0, string.length() - 1);
        }
        return string;
    }

    public static Account getEarnerAuth(DataAccount accountObj) {
        Account account = new Account();
        account.set_p_id(accountObj.getPublisherId());
        return account;
    }

    public static Account getAcquirerAuth(DataAccount accountObj) {
        // TODO.
        return null;
    }

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////// Inner Class Beans      ///////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

    public static class AdapterBean {

        public AdapterBean() {
        }

    }

    public static class Account extends AdapterBean {
    public Account() {
    }
    private String m_pubid;
        public String get_pubid() {
            return m_pubid;
        }
        public void set_pubid( String pubid ) {
            m_pubid = pubid;
        }
    private Integer m_p_id;
        public Integer get_p_id() {
            return m_p_id;
        }
        public void set_p_id( Integer p_id ) {
            m_p_id = p_id;
        }
    private Integer m_aq_id;
        public Integer get_aq_id() {
            return m_aq_id;
        }
        public void set_aq_id( Integer aq_id ) {
            m_aq_id = aq_id;
        }
    private String m_passwd;
    public String get_passwd() {
        return m_passwd;
    }
    public void set_passwd(String passwd) {
        m_passwd = passwd;
    }
    }

    public static class Site extends AdapterBean {
    public Site() {
    }
    private String m_name;
    public String get_name() {
        return m_name;
    }
    public void set_name(String name) {
        m_name = name;
    }
    private String m_description;
    public String get_description() {
        return m_description;
    }
    public void set_description(String description) {
        m_description = description;
    }
    private String m_url;
    public String get_url() {
        return m_url;
    }
    public void set_url(String url) {
        m_url = url;
    }
    private Boolean m_available;
    public Boolean get_available() {
        return m_available;
    }
    public void set_available(Boolean available) {
        m_available = available;
    }
    }

    public static class Earner extends AdapterBean {
        public Earner() {
        }
    private String m_fname;
    public String get_fname() {
        return m_fname;
    }
    public void set_fname(String fname) {
        m_fname = fname;
    }
    private String m_lname;
    public String get_lname() {
        return m_lname;
    }
    public void set_lname(String lname) {
        m_lname = lname;
    }
    private String m_mi;
    public String get_mi() {
        return m_mi;
    }
    public void set_mi(String mi) {
        m_mi = mi;
    }
    private String m_title;
    public String get_title() {
        return m_title;
    }
    public void set_title(String title) {
        m_title = title;
    }
    private String m_company;
    public String get_company() {
        return m_company;
    }
    public void set_company(String company) {
        m_company = company;
    }
    private String m_address1;
    public String get_address1() {
        return m_address1;
    }
    public void set_address1(String address1) {
        m_address1 = address1;
    }
    private String m_address2;
    public String get_address2() {
        return m_address2;
    }
    public void set_address2(String address2) {
        m_address2 = address2;
    }
    private String m_address3;
    public String get_address3() {
        return m_address3;
    }
    public void set_address3(String address3) {
        m_address3 = address3;
    }
    private String m_city;
    public String get_city() {
        return m_city;
    }
    public void set_city(String city) {
        m_city = city;
    }
    private String m_province;
    public String get_province() {
        return m_province;
    }
    public void set_province(String province) {
        m_province = province;
    }
    private String m_postal;
    public String get_postal() {
        return m_postal;
    }
    public void set_postal(String postal) {
        m_postal = postal;
    }
    private String m_country;
    public String get_country() {
        return m_country;
    }
    public void set_country(String country) {
        m_country = country;
    }
    private String m_phone;
    public String get_phone() {
        return m_phone;
    }
    public void set_phone(String phone) {
        m_phone = phone;
    }
    private String m_email;
    public String get_email() {
        return m_email;
    }
    public void set_email(String email) {
        m_email = email;
    }
    }

    public static class I18nInfo extends AdapterBean {
        private String m_country;
        public String get_country() {
            return m_country;
        }
        public void set_country(String country) {
            m_country = country;
        }
        private String m_timezone;
        public String get_timezone() {
            return m_timezone;
        }
        public void set_timezone(String timezone) {
            m_timezone = timezone;
        }
        private String m_currency;
        public String get_currency() {
            return m_currency;
        }
        public void set_currency(String currency) {
            m_currency = currency;
        }
        private String m_language;
        public String get_language() {
            return m_language;
        }
        public void set_language(String language) {
            m_language = language;
        }
    }

//     public class Gateway extends AdapterBean {

//         public Gateway() {
//         }

//         private String m_script;
//         public String get_script() {
//             return m_script;
//         }
//         public void set_script( String script ) {
//             m_script = script;
//         }

//         private String m_gate;
//         public String get_gate() {
//             return m_gate;
//         }
//         public void set_gate( String gate ) {
//             m_gate = gate;
//         }

//         private String m_basedir;
//         public String get_basedir() {
//             return m_basedir;
//         }
//         public void set_basedir( String basedir ) {
//             m_basedir = basedir;
//         }

//         private String m_indexfname;
//         public String get_indexfname() {
//             return m_indexfname;
//         }
//         public void set_indexfname( String indexfname ) {
//             m_indexfname = indexfname;
//         }

//         private String m_p3p;
//         public String get_p3p() {
//             return m_p3p;
//         }
//         public void set_p3p( String p3p ) {
//             m_p3p = p3p;
//         }

//     }

    public static class Transaction extends AdapterBean {
        public Transaction() {
        }
    private String m_type;
    public String get_type() {
        return m_type;
    }
    public void set_type(String type) {
        m_type = type;
    }
    private Date m_txntime;
    public Date get_txntime() {
        return m_txntime;
    }
    public void set_txntime(Date txntime) {
        m_txntime = txntime;
    }
    private Date m_original_time;
    public Date get_original_time() {
        return m_original_time;
    }
    public void set_original_time(Date original_time) {
        m_original_time = original_time;
    }
    private Double m_amount;
    public Double get_amount() {
        return m_amount;
    }
    public void set_amount(Double amount) {
        m_amount = amount;
    }
    private String m_currency = "USD";
    public String get_currency() {
        return m_currency;
    }
    public void set_currency(String currency) {
        m_currency = currency;
    }
    private Double m_txnfee;
    public Double get_txnfee() {
        return m_txnfee;
    }
    public void set_txnfee(Double txnfee) {
        m_txnfee = txnfee;
    }
    private Boolean m_settled;
    public Boolean get_settled() {
        return m_settled;
    }
    public void set_settled(Boolean settled) {
        m_settled = settled;
    }
    private Boolean m_refunded;
    public Boolean get_refunded() {
        return m_refunded;
    }
    public void set_refunded(Boolean refunded) {
        m_refunded = refunded;
    }
    private Integer m_txn_id;
    public Integer get_txn_id() {
        return m_txn_id;
    }
    public void set_txn_id(Integer txn_id) {
        m_txn_id = txn_id;
    }
    private Integer m_original_txn_id;
    public Integer get_original_txn_id() {
        return m_original_txn_id;
    }
    public void set_original_txn_id(Integer original_txn_id) {
        m_original_txn_id = original_txn_id;
    }
    private String m_purchase_type;
    public String get_purchase_type() {
        return m_purchase_type;
    }
    public void set_purchase_type(String purchase_type) {
        m_purchase_type = purchase_type;
    }
    private Item m_item;
    public Item get_item() {
        return m_item;
    }
    public void set_item(Item item) {
        m_item = item;
    }

    }

    public static class Complaint extends AdapterBean {
        public Complaint() {
        }
        private String m_s_email;
        public String get_s_email() {
            return m_s_email;
        }
        public void set_s_email(String s_email) {
            m_s_email = s_email;
        }

        private String m_reason;
        public String get_reason() {
            return m_reason;
        }
        public void set_reason(String reason) {
            m_reason = reason;
        }

        private Integer m_request;
        public Integer get_request() {
            return m_request;
        }
        public void set_request(Integer request) {
            m_request = request;
        }

        private String m_message;
        public String get_message() {
            return m_message;
        }
        public void set_message(String message) {
            m_message = message;
        }

        private Date m_request_time;
        public Date get_request_time() {
            return m_request_time;
        }
        public void set_request_time(Date request_time) {
            m_request_time = request_time;
        }

        private String m_response;
        public String get_response() {
            return m_response;
        }
        public void set_response(String response) {
            m_response = response;
        }

        private Date m_response_time;
        public Date get_response_time() {
            return m_response_time;
        }
        public void set_response_time(Date response_time) {
            m_response_time = response_time;
        }


        private Item m_item;
        public Item get_item() {
            return m_item;
        }
        public void set_item(Item item) {
            m_item = item;
        }

        private Transaction m_txn;
        public Transaction get_txn() {
            return m_txn;
        }
        public void set_txn(Transaction txn) {
            m_txn = txn;
        }

        private Boolean m_pass_expired;
        public Boolean get_pass_expired() {
            return m_pass_expired;
        }
        public void set_pass_expired(Boolean pass_expired) {
            m_pass_expired = pass_expired;
        }

        private Date m_pass_issued;
        public Date get_pass_issued() {
            return m_pass_issued;
        }
        public void set_pass_issued(Date pass_issued) {
            m_pass_issued = pass_issued;
        }

        private Date m_visit_time;
        public Date get_visit_time() {
            return m_visit_time;
        }
        public void set_visit_time(Date visit_time) {
            m_visit_time = visit_time;
        }

        private Integer m_visit_number;
        public Integer get_visit_number() {
            return m_visit_number;
        }
        public void set_visit_number(Integer visit_number) {
            m_visit_number = visit_number;
        }

        private Integer m_visit_allowed;
        public Integer get_visit_allowed() {
            return m_visit_allowed;
        }
        public void set_visit_allowed(Integer visit_allowed) {
            m_visit_allowed = visit_allowed;
        }


        private Integer m_cpid;
        public Integer get_cpid() {
            return m_cpid;
        }
        public void set_cpid(Integer cpid) {
            m_cpid = cpid;
        }

        private String m_status;
        public String get_status() {
            return m_status;
        }
        public void set_status(String status) {
            m_status = status;
        }

    }

    public static class Item extends AdapterBean {
        public Item() {
        }
        private Integer m_i_id;
        public Integer get_i_id() {
            return m_i_id;
        }
        public void set_i_id( Integer i_id ) {
            m_i_id = i_id;
        }
        private String m_name;
        public String get_name() {
            return m_name;
        }
        public void set_name( String name ) {
            m_name = name;
        }
    private String m_type;
    public String get_type() {
        return m_type;
    }
    public void set_type(String type) {
        m_type = type;
    }
        private String m_path;
        public String get_path() {
            return m_path;
        }
        public void set_path( String path ) {
            m_path = path;
        }
    // Total sales is only used for txn history stuff.
    private Double m_s_amount;
    public Double get_s_amount() {
        return m_s_amount;
    }
    public void set_s_amount(Double s_amount) {
        m_s_amount = s_amount;
    }
        private Integer  m_s_cnt;
        public Integer get_s_cnt() {
            return m_s_cnt;
        }
        public void set_s_cnt( Integer s_cnt ) {
            m_s_cnt = s_cnt;
        }
        private String m_currency = "USD";
        public String get_currency() {
            return m_currency;
        }
        public void set_currency( String currency ) {
            m_currency = currency;
        }
        private Boolean m_deleted;
        public Boolean get_deleted() {
            return m_deleted;
        }
        public void set_deleted(Boolean deleted) {
            m_deleted = deleted;
        }
    }


    // Note that when we get an accurate API into other item types, we should abstract more from ContentItem into Item.
    public static class ContentItem extends Item {
        public ContentItem() {
        }
  public ContentItem(Item item) {
      if(item.get_i_id() != null) {
    this.set_i_id(item.get_i_id());
      }
      if(item.get_name() != null) {
    this.set_name(item.get_name());
      }
      if(item.get_path() != null) {
    this.set_name(item.get_path());
      }
      if(item.get_s_amount() != null) {
    this.set_s_amount(item.get_s_amount());
      }
      if(item.get_s_cnt() != null) {
    this.set_s_cnt(item.get_s_cnt());
      }
      if(item.get_currency() != null) {
    this.set_currency(get_currency());
      }
      if(item.get_deleted() != null) {
    this.set_deleted(item.get_deleted());
      }
  }
        private String m_linktxt;
        public String get_linktxt() {
            return m_linktxt;
        }
        public void set_linktxt( String linktxt ) {
            m_linktxt = linktxt;
        }
        private Double m_price;
        public Double get_price() {
            return m_price;
        }
        public void set_price( Double price ) {
            m_price = price;
        }
        private Integer m_iconset;
        public Integer get_iconset() {
            return m_iconset;
        }
        public void set_iconset( Integer iconset ) {
            m_iconset = iconset;
        }
        private Integer m_icon_align;
        public Integer get_icon_align() {
            return m_icon_align;
        }
        public void set_icon_align( Integer icon_align ) {
            m_icon_align = icon_align;
        }
        private Integer  m_exp_d;
        public Integer get_exp_d() {
            return m_exp_d;
        }
        public void set_exp_d( Integer exp_d ) {
            m_exp_d = exp_d;
        }
        private Integer m_exp_h;
        public Integer get_exp_h() {
            return m_exp_h;
        }
        public void set_exp_h( Integer exp_h ) {
            m_exp_h = exp_h;
        }
        private Integer m_exp_m;
        public Integer get_exp_m() {
            return m_exp_m;
        }
        public void set_exp_m( Integer exp_m ) {
            m_exp_m = exp_m;
        }
        private Integer m_max_clk;
        public Integer get_max_clk() {
            return m_max_clk;
        }
        public void set_max_clk( Integer max_clk ) {
            m_max_clk = max_clk;
        }
        private Integer m_available;
        public Integer get_available() {
            return m_available;
        }
        public void set_available( Integer available ) {
            m_available = available;
        }
        private String m_target;
        public String get_target() {
            return m_target;
        }
        public void set_target( String target ) {
            m_target = target;
        }
        private String m_licensecode;
        public String get_licensecode() {
            return m_licensecode;
        }
        public void set_licensecode( String licensecode ) {
            m_licensecode = licensecode;
        }
        private Boolean m_incqstr;
        public Boolean get_incqstr() {
            return m_incqstr;
        }
        public void set_incqstr( Boolean incqstr ) {
            m_incqstr = incqstr;
        }
        private Integer m_stat;
        public Integer get_stat() {
            return m_stat;
        }
        public void set_stat( Integer stat ) {
            m_stat = stat;
        }
    public String get_type() {
        return "CONTENT";
    }
    public void set_type(String type) {
    }
    // These are passed in, but not back, and are broken anyway
        private String m_cssurl;
        public String get_cssurl() {
            return m_cssurl;
        }
        public void set_cssurl( String cssurl ) {
            m_cssurl = cssurl;
        }
        private String m_preview;
        public String get_preview() {
            return m_preview;
        }
        public void set_preview( String preview ) {
            m_preview = preview;
        }
    }

//     public class ReferralItem extends Item {

//         public ReferralItem() {
//         }

//         private String m_ref;
//         public String get_ref() {
//             return m_ref;
//         }
//         public void set_ref( String ref ) {
//             m_ref = ref;
//         }

//         private String m_idstr;
//         public String get_idstr() {
//             return m_idstr;
//         }
//         public void set_idstr( String idstr ) {
//             m_idstr = idstr;
//         }
//     }

//     public class DonationItem extends Item {

//         public DonationItem() {
//         }

//         private Double m_amount;
//         public Double get_amount() {
//             return m_amount;
//         }
//         public void set_amount( Double amount ) {
//             m_amount = amount;
//         }

//         private Double m_total;
//         public Double get_total() {
//             return m_total;
//         }
//         public void set_total( Double total ) {
//             m_total = total;
//         }

//         private String m_goal;
//         public String get_goal() {
//             return m_goal;
//         }
//         public void set_goal( String goal ) {
//             m_goal = goal;
//         }

//         private Double m_min_amount;
//         public Double get_min_amount() {
//             return m_min_amount;
//         }
//         public void set_min_amount( Double min_amount ) {
//             m_min_amount = min_amount;
//         }

//         private Double m_max_amount;
//         public Double get_max_amount() {
//             return m_max_amount;
//         }
//         public void set_max_amount( Double max_amount ) {
//             m_max_amount = max_amount;
//         }

//         private String m_desturl;
//         public String get_desturl() {
//             return m_desturl;
//         }
//         public void set_desturl( String desturl ) {
//             m_desturl = desturl;
//         }

//         private String m_multi;
//         public String get_multi() {
//             return m_multi;
//         }
//         public void set_multi( String multi ) {
//             m_multi = multi;
//         }
//     }
}

/* r.e. to create accessor methods.
        private \1 m_\2;
        public \1 get_\2() {
            return m_\2;
        }
        public void set_\2(\1 \2) {
            m_\2 = \2;
        }
*/

//
// $Log: BitPassAdapter.java,v $
// Revision 1.72  2005/07/27 01:49:35  ebuswell
// fixed next/prev bug; fixed api xml entity related bug
//
// Revision 1.71  2005/07/15 18:32:17  ebuswell
// added currency parameter to create-account
//
// Revision 1.70  2005/07/09 00:11:13  ebuswell
// fixed some integration problems; pointed to api.firesalt.com until dev server is updated.
//
// Revision 1.69  2005/07/06 23:00:00  ebuswell
// changed to new xmlrpc names
//
// Revision 1.68  2005/06/15 01:27:51  ebuswell
// sorting implemented on our side for listcnt
//
// Revision 1.67  2005/06/14 00:15:44  ebuswell
// reports now do pagination
//
// Revision 1.66  2005/05/18 00:33:45  ebuswell
// integrated completely! (did getdispute extra, fixed ssummary bug)
//
// Revision 1.65  2005/05/17 00:29:17  ebuswell
// completed integration
//
// Revision 1.64  2005/05/16 22:15:35  ebuswell
// integrated report sorting; fixed action.login bug
//
// Revision 1.63  2005/05/11 07:32:00  ebuswell
// able to create earners now
//
// Revision 1.62  2005/05/07 17:02:52  ebuswell
// integrated new dispute and ssummary functionality
//
// Revision 1.61  2005/05/03 23:02:00  ebuswell
// integrated i18n; fixed Rachel's bug
//
// Revision 1.60  2005/05/03 19:26:34  ebuswell
// integrated dispute handling
//
// Revision 1.59  2005/05/03 16:11:53  ebuswell
// integrated siteinfo
//
// Revision 1.58  2005/05/03 15:33:12  ebuswell
// integrated with api, moved to new xml-rpc server
//
// Revision 1.57  2005/04/28 03:07:30  ncheng
// got rid of stuff thats not available yet (bug 845, etc.)
//
// Revision 1.56  2005/04/27 17:06:49  ebuswell
// integrated a few things
//
// Revision 1.55  2005/04/17 18:36:30  ebuswell
// integrated earnerinfo and map_acquirer
//
// Revision 1.54  2005/04/15 02:06:42  ebuswell
// added a stubbed out mapacquirer
//
// Revision 1.53  2005/04/14 02:32:16  ebuswell
// made our earner info correspond with bitpass earner info
//
// Revision 1.52  2005/04/04 18:38:19  ebuswell
// cleaned up
//
// Revision 1.51  2005/04/01 22:50:54  ebuswell
// 1)Integration with new api.bitpassdemo.net api server.
// 2)Get Earner information from server
// 3)Migrate Earner functionality added
// 4)Permission checking now checks whether the permission requires there to be a currentBitPassAdapterAccount
//
// Revision 1.50  2005/03/22 06:28:37  ebuswell
// Alpha of reports finished
//
// Revision 1.49  2005/03/22 04:33:44  ebuswell
// Sales Summary and Transaction History work now
//
// Revision 1.48  2005/03/19 04:54:55  ebuswell
// Dispute History is bitchin' now
//
// Revision 1.47  2005/03/18 22:15:57  ebuswell
// preliminary reports
//
// Revision 1.46  2005/03/16 22:41:24  ebuswell
// dispute actions work now
//
// Revision 1.45  2005/03/16 00:35:33  ebuswell
// changed appropriate values to java.util.Date
//
// Revision 1.44  2005/03/15 22:42:01  ebuswell
// display currency and title correctly
//
// Revision 1.43  2005/03/15 21:54:33  ebuswell
// viewing complaints works now
//
// Revision 1.42  2005/03/15 20:29:58  ebuswell
// Stubbed out complaint handling
//
// Revision 1.41  2005/03/15 00:07:33  ebuswell
// content summary works now (bug 698)
//
// Revision 1.40  2005/03/11 21:10:17  ebuswell
// Made everything use proper BitPassAdapter functions
//
// Revision 1.39  2005/03/11 01:35:32  ncheng
// working on account listing;
// change some hardcoded vals to constants
//
// Revision 1.38  2005/03/09 23:26:47  ebuswell
// updated BitPassAdapter to reflect actual API
//
// Revision 1.37  2005/03/08 03:58:16  ichoudhury
// after modification in add/edit methods for ref and dnt
//
// Revision 1.36  2005/03/08 00:35:03  ncheng
// refactored add/update functionality;
// moved back to 0/1 for icon_align instead of r/l because we are not translating other fields and 0/1 or r/l is all the same to us--theyre just codes that have little semantic value to us
//
// Revision 1.35  2005/03/05 09:17:45  ncheng
// adding is now possible
//
// Revision 1.34  2005/03/05 04:53:07  ncheng
// editing works
//
// Revision 1.33  2005/03/05 00:51:53  ebuswell
// caused null parameters not to cause exceptions and do the Right Thing
//
// Revision 1.32  2005/03/04 22:17:40  ebuswell
// changed item.stat to Integer
//
// Revision 1.31  2005/03/04 22:00:13  ebuswell
// added an updatecnt that accepts a ContentItem
//
// Revision 1.30  2005/03/04 21:38:32  ebuswell
// added an addcnt that accepts an item
//
// Revision 1.29  2005/03/04 20:24:58  ebuswell
// unpacked ICON_SET returned by bitpass adapter
//
// Revision 1.28  2005/03/04 12:12:41  ncheng
// still a lot of errors
//
// Revision 1.27  2005/03/04 03:49:00  ebuswell
// abstracted out parsing item from listcnt and viewcnt
//
// Revision 1.26  2005/03/04 02:11:22  ebuswell
// fixed listcnt so it actually returns items correctly
//
// Revision 1.25  2005/03/03 03:24:00  ebuswell
// got listcnt to compile, but doesnt seem to be returning items
//
// Revision 1.24  2005/03/02 19:58:33  ncheng
// made the listcnt method return total items also;
// passing off wip...
//
// Revision 1.23  2005/03/02 01:56:13  ncheng
// moved things around a little while working on Object Manager
//
// Revision 1.22  2005/03/01 23:51:42  ebuswell
// turned "EXPIRES" into d/h/m
//
// Revision 1.21  2005/03/01 20:27:28  ncheng
// working on Object Manager concept
//
// Revision 1.20  2005/02/28 20:20:17  ichoudhury
// after pagination
//
// Revision 1.19  2005/02/25 22:48:53  ichoudhury
// after pagination
//
// Revision 1.18  2005/02/25 21:05:34  ichoudhury
// after pagination
//
// Revision 1.17  2005/02/17 03:10:50  ichoudhury
// on feb 16
//
// Revision 1.16  2005/02/15 23:32:07  ichoudhury
// on feb 15
//
// Revision 1.15  2005/02/15 22:15:01  ichoudhury
// on feb 15
//
// Revision 1.14  2005/02/15 03:00:00  ichoudhury
// on feb 14
//
// Revision 1.13  2005/02/15 01:12:00  ichoudhury
// fixed compile error
//
// Revision 1.12  2005/02/14 18:53:20  ichoudhury
// on feb 14
//
// Revision 1.11  2005/02/11 18:57:03  ichoudhury
// on feb 11
//
// Revision 1.10  2005/02/11 02:03:09  ichoudhury
// on thursday
//
// Revision 1.9  2005/02/10 22:34:03  eforce
// on thursday
//
// Revision 1.8  2005/02/09 19:02:30  eforce
// added inner classes
//
// Revision 1.7  2005/02/09 02:01:18  eforce
// demo ready
//
// Revision 1.6  2005/02/09 00:05:10  eforce
// makes call
//
// Revision 1.5  2005/02/08 23:54:31  eforce
// adapter inits ok
//
// Revision 1.4  2005/02/08 23:15:37  eforce
// loads props file;
// initializes adapater
//
// Revision 1.3  2005/02/08 23:06:45  eforce
// added logging
//
// Revision 1.2  2005/02/08 21:38:49  eforce
// placeholder class
//
//
TOP

Related Classes of com.bitpass.css.wrapper.BitPassAdapter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.