/*
* Copyright (c) 2005 Your Corporation. All Rights Reserved.
*/
package com.chis;
/**
* Created by IntelliJ IDEA. User: Shi Tiejun Date: 2005-12-1 Time: 10:35:46 To
* change this template use File | Settings | File Templates.
*/
public class StringFormatUtil {
/**
* 产生上级区划国标
*
* @param zoneCode
* @return 上级 区划国标
*/
public static String getParentZoneCode(String zoneCode) {
String s = StringFormatUtil.dealZero(zoneCode);
s = s.substring(0, s.length() - 2);
s = s + "00000000";
s = s.substring(0, 8);
return s;
}
/**
* 产生下级区划国标查询串
*
* @param zoneCode
* @return 产生下级区划国标查询串 oracle中单字匹配符号_
*/
public static String getChildZoneCode(String zoneCode) {
String s = StringFormatUtil.dealZero(zoneCode);
s = s + "__00000000";
s = s.substring(0, 8);
return s;
}
/**
* 根据传入的url获取页面文件
*
* @param urlStr
* @return pagename
*/
public static String getUrlPageName(String urlStr) {
String pageName = "";
String[] tempUrl = urlStr.split("\\?");
if (tempUrl.length > 0) {
pageName = tempUrl[0];
while (pageName.indexOf("/", 0) > -1) {
pageName = pageName.substring(pageName.indexOf("/", 0) + 1);
}
String[] tempParameter = pageName.split("\\.");
if (tempParameter.length > 1) {
if (!tempParameter[1].equalsIgnoreCase("jsp")) {
pageName = "";
}
}
}
return pageName;
}
/**
* 获取DisplayTag分页的参数名称和页数
*
* @param urlStr
* @return String[] 参数名称 参数值
*/
public static String[] getDisplayDP(String urlStr) {
String parameter, parameterName, parameterValue;
parameter = "";
parameterName = "";
parameterValue = "";
String[] tempUrl = urlStr.split("\\?");
if (tempUrl.length > 1) {
parameter = tempUrl[1];
String[] tempParameter = parameter.split("&");
for (int i = 0; i < tempParameter.length; i++) {
String[] temp = tempParameter[i].split("=");
if (temp[0].matches("d-[0-9]+-p")) {
parameterName = temp[0];
parameterValue = temp[1];
break;
}
}
}
String[] returnvalue = { parameterName, parameterValue };
return returnvalue;
}
/**
* 根据传入的行政区划国标编码取得地区级别
*
* @param zoneCode
* @return String 0处理错误 1国家,2省市,3地市,4县区、5乡镇
*/
public static String getZoneLevel(String zoneCode) {
String returnValue = "";
if (zoneCode.length() != 8) {
returnValue = "0";
} else {
returnValue = "5";
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 6);
returnValue = "4";
}
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 4);
returnValue = "3";
}
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 2);
returnValue = "2";
}
}
return returnValue;
}
/**
* 去除传入的行政区划国标编码两位零
*
* @param zoneCode
* @return string
*/
public static String dealZero(String zoneCode) {
if (zoneCode.length() != 8) {
return zoneCode;
} else {
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 6);
}
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 4);
}
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 2);
}
return zoneCode;
}
}
/**
* 去除传入的行政区划国标编码两位零
*
* @param zoneCode
* @return string
*/
public static String dealLongZero(String zoneCode) {
if (zoneCode.length() != 10) {
return zoneCode;
} else {
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 8);
}
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 6);
}
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 4);
}
if (zoneCode.substring(zoneCode.length() - 2).equals("00")) {
zoneCode = zoneCode.substring(0, 2);
}
return zoneCode;
}
}
/**
* 去除多余的0
*
* @param str
* @return String
*/
public static String trimZero(String str) {
String dealZero = "";
String tag = "no";
int size = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == '0') {
for (int j = i; j < str.length(); j++) {
if (str.charAt(j) == '0') {
size = i;
if (j == (str.length() - 1)) {
tag = "yes";
}
} else {
size = 0;
break;
}
}
}
if (tag.equals("yes")) {
break;
}
}
if (size != 0) {
dealZero = str.substring(0, size);
} else {
dealZero = str;
}
return dealZero;
}
/**
* add by zhouzw 根据传入的参数获取子标题的名称 用于医疗资源
*/
public static String getSubTitle(String titleid) {
String myTitle = "";
if ("1".equals(titleid)) {
myTitle = "出版论著";
} else if ("2".equals(titleid)) {
myTitle = "发表论文";
} else if ("3".equals(titleid)) {
myTitle = "获奖科研项目";
} else if ("4".equals(titleid)) {
myTitle = "进修实习人数";
}
return myTitle;
}
/**
* 16进制显示数据
*
* @param value
* 字节数组
* @return
*/
public static String toHexString(byte[] value) {
String newString = "";
for (int i = 0; i < value.length; i++) {
byte b = value[i];
String str = Integer.toHexString(b);
if (str.length() > 2) {
str = str.substring(str.length() - 2);
}
if (str.length() < 2) {
str = "0" + str;
}
newString += str;
}
return newString.toUpperCase();
}
/**
* 把16进制字符串转换成字节数组
*
* @param hex
* @return
*/
public static byte[] hexStringToByte(String hex) {
int len = (hex.length() / 2);
byte[] result = new byte[len];
char[] achar = hex.toCharArray();
for (int i = 0; i < len; i++) {
int pos = i * 2;
result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[pos + 1]));
}
return result;
}
private static byte toByte(char c) {
byte b = (byte) "0123456789ABCDEF".indexOf(c);
return b;
}
/**
* 转化十六进制编码为字符串
*
* @param s
* @return
*/
public static String toStringHex(String s) {
byte[] baKeyword = new byte[s.length() / 2];
for (int i = 0; i < baKeyword.length; i++) {
try {
baKeyword[i] = (byte) (0xff & Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16));
} catch (Exception e) {
e.printStackTrace();
}
}
try {
s = new String(baKeyword, "utf-8 ");// UTF-16le:Not
} catch (Exception e1) {
e1.printStackTrace();
}
return s;
}
}