📄 commonutil.java
字号:
*
*@param format 产生的格式
*@return String 当前时间字符串
*/
public static synchronized String productDateText( String format )
{
SimpleDateFormat sdf = new SimpleDateFormat( format );
Date dt = new Date();
String dateText = sdf.format( dt );
return dateText;
}
/**
* 按照当前的日期产生序列号总共17位,yyyymmddhhmmss,最后三位为毫秒 add by lihg
*
*@return NextID的数据对象
*@exception Exception 异常描述
*/
public static java.lang.Number getNextID()
throws Exception
{
Thread.sleep( 21 );
String result = productDateText( "yyyyMMddHHmmssSSS" );
Long nextid = new Long( result );
return nextid;
}
/**
* 取得几天后的某日
*
*@param strdate 时间字符串
*@param count 天数
*@return 属性 stringOfDay的值
*@exception Exception 异常描述
*/
public static String getNextOfDay( String strdate, int count )
throws Exception
{
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );
Calendar cal = Calendar.getInstance();
Date datetmp = sdf.parse( strdate );
cal.setTime( datetmp );
cal.add( Calendar.DATE, count );
datetmp = cal.getTime();
return sdf.format( datetmp );
}
/**
* 取得 CommonUtil class 的属性nextOfDay
*
*@param strdate 参数描述
*@param count 参数描述
*@return 属性 nextOfDay的值
*@exception Exception 异常描述
*/
public static String getNextOfDay( String strdate, String count )
throws Exception
{
return getNextOfDay( strdate, Integer.parseInt( count ) );
}
/**
* 从一个Url中取得文件名
*
*@param strFile 文件的url
*@return 属性 fileName的值
*/
public static String getFileName( String strFile )
{
return strFile.substring( strFile.lastIndexOf( File.separator ) + 1);
}
/**
* 读取文件内容
*
*@param filepath 文件路径
*@return 文件内容
*@exception Exception 异常描述
*/
public static String readFile( String filepath )
throws Exception
{
FileReader fin = null;
StringBuffer sb = new StringBuffer();
BufferedReader br = null;
try
{ File readfile=new File(filepath);
String templine = null;
if(readfile.exists()){
fin = new FileReader( readfile );
br = new BufferedReader( fin );
while (true) {
templine = br.readLine();
if (templine == null) {
break;
}
else {
sb.append(templine + "\n");
}
}
}else{
sb.append("文件不存在!");
}
} catch ( Exception ex )
{
ex.printStackTrace();
throw new Exception( ex.getMessage() );
} finally
{ if(fin!=null){
fin.close();
br.close();
}
fin = null;
br = null;
}
return sb.toString();
}
/**
* 对特殊字符",","^"处理后的逆向处理 <b>Exemple :</b> <br>
* parseStr("a\ab\bc") 返回结果a,b^c
*
*@param chkstr 要处理的字符串
*@return 处理后的字符串
*/
public static String uParseStr( String chkstr )
{
if ( chkstr == null || chkstr.length() == 0 )
{
return chkstr;
}
StringBuffer buf = new StringBuffer();
char temp;
boolean flag = false;
for ( int i = 0; i < chkstr.length(); i++ )
{
temp = chkstr.charAt( i );
if ( temp == '+' && !flag )
{
flag = true;
} else if ( flag )
{
if ( temp == 'a' )
{
buf.append( ',' );
} else if ( temp == 'b' )
{
buf.append( '^' );
} else if ( temp == '+' )
{
buf.append( "+" );
}
flag = false;
} else
{
buf.append( temp );
}
}
return buf.toString();
}
/**
* 对特殊字符",","^"处理 <b>Exemple :</b> <br>
* parseStr("a,b^c") 返回结果a\ab\bc
*
*@param chkstr 要处理的字符串
*@return 处理后的字符串
*/
public static String parseStr( String chkstr )
{
if ( chkstr == null || chkstr.length() == 0 )
{
return chkstr;
}
StringBuffer buf = new StringBuffer();
char temp;
for ( int i = 0; i < chkstr.length(); i++ )
{
temp = chkstr.charAt( i );
if ( temp == '+' )
{
buf.append( "++" );
} else if ( temp == ',' )
{
buf.append( "+a" );
} else if ( temp == '^' )
{
buf.append( "+b" );
} else
{
buf.append( temp );
}
}
return buf.toString();
}
/**
* 将组织字符串进行解析, 例如role:555,unit:222按逗号分解成数组
*
*@param mtMaster 组织字符串
*@return 解析后的字符串数组
*/
public static String[] getMasterID( String mtMaster )
{
String[] list = CommonUtil.StringToArray( mtMaster, "," );
return list;
}
/**
* 将组织id转换成组织名称用于显示
*
*@param list 组织id列表
*@return 组织名称
*/
/*
public static String[] getMasterName( String[] list )
{
String[] result = new String[list.length];
for ( int i = 0; i < list.length; i++ )
{
result[i] = getMasterName( list[i] );
}
return result;
}
/**
* 取得 CommonUtil class 的属性perMasterName
*
*@param list 参数描述
*@return 属性 perMasterName的值
*/
/*
public static String getMasterName( String list )
{
String result = "";
if ( list.indexOf( PERSON ) != -1 )
{
result = getPersonName( list );
} else if ( list.indexOf( ROLE ) != -1 )
{
result = getRoleName( list );
} else if ( list.indexOf( UNIT ) != -1 )
{
result = getUnitName( list );
} else if ( list.indexOf( POST ) != -1 )
{
result = getPostName( list );
}
//System.out.println("result="+result);
return result;
}
/**
* 根据人员id取得人员名称
*
*@param personId 人员id
*@return 人员名称
*/
/*
private static String getPersonName( String personId )
{
LdapExtendTool ldapTool = new LdapExtendTool();
ldapTool.connection();
personId = CommonUtil.uParseStr( getName( personId, PERSON ) );
NWPerson nwP = ( NWPerson ) ldapTool.getPersonByUid( personId );
String result = "";
if ( nwP != null )
{
result = nwP.getName();
}
ldapTool.close();
return result;
}
/**
* 根据用户id取得用户名称
*
*@param userid 参数描述
*@return 属性 userName的值
*/
/*
public static String getUserName( String userid )
{
LdapExtendTool ldapTool = new LdapExtendTool();
ldapTool.connection();
NWPerson nwP = ( NWPerson ) ldapTool.getPersonByUid( userid );
String result = "";
if ( nwP != null )
{
result = nwP.getName();
}
ldapTool.close();
return result;
}
/**
* 取得角色名称
*
*@param roleId 角色id
*@return 角色名称
*/
private static String getRoleName( String roleId )
{
String result = CommonUtil.uParseStr( getName( roleId, ROLE ) ) + "";
return result;
}
/**
* 取得组织单元名称
*
*@param unitId 组织id
*@return 组织名称
*/
private static String getUnitName( String unitId )
{
String result = CommonUtil.uParseStr( getName( unitId, UNIT ) ) + "";
return result;
}
/**
* 取得 岗位名称
*
*@param postId 岗位id
*@return 岗位名称
*/
private static String getPostName( String postId )
{
String post = CommonUtil.uParseStr( getName( postId, POST ) );
String[] list = CommonUtil.StringToArray( post, "^" );
String result = CommonUtil.uParseStr( list[1] ) + "";
return result;
}
/**
* 取得 岗位名称
*
*@param postId 岗位id
*@return 岗位名称
*/
private static String getPostUnitName( String postId )
{
String result = postId.substring( postId.indexOf( "^" ) );
return result;
}
/**
* 取得 CommonUtil class 的属性departMent
*
*@param userid 参数描述
*@return 属性 departMent的值
*/
/*
public static String getDepartMent( String userid )
{
LdapExtendTool ldapTool = new LdapExtendTool();
ldapTool.connection();
NWPerson nwPerson = ldapTool.getPersonByUid( userid );
String departMent = nwPerson.getDepartment();
ldapTool.close();
if ( departMent == null )
{
departMent = "";
}
return departMent;
}
/**
* 取得组织id 例如 unit:aaa 结果为aaa
*
*@param name id
*@param reg 前缀 eg:unit,role,person,post
*@return 名称
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -