package com.zksy.common.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.sql.Clob;

public  class StringUtil {
	
	public static String[] getEMaps(String name){
		String map="";
		String emap="";
		if(!StringUtil.isBlank(name)){
			if(name.indexOf("长沙市")!=-1){
				map="changshashi.js";
				emap="cs";
			}else if(name.indexOf("衡阳市")!=-1){
				map="hengyangshi.js";
				emap="hy";
			}else if(name.indexOf("株洲市")!=-1){
				map="zhuzhoushi.js";
				emap="zz";
			}else if(name.indexOf("邵阳市")!=-1){
				map="shaoyangshi.js";
				emap="sy";
			}else if(name.indexOf("岳阳市")!=-1){
				map="yueyangshi.js";
				emap="yuey";
			}else if(name.indexOf("郴州市")!=-1){
				map="chenzhoushi.js";
				emap="cz";
			}else if(name.indexOf("永州市")!=-1){
				map="yongzhoushi.js";
				emap="yz";
			}else if(name.indexOf("常德市")!=-1){
				map="changdeshi.js";
				emap="cd";
			}else if(name.indexOf("益阳市")!=-1){
				map="yiyangshi.js";
				emap="yy";
			}else if(name.indexOf("张家界市")!=-1){
				map="zhangjiajieshi.js";
				emap="zjj";
			}else if(name.indexOf("湘潭市")!=-1){
				map="xiangtanshi.js";
				emap="xt";
			}else if(name.indexOf("怀化市")!=-1){
				map="huaihuashi.js";
				emap="hh";
			}else if(name.indexOf("娄底市")!=-1){
				map="loudishi.js";
				emap="ld";
			}else if(name.indexOf("湘西州")!=-1){
				map="xiangxizhou.js";
				emap="xx";
			}else if(name.indexOf("湖南")!=-1){
				map="hunansheng.js";
				emap="hn";
			}
		}
		return new String[]{map,emap};
	}
	
	/**
	 * 
	 * @param clazz
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String getClassPath(Class<?> clazz)
			throws UnsupportedEncodingException {
		return java.net.URLDecoder.decode(getClassPathFile(clazz)
				.getAbsolutePath(), "UTF-8");

	}

	public static File getClassPathFile(Class<?> clazz) {
		File file = getClassFile(clazz);
		for (int i = 0, count = clazz.getName().split("[.]").length; i < count; i++)
			file = file.getParentFile();
		if (file.getName().toUpperCase().endsWith(".JAR!")) {
			file = file.getParentFile();
		}
		return file;
	}

	public static File getClassFile(Class<?> clazz) {
		URL path = clazz.getResource(clazz.getName().substring(
				clazz.getName().lastIndexOf(".") + 1)
				+ ".class");
		if (path == null) {
			String name = clazz.getName().replaceAll("[.]", "/");
			path = clazz.getResource("/" + name + ".class");
		}
		return new File(path.getFile());
	}
	/**
	 * 把Null型转换为""
	 * @param str
	 * @return
	 */
	public static String deNull(String str) {
		if (str == null) {
			return "";
		}
		return str;
	}
	/**
	 * 判断String 是否有值
	 * @param str
	 * @return 有值返回true，反之返回false
	 */
	public static boolean checkString(String str){
		if(str!=null && !str.trim().equals("")&&!"null".equals(str)){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 功能描述：是否为空白,包括null和""
	 * @param str
	 * @return
	 */
	public static boolean isBlank(String str) {
		return str == null || str.trim().length() == 0 || "null".equals(str);
	}
	


	public static String deNull(Object object) {
		if(object == null || isBlank(object.toString())){
			return "";
		}else{
			return object.toString();
		}
	}
	
	public static String deZero(Object obj){
		if(obj == null || isBlank(obj.toString())){
			return "0";
		}else{
			return obj.toString();
		}
	}


	public static String clobToString(Clob clob) throws Exception {
		String reString = "";
		Reader is = clob.getCharacterStream();// 得到流
		BufferedReader br = new BufferedReader(is);
		String s = br.readLine();
		StringBuffer sb = new StringBuffer();
		while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING
			sb.append(s);
			s = br.readLine();
		}
		reString = sb.toString();
		return reString;
	}


}

