package cn.com.pc.penguin.utils;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.NoInitialContextException;
import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: huangqinghe
 * To change this template use File | Settings | File Templates.
 */

public class PenguinUtils {
	private static final Logger log = Logger.getLogger(PenguinUtils.class);
    public static String indexHome = null;

    public static String getPenguinHome(){
        String project = "penguin";
		String home = getIndexHome();
		// Now try system property
	    if(StringUtils.isBlank(home)) {
	      String prop = project + "penguin.home";
	      home = System.getProperty(prop);
	      if( home != null ) {
	        log.info("using system property "+prop+": " + home );
	      }
	    }
	    //
	    if(StringUtils.isBlank(home)) {
	    	home = System.getProperty("java.io.tmpdir") + File.separator;
	    }
        return home;
    }


	public static String getPenguinIndexerDirectory() {
        String home = getPenguinHome();
        if(home != null){
            home = home + "penguin" + File.separator + "indexer" + File.separator;
        }
		return home;
	}

    //for lucene uncommit file
    public static String getPenguinCatalog() {
        String home = getPenguinHome();
        if (home != null) {
            home = home + "penguin" + File.separator + "catalog";
        }
		return home;
	}

    public static String getIndexHome() {
        return indexHome;
    }

    public static void setIndexHome(String indexHome) {
        PenguinUtils.indexHome = indexHome;
    }
}
