
package org.mortbay.ijetty;


import android.content.Context;
import android.content.Intent;
import android.util.Log;
import org.mortbay.ijetty.JContext;


/**
 * IJettyService
 *
 * Android Service which runs the Jetty server
 */
public class Common{
    private Common(){}
	public static final String TAG = "Common";
	public static final  boolean  __DEBUG          = true;
	
	/*Jetty Directories*/
	public static final  String   __ROOT_DIR       = "/system";
	public static final  String   __DATA_DIR       = "/data";
	public static final  String   __JETTY_MAIN_DIR = "jetty";
	public static final  String   __WEBAPP_DIR     = "webapps";
    public static final  String   __ETC_DIR        = "etc";
    public static final  String   __CONTEXTS_DIR   = "contexts";
	public static final  String   __REALM_REF_NAME = "jetty/etc/realm.properties";
	
	/*Jetty handler parameters*/
	public static final  int     __STARTED  = 1;
	public static final  int     __STARTING = 2;
	public static final  int     __STOPPED  = 3;
	public static final  int     __ERROR    = 4;
	
	/*Jetty Server parameters*/
    public static final String __PORT = "org.mortbay.ijetty.port";
    public static final String __NIO = "org.mortbay.ijetty.nio";
    public static final String __SSL = "org.mortbay.ijetty.ssl";
    public static final String __CONSOLE_PWD = "org.mortbay.ijetty.console";
    public static final String __PORT_DEFAULT = "8080";
    public static final boolean __NIO_DEFAULT = true;
    public static final boolean __SSL_DEFAULT = false;
    public static final String __USERNAME = "org.mortbay.ijetty.username";
    public static final String __PASSWORD = "org.mortbay.ijetty.password";
    public static final String __GROUP = "org.mortbay.ijetty.group";
    public static final String __USERNAME_VALUE = "admin"; //default value
    public static final String __PASSWORD_VALUE = "admin"; //default value
    public static final String __GROUP_VALUE    = "admin"; //default value
    public static final String __CONSOLE_PWD_DEFAULT = "admin";
    public static final String __REALM_PROPERTIES = "realm.properties";
	public static final String __REALM_COPY_CONFIRMATION = "realm.check";
	public static final String __MAXWELLHIDDEN_REALM_PROPERTIES = "maxwellhidden.realm.properties";

	private static String ip;
	public static String getWebServerIP(){
       return ip;
	}
	public static void setWebServerIP(String new_ip){
	   if (__DEBUG)Log.i(TAG,"setWebServerIP = " + new_ip);
       ip = new_ip;
	}

	public static boolean startJetty(Context context, Intent serviceIntent){
             if (__DEBUG)Log.i(TAG,"Starting Jetty server");
             serviceIntent.putExtra(JContext.__INTENT_TYPE,JContext.__INTENT_TYPE_START_JETTY_VALUE);
             if ( null != context.startService(serviceIntent))
			 	return true;
			 return false;
	}

	public static boolean restartJetty(Context context, Intent serviceIntent){
             if (__DEBUG)Log.i(TAG,"restartJetty Jetty server ");
             serviceIntent.putExtra(JContext.__INTENT_TYPE,JContext.__INTENT_TYPE_RESTART_JETTY_VALUE);
             if ( null != context.startService(serviceIntent))
			 	return true;
			 return false;
	}
	
	public static void stopJetty(Context context, Intent serviceIntent){
             if (__DEBUG)Log.i(TAG,"Stopping jetty server");
             context.stopService(serviceIntent);
	}

}    
