- 浏览: 123605 次
最新评论
-
gaoxikun:
看起来很齐全,很完美,但是不知道从哪里下载 。
myeclipse插件简单介绍 -
gaoxikun:
亲,能把这个集成了插件的myeclipse 6.5给我一下吗, ...
myeclipse插件简单介绍 -
hotsmile:
不错!!!!!!!!!
myeclipse插件简单介绍
public static void modifyProperties(Properties properties)
{
InputStream inputStream = null;
OutputStream fos = null;
Properties tempProper = new Properties();
File file = new File(Constant.CipherKey_FILE_PATH);
try
{
inputStream = new FileInputStream(file);
tempProper.load(inputStream);
fos = new FileOutputStream(file);
tempProper.setProperty("userName", properties.getProperty("userName"));
tempProper.setProperty("passwd", properties.getProperty("passwd"));
tempProper.store(fos, null);
}
catch (Exception e)
{
log.error("Tools calss Setting PropertyValue is fail!"+e.getMessage());
}finally
{
try
{
if(null != fos)
{
fos.close();
}
if(null != inputStream)
{
inputStream.close();
}
}
catch (IOException e)
{
log.error("Tools calss close OutputStream fial!"+e.getMessage());
}
}
}
=================================================
package com.huawei.idesign.tablesetdatas.dataprocess.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import org.apache.log4j.PropertyConfigurator;
import com.as.oms.log.OMSLog;
import com.as.oms.log.OMSLogFactory;
import com.huawei.authorization.HttpValidate;
import com.huawei.idesign.util.DataBaseException;
/**
* 工具类
*/
public class Tools
{
static OMSLog log = Tools.getLog(Tools.class);
/**
* 文件内容集合 key :实际文件名称 value :Map<实际文件中的sheet名称, Map<表字段名称,
* String[文件中列索引,文件中实际列名]>>
*/
private static Map<String, Map<String, Map<String, String[]>>> fileMap =
null;
/**
* 名称集合 <文件名称,<实际文件中的sheet名称,表名(常量)>
*/
private static Map<String, Map<String, String>> fileNameMap = null;
/**
* 表名称对应的列集合 <表名,<列名,String[文件中列索引,文件中实际列名]>
*/
private static Map<String, Map<String, String[]>> tableMap = null;
/**
* 数据表集合 key :表名(常量) value :map<列索引,列名>
*/
private static Map<String, Map<Integer, String>> dataBaseMap = null;
/**
* 文件下的sheet名称集合(按读入顺序),导出
*/
private static Map<String, List<String>> fileSheetNameMap = null;
/**
* 支持导出文件名称集合
*/
private static List<String> exportFileNameList = null;
/**
* 插入
*/
public final static int insert = 1;
/**
* 修改
*/
public final static int update = 2;
/**
* 删除
*/
public final static int delete = 3;
/**
* 文件语言版本
*/
private static Map<String, String> fileLanguageVersion = null;
/**
* 取得日志
*
* @param clas
* @return
*/
public static OMSLog getLog(Class<?> clas)
{
String log4jName = getStringNoNull(System.getProperty("log4jname"));
if (!"".equals(log4jName))
{
PropertyConfigurator.configure(Constant.PROJECT_DIR + "/config/"
+ log4jName + ".properties");
}
return OMSLogFactory.getLog(clas);
}
/**
* 得到对应资源的资源实例
*
* @param resourceFilePath 资源文件路径
* @return ResourceBundle 资源实例
*/
public static ResourceBundle getResourceBundle(String resourceFilePath)
{
ResourceBundle resourceBundle =
ResourceBundle.getBundle(resourceFilePath);
return resourceBundle;
}
/**
* 得到对应资源的资源实例
*
* @param resourceFilePath 资源文件路径
* @return ResourceBundle 资源实例
*/
public static ResourceBundle getResourceBundle(String resourceFilePath,
Locale locale)
{
ResourceBundle resourceBundle =
ResourceBundle.getBundle(resourceFilePath, locale);
return resourceBundle;
}
/**
* 得到属性文件实例
*/
public static Properties getPropertiesByFile(String filePath)
{
InputStream inputStream = null;
Properties properties = new Properties();
try
{
File file = new File(filePath);
inputStream = new FileInputStream(file);
properties.load(inputStream);
}
catch (Exception e)
{
log.error(e.getMessage(), e);
}
finally
{
try
{
inputStream.close();
}
catch (IOException e)
{
log.error(e.getMessage(), e);
}
}
return properties;
}
/**
* 初始化导入文件功能的配置文件
*/
private static void initConfig()
{
XMLReader reader = new XMLReader();
fileMap = reader.readConfigXMLFile();
dataBaseMap = reader.readDatabaseXMLFile();
fileNameMap = reader.getSheetNameMap();
exportFileNameList = reader.getExportFileNameList();
tableMap = reader.getTableMap();
fileSheetNameMap = reader.getFileSheetNameMap();
fileLanguageVersion = reader.getFileLanguageVersion();
}
/**
* 支持导出文件名称集合
*/
public static List<String> getExportFileNameList()
{
if (exportFileNameList == null)
{
initConfig();
}
return exportFileNameList;
}
/**
* 根据表名称从database.xml文件中得到表字段集合
*
* @param tableName 表名称
* @return Map<Integer,String> 表字段集合<字段索引,字段名称>
*/
public static Map<Integer, String> getColumnMapByTableName(String tableName)
{
if (dataBaseMap == null)
{
initConfig();
}
return dataBaseMap.get(tableName.toLowerCase(Locale.getDefault()));
}
/**
* 得到对应的EXCEL文件内容集合
*
* @param fileName 文件名称
* @return Map<String, Map<String, String[]>> EXCEL文件内容集合
*/
public static Map<String, Map<String, String[]>> getSheetsByFile(
String fileName)
{
if (fileMap == null)
{
initConfig();
}
return fileMap.get(fileName.toLowerCase(Locale.getDefault()));
}
/**
* 得到对应的EXCEL文件内一个sheet页的内容集合
*
* @param fileName 文件名称
* @param sheetName sheet页名称
* @return Map<String, String[]> 一个sheet页的内容集合<表列字段名称,[文件列索引,文件列名]>
*/
public static Map<String, String[]> getColumnBySheet(String fileName,
String sheetName)
{
Map<String, Map<String, String[]>> map =
getSheetsByFile(fileName.toLowerCase(Locale.getDefault()));
return map.get(sheetName.toLowerCase(Locale.getDefault()));
}
/**
* 得到表名对应配置的列属性集合
*
* @param fileName 表名称
* @return Map<String, String[]> map<表列字段名称,[文件列索引,文件列名]>
*/
public static Map<String, String[]> getColumnByTableName(String tableName)
{
if (tableMap == null)
{
initConfig();
}
return tableMap.get(tableName.toLowerCase(Locale.getDefault()));
}
/**
* 得到EXCEL中sheet页对应的表名
*
* @param sheetName sheet页名
* @return String 表名
*/
public static String getTableName(String fileName, String sheetName)
{
if (fileNameMap == null)
{
initConfig();
}
return fileNameMap.get(fileName.toLowerCase(Locale.getDefault())).get(
sheetName.toLowerCase(Locale.getDefault()));
}
/**
* 得到EXCEL文件中sheet页的名称集合
*
* @return List<String> sheet页名集合,按读入顺序
*/
public static List<String> getSheetNameByFileName(String fileName)
{
if (fileSheetNameMap == null)
{
initConfig();
}
return fileSheetNameMap.get(fileName.toLowerCase(Locale.getDefault()));
}
/**
* 配置文件中的文件集合
*
* @return Map<实际文件中的sheet名称, Map<表字段名称, String[文件中列索引,文件中实际列名]>>
*/
public static Map<String, Map<String, Map<String, String[]>>> getFileMap()
{
if (fileMap == null)
{
initConfig();
}
return fileMap;
}
/**
* 取当前数据库中数据版本
*
* @return String 当前数据版本
*/
public static int getDataBaseVersion(int languageId)
{
int version = 0;
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try
{
connection = JdbcUtil.getConnection();
statement = connection.createStatement();
rs =
statement
.executeQuery("select Version,languageId from version where languageId="
+ languageId);
while (rs.next())
{
String s = rs.getString("version");
version = Integer.parseInt(s);
}
}
catch (DataBaseException e)
{
log.error(e.getMessage(), e);
}
catch (SQLException e)
{
log.error(e.getMessage(), e);
}
finally
{
JdbcUtil.release(rs, statement);
}
return version;
}
/**
* 取出当前表中最大ID值
*
* @return 表中ID值
*/
public static long getTableMaxID(String tableName, String idName)
{
long id = 0;
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try
{
connection = JdbcUtil.getConnection();
statement = connection.createStatement();
rs =
statement.executeQuery("select max(" + idName + ") from "
+ tableName);
while (rs.next())
{
id = rs.getLong(1);
}
}
catch (DataBaseException e)
{
log.error(e.getMessage(), e);
}
catch (SQLException e)
{
log.error(e.getMessage(), e);
}
finally
{
JdbcUtil.release(rs, statement);
}
id++;
return id;
}
/**
* 取出当前表中最大ID值(默认ID列名称为“id”)
*
* @return 表中ID值
*/
public static long getTableMaxID(String tableName)
{
return getTableMaxID(tableName, "id");
}
/**
* 请空表数据
*
* @param histableName 表名
* @throws DataBaseException
*/
public static void clearTableData(String tableName)
throws DataBaseException
{
String sql = "delete from " + tableName;
PreparedStatement preparedStatement = null;
try
{
preparedStatement = JdbcUtil.getConnection().prepareStatement(sql);
preparedStatement.execute();
}
catch (SQLException e)
{
throw new DataBaseException(e.getMessage(), e);
}
finally
{
JdbcUtil.release(null, preparedStatement);
}
}
/**
* 从文件路径中取出文件名称,不包含文件类型后缀
*
* @param filePath
* @return
*/
public static String getFileNameFromFilePath(String filePath)
{
String fileName =
filePath.substring(filePath.lastIndexOf("\\") + 1,
filePath.lastIndexOf("."));
// 处理有些文件配置路径为test/file.xml格式
if (fileName.indexOf("/") != -1)
{
fileName =
fileName.substring(fileName.lastIndexOf("/") + 1,
fileName.length());
}
return fileName;
}
/**
* 获取操作类型
*
* @param action
* @return
*/
public static String getOperationByAction(int action)
{
String op = "";
switch (action)
{
case insert:
op = Constant.OPERATION_CREATE;
break;
case update:
op = Constant.OPERATION_UPDATE;
break;
case delete:
op = Constant.OPERATION_DELETE;
break;
default:
break;
}
return op;
}
/**
* 获取操作类型对应值
*
* @param action
* @return
*/
public static int getActionByOperation(String operation)
{
int action = 0;
if (Constant.OPERATION_CREATE.equalsIgnoreCase(operation))
{
action = insert;
}
else if (Constant.OPERATION_UPDATE.equalsIgnoreCase(operation))
{
action = update;
}
else if (Constant.OPERATION_DELETE.equalsIgnoreCase(operation))
{
action = delete;
}
return action;
}
/**
* 得到文件中配置版本号子,如果配置不正确返-1。
*
* @return int 文件中配置版本号
*/
public static int getFileVersion(int languageId, ExcelReader excelReader)
{
int result = 0;
try
{
Locale locale = Locale.getDefault();
if (languageId == 1)
{
locale = Locale.CHINA;
}
else if (languageId == 2)
{
locale = Locale.US;
}
String fileVersion =
getResourceBundle(
"com.huawei.idesign.tablesetdatas.dataprocess.properties.tool",
locale).getString("file_version");
for (int i = 0; i < excelReader.getSheetNum(); i++)
{
String execlSheetName = excelReader.getSheetNameByIndex(i);
if (fileVersion.equalsIgnoreCase(execlSheetName))
{
List<List<String>> list = excelReader.getAllData(i);
String version = list.get(0).get(0);
result = (int) Double.parseDouble(version);
}
}
}
catch (Exception e)
{
log.error(e.getMessage(), e);
}
return result;
}
/**
* 文件语言版本
*
* @return map<文件名,语言版本>
*/
public static Map<String, String> getFileLanguageVersion()
{
if (fileLanguageVersion == null)
{
initConfig();
}
return fileLanguageVersion;
}
/**
* 将excel中的列索引转换为下标
*
* @param op
* @return
*/
public static int getIndex(String op)
{
String alphabet = "abcdefghijklmnopqrstuvwxyz";
try
{
// 如果是数字,直接返回,是字母再转换
int index = Integer.parseInt(op) - 1;
return index;
}
catch (NumberFormatException e)
{
String s = op.toLowerCase(Locale.getDefault());
if (s.length() == 1)
{
return alphabet.indexOf(s);
}
else if (s.length() == 2)
{
String fir = s.substring(0, 1);
String sed = s.substring(1, 2);
int f =
(alphabet.indexOf(fir) + 1) * 26 + alphabet.indexOf(sed);
return f;
}
else
{
return -1;
}
}
}
public static String getStringNoNull(Object str)
{
if (str == null)
{
return "";
}
else
{
return str.toString().trim();
}
}
public static String getPropertyByString(String key, String defaultValue)
{
return getStringNoNull(Tools.getPropertiesByFile(
Constant.CipherKey_FILE_PATH).getProperty(key, defaultValue));
}
/**
* 需要修改的properties键值对集合
* @param listproperties
* @see [类、类#方法、类#成员]
*/
public static void modifyProperties(Properties properties)
{
InputStream inputStream = null;
OutputStream fos = null;
Properties tempProper = new Properties();
File file = new File(Constant.CipherKey_FILE_PATH);
try
{
inputStream = new FileInputStream(file);
tempProper.load(inputStream);
fos = new FileOutputStream(file);
tempProper.setProperty("userName", properties.getProperty("userName"));
tempProper.setProperty("passwd", properties.getProperty("passwd"));
tempProper.store(fos, null);
}
catch (Exception e)
{
log.error("Tools calss Setting PropertyValue is fail!"+e.getMessage());
}finally
{
try
{
if(null != fos)
{
fos.close();
}
if(null != inputStream)
{
inputStream.close();
}
}
catch (IOException e)
{
log.error("Tools calss close OutputStream fial!"+e.getMessage());
}
}
}
public static int getPropertyByInt(String key, int defaultValue)
{
int result = defaultValue;
String strValue = getStringNoNull(Tools.getPropertiesByFile(
Constant.CipherKey_FILE_PATH).getProperty(key));
try {
result = Integer.parseInt(strValue);
} catch (NumberFormatException e) {
log.error(e.getMessage());
}
return result;
}
public static boolean authorise()
{
/**
* 增加用户鉴权
*/
boolean isLogin = false;
try
{
//得到解密后的passwd值
String tempPasswd = CipherUtil.decryptPwd(getPropertyByString("passwd",""));
//得到配置文件中的user值
String tempUser = getPropertyByString("userName","");
//得到配置的URL
String tempUrl = getPropertyByString("url","");
isLogin = HttpValidate.validConnector(tempUser, tempPasswd, tempUrl);
// if("admin".equals(tempUser) && "admin".equals(tempPasswd))
// {
// isLogin = true;
// }
}
catch (Exception e1)
{
log.error("CFGSelectDialog calss Getting PropertyValue is fail!"+e1.getMessage());
}
return isLogin;
}
}
{
InputStream inputStream = null;
OutputStream fos = null;
Properties tempProper = new Properties();
File file = new File(Constant.CipherKey_FILE_PATH);
try
{
inputStream = new FileInputStream(file);
tempProper.load(inputStream);
fos = new FileOutputStream(file);
tempProper.setProperty("userName", properties.getProperty("userName"));
tempProper.setProperty("passwd", properties.getProperty("passwd"));
tempProper.store(fos, null);
}
catch (Exception e)
{
log.error("Tools calss Setting PropertyValue is fail!"+e.getMessage());
}finally
{
try
{
if(null != fos)
{
fos.close();
}
if(null != inputStream)
{
inputStream.close();
}
}
catch (IOException e)
{
log.error("Tools calss close OutputStream fial!"+e.getMessage());
}
}
}
=================================================
package com.huawei.idesign.tablesetdatas.dataprocess.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import org.apache.log4j.PropertyConfigurator;
import com.as.oms.log.OMSLog;
import com.as.oms.log.OMSLogFactory;
import com.huawei.authorization.HttpValidate;
import com.huawei.idesign.util.DataBaseException;
/**
* 工具类
*/
public class Tools
{
static OMSLog log = Tools.getLog(Tools.class);
/**
* 文件内容集合 key :实际文件名称 value :Map<实际文件中的sheet名称, Map<表字段名称,
* String[文件中列索引,文件中实际列名]>>
*/
private static Map<String, Map<String, Map<String, String[]>>> fileMap =
null;
/**
* 名称集合 <文件名称,<实际文件中的sheet名称,表名(常量)>
*/
private static Map<String, Map<String, String>> fileNameMap = null;
/**
* 表名称对应的列集合 <表名,<列名,String[文件中列索引,文件中实际列名]>
*/
private static Map<String, Map<String, String[]>> tableMap = null;
/**
* 数据表集合 key :表名(常量) value :map<列索引,列名>
*/
private static Map<String, Map<Integer, String>> dataBaseMap = null;
/**
* 文件下的sheet名称集合(按读入顺序),导出
*/
private static Map<String, List<String>> fileSheetNameMap = null;
/**
* 支持导出文件名称集合
*/
private static List<String> exportFileNameList = null;
/**
* 插入
*/
public final static int insert = 1;
/**
* 修改
*/
public final static int update = 2;
/**
* 删除
*/
public final static int delete = 3;
/**
* 文件语言版本
*/
private static Map<String, String> fileLanguageVersion = null;
/**
* 取得日志
*
* @param clas
* @return
*/
public static OMSLog getLog(Class<?> clas)
{
String log4jName = getStringNoNull(System.getProperty("log4jname"));
if (!"".equals(log4jName))
{
PropertyConfigurator.configure(Constant.PROJECT_DIR + "/config/"
+ log4jName + ".properties");
}
return OMSLogFactory.getLog(clas);
}
/**
* 得到对应资源的资源实例
*
* @param resourceFilePath 资源文件路径
* @return ResourceBundle 资源实例
*/
public static ResourceBundle getResourceBundle(String resourceFilePath)
{
ResourceBundle resourceBundle =
ResourceBundle.getBundle(resourceFilePath);
return resourceBundle;
}
/**
* 得到对应资源的资源实例
*
* @param resourceFilePath 资源文件路径
* @return ResourceBundle 资源实例
*/
public static ResourceBundle getResourceBundle(String resourceFilePath,
Locale locale)
{
ResourceBundle resourceBundle =
ResourceBundle.getBundle(resourceFilePath, locale);
return resourceBundle;
}
/**
* 得到属性文件实例
*/
public static Properties getPropertiesByFile(String filePath)
{
InputStream inputStream = null;
Properties properties = new Properties();
try
{
File file = new File(filePath);
inputStream = new FileInputStream(file);
properties.load(inputStream);
}
catch (Exception e)
{
log.error(e.getMessage(), e);
}
finally
{
try
{
inputStream.close();
}
catch (IOException e)
{
log.error(e.getMessage(), e);
}
}
return properties;
}
/**
* 初始化导入文件功能的配置文件
*/
private static void initConfig()
{
XMLReader reader = new XMLReader();
fileMap = reader.readConfigXMLFile();
dataBaseMap = reader.readDatabaseXMLFile();
fileNameMap = reader.getSheetNameMap();
exportFileNameList = reader.getExportFileNameList();
tableMap = reader.getTableMap();
fileSheetNameMap = reader.getFileSheetNameMap();
fileLanguageVersion = reader.getFileLanguageVersion();
}
/**
* 支持导出文件名称集合
*/
public static List<String> getExportFileNameList()
{
if (exportFileNameList == null)
{
initConfig();
}
return exportFileNameList;
}
/**
* 根据表名称从database.xml文件中得到表字段集合
*
* @param tableName 表名称
* @return Map<Integer,String> 表字段集合<字段索引,字段名称>
*/
public static Map<Integer, String> getColumnMapByTableName(String tableName)
{
if (dataBaseMap == null)
{
initConfig();
}
return dataBaseMap.get(tableName.toLowerCase(Locale.getDefault()));
}
/**
* 得到对应的EXCEL文件内容集合
*
* @param fileName 文件名称
* @return Map<String, Map<String, String[]>> EXCEL文件内容集合
*/
public static Map<String, Map<String, String[]>> getSheetsByFile(
String fileName)
{
if (fileMap == null)
{
initConfig();
}
return fileMap.get(fileName.toLowerCase(Locale.getDefault()));
}
/**
* 得到对应的EXCEL文件内一个sheet页的内容集合
*
* @param fileName 文件名称
* @param sheetName sheet页名称
* @return Map<String, String[]> 一个sheet页的内容集合<表列字段名称,[文件列索引,文件列名]>
*/
public static Map<String, String[]> getColumnBySheet(String fileName,
String sheetName)
{
Map<String, Map<String, String[]>> map =
getSheetsByFile(fileName.toLowerCase(Locale.getDefault()));
return map.get(sheetName.toLowerCase(Locale.getDefault()));
}
/**
* 得到表名对应配置的列属性集合
*
* @param fileName 表名称
* @return Map<String, String[]> map<表列字段名称,[文件列索引,文件列名]>
*/
public static Map<String, String[]> getColumnByTableName(String tableName)
{
if (tableMap == null)
{
initConfig();
}
return tableMap.get(tableName.toLowerCase(Locale.getDefault()));
}
/**
* 得到EXCEL中sheet页对应的表名
*
* @param sheetName sheet页名
* @return String 表名
*/
public static String getTableName(String fileName, String sheetName)
{
if (fileNameMap == null)
{
initConfig();
}
return fileNameMap.get(fileName.toLowerCase(Locale.getDefault())).get(
sheetName.toLowerCase(Locale.getDefault()));
}
/**
* 得到EXCEL文件中sheet页的名称集合
*
* @return List<String> sheet页名集合,按读入顺序
*/
public static List<String> getSheetNameByFileName(String fileName)
{
if (fileSheetNameMap == null)
{
initConfig();
}
return fileSheetNameMap.get(fileName.toLowerCase(Locale.getDefault()));
}
/**
* 配置文件中的文件集合
*
* @return Map<实际文件中的sheet名称, Map<表字段名称, String[文件中列索引,文件中实际列名]>>
*/
public static Map<String, Map<String, Map<String, String[]>>> getFileMap()
{
if (fileMap == null)
{
initConfig();
}
return fileMap;
}
/**
* 取当前数据库中数据版本
*
* @return String 当前数据版本
*/
public static int getDataBaseVersion(int languageId)
{
int version = 0;
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try
{
connection = JdbcUtil.getConnection();
statement = connection.createStatement();
rs =
statement
.executeQuery("select Version,languageId from version where languageId="
+ languageId);
while (rs.next())
{
String s = rs.getString("version");
version = Integer.parseInt(s);
}
}
catch (DataBaseException e)
{
log.error(e.getMessage(), e);
}
catch (SQLException e)
{
log.error(e.getMessage(), e);
}
finally
{
JdbcUtil.release(rs, statement);
}
return version;
}
/**
* 取出当前表中最大ID值
*
* @return 表中ID值
*/
public static long getTableMaxID(String tableName, String idName)
{
long id = 0;
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try
{
connection = JdbcUtil.getConnection();
statement = connection.createStatement();
rs =
statement.executeQuery("select max(" + idName + ") from "
+ tableName);
while (rs.next())
{
id = rs.getLong(1);
}
}
catch (DataBaseException e)
{
log.error(e.getMessage(), e);
}
catch (SQLException e)
{
log.error(e.getMessage(), e);
}
finally
{
JdbcUtil.release(rs, statement);
}
id++;
return id;
}
/**
* 取出当前表中最大ID值(默认ID列名称为“id”)
*
* @return 表中ID值
*/
public static long getTableMaxID(String tableName)
{
return getTableMaxID(tableName, "id");
}
/**
* 请空表数据
*
* @param histableName 表名
* @throws DataBaseException
*/
public static void clearTableData(String tableName)
throws DataBaseException
{
String sql = "delete from " + tableName;
PreparedStatement preparedStatement = null;
try
{
preparedStatement = JdbcUtil.getConnection().prepareStatement(sql);
preparedStatement.execute();
}
catch (SQLException e)
{
throw new DataBaseException(e.getMessage(), e);
}
finally
{
JdbcUtil.release(null, preparedStatement);
}
}
/**
* 从文件路径中取出文件名称,不包含文件类型后缀
*
* @param filePath
* @return
*/
public static String getFileNameFromFilePath(String filePath)
{
String fileName =
filePath.substring(filePath.lastIndexOf("\\") + 1,
filePath.lastIndexOf("."));
// 处理有些文件配置路径为test/file.xml格式
if (fileName.indexOf("/") != -1)
{
fileName =
fileName.substring(fileName.lastIndexOf("/") + 1,
fileName.length());
}
return fileName;
}
/**
* 获取操作类型
*
* @param action
* @return
*/
public static String getOperationByAction(int action)
{
String op = "";
switch (action)
{
case insert:
op = Constant.OPERATION_CREATE;
break;
case update:
op = Constant.OPERATION_UPDATE;
break;
case delete:
op = Constant.OPERATION_DELETE;
break;
default:
break;
}
return op;
}
/**
* 获取操作类型对应值
*
* @param action
* @return
*/
public static int getActionByOperation(String operation)
{
int action = 0;
if (Constant.OPERATION_CREATE.equalsIgnoreCase(operation))
{
action = insert;
}
else if (Constant.OPERATION_UPDATE.equalsIgnoreCase(operation))
{
action = update;
}
else if (Constant.OPERATION_DELETE.equalsIgnoreCase(operation))
{
action = delete;
}
return action;
}
/**
* 得到文件中配置版本号子,如果配置不正确返-1。
*
* @return int 文件中配置版本号
*/
public static int getFileVersion(int languageId, ExcelReader excelReader)
{
int result = 0;
try
{
Locale locale = Locale.getDefault();
if (languageId == 1)
{
locale = Locale.CHINA;
}
else if (languageId == 2)
{
locale = Locale.US;
}
String fileVersion =
getResourceBundle(
"com.huawei.idesign.tablesetdatas.dataprocess.properties.tool",
locale).getString("file_version");
for (int i = 0; i < excelReader.getSheetNum(); i++)
{
String execlSheetName = excelReader.getSheetNameByIndex(i);
if (fileVersion.equalsIgnoreCase(execlSheetName))
{
List<List<String>> list = excelReader.getAllData(i);
String version = list.get(0).get(0);
result = (int) Double.parseDouble(version);
}
}
}
catch (Exception e)
{
log.error(e.getMessage(), e);
}
return result;
}
/**
* 文件语言版本
*
* @return map<文件名,语言版本>
*/
public static Map<String, String> getFileLanguageVersion()
{
if (fileLanguageVersion == null)
{
initConfig();
}
return fileLanguageVersion;
}
/**
* 将excel中的列索引转换为下标
*
* @param op
* @return
*/
public static int getIndex(String op)
{
String alphabet = "abcdefghijklmnopqrstuvwxyz";
try
{
// 如果是数字,直接返回,是字母再转换
int index = Integer.parseInt(op) - 1;
return index;
}
catch (NumberFormatException e)
{
String s = op.toLowerCase(Locale.getDefault());
if (s.length() == 1)
{
return alphabet.indexOf(s);
}
else if (s.length() == 2)
{
String fir = s.substring(0, 1);
String sed = s.substring(1, 2);
int f =
(alphabet.indexOf(fir) + 1) * 26 + alphabet.indexOf(sed);
return f;
}
else
{
return -1;
}
}
}
public static String getStringNoNull(Object str)
{
if (str == null)
{
return "";
}
else
{
return str.toString().trim();
}
}
public static String getPropertyByString(String key, String defaultValue)
{
return getStringNoNull(Tools.getPropertiesByFile(
Constant.CipherKey_FILE_PATH).getProperty(key, defaultValue));
}
/**
* 需要修改的properties键值对集合
* @param listproperties
* @see [类、类#方法、类#成员]
*/
public static void modifyProperties(Properties properties)
{
InputStream inputStream = null;
OutputStream fos = null;
Properties tempProper = new Properties();
File file = new File(Constant.CipherKey_FILE_PATH);
try
{
inputStream = new FileInputStream(file);
tempProper.load(inputStream);
fos = new FileOutputStream(file);
tempProper.setProperty("userName", properties.getProperty("userName"));
tempProper.setProperty("passwd", properties.getProperty("passwd"));
tempProper.store(fos, null);
}
catch (Exception e)
{
log.error("Tools calss Setting PropertyValue is fail!"+e.getMessage());
}finally
{
try
{
if(null != fos)
{
fos.close();
}
if(null != inputStream)
{
inputStream.close();
}
}
catch (IOException e)
{
log.error("Tools calss close OutputStream fial!"+e.getMessage());
}
}
}
public static int getPropertyByInt(String key, int defaultValue)
{
int result = defaultValue;
String strValue = getStringNoNull(Tools.getPropertiesByFile(
Constant.CipherKey_FILE_PATH).getProperty(key));
try {
result = Integer.parseInt(strValue);
} catch (NumberFormatException e) {
log.error(e.getMessage());
}
return result;
}
public static boolean authorise()
{
/**
* 增加用户鉴权
*/
boolean isLogin = false;
try
{
//得到解密后的passwd值
String tempPasswd = CipherUtil.decryptPwd(getPropertyByString("passwd",""));
//得到配置文件中的user值
String tempUser = getPropertyByString("userName","");
//得到配置的URL
String tempUrl = getPropertyByString("url","");
isLogin = HttpValidate.validConnector(tempUser, tempPasswd, tempUrl);
// if("admin".equals(tempUser) && "admin".equals(tempPasswd))
// {
// isLogin = true;
// }
}
catch (Exception e1)
{
log.error("CFGSelectDialog calss Getting PropertyValue is fail!"+e1.getMessage());
}
return isLogin;
}
}
发表评论
-
java 中的文件读取信息
2013-03-11 08:56 1058import java.io.BufferedReader ... -
oracle结果集的操作信息
2013-03-04 16:22 914众所周知的几个结果集集合操作命令,今天详细地测试了一下,发现一 ... -
js正则表达式(二)
2013-01-09 11:20 885首先加个重要的东西 * ... -
java路径问题以及java对文件的基本操作信息
2012-12-19 14:09 9751.基本概念的理解 绝对 ... -
JS正则表达式
2012-11-15 17:10 851function isTrueName(s) { var pa ... -
java公用类
2012-11-15 17:05 864package cn.org.jshuwei.j2ee.uti ... -
java规范信息
2012-10-30 08:44 27881 一、判断选择题(每题1分) 1. 表达式要在低优先级操作符 ... -
java时间公用和StringUnitl以及java调用存储过程
2012-10-16 17:38 16151 构建存储过程的语句信息 /** * 从Fun ... -
jquery批量删除
2012-09-20 14:31 3389<%@ page language="java ... -
java操作execl文件(2003与2007不兼容问题)
2012-09-19 14:49 1476package com.huawei.bss.execlCom ... -
java操作execl文件
2012-09-19 08:53 986package com.huawei.bss.execlCom ... -
通过onkeypress和onkeydown事件禁用键盘中某些键
2012-09-17 15:09 953http://zywang.iteye.com/blog/70 ... -
java学习的一点记录
2012-09-12 16:15 1235public class Tools { stati ... -
STRUTS2与JSON的LIST和MAP对象返回
2012-09-07 14:57 6685<%@ page language="java ... -
struts2 iterator双重叠迭取值
2012-09-05 18:08 1259•效果:Map<String,List<Derpa ... -
struts2多个配置文件的应用
2012-09-05 10:10 1075<!-- 定义Struts2的核心Filter --&g ... -
java中使用net.sf.json对json进行解析
2012-09-04 12:24 1023作者: http://zhangnet1.iteye.com/ ... -
XML的TreeConfig
2012-09-04 10:20 912/** * <?xml version=&qu ... -
JSON与 STRuts2
2012-09-04 10:20 1310package com.huawei.cmclient.com ... -
sql在不同数据库查询前几条数据
2012-09-03 15:14 800sql在不同数据库查询前几条数据 1. ORACLE ...
相关推荐
CommentedProperties代码 博文链接:https://brokendreams.iteye.com/blog/1932875
进行properties文件的批量处理工具,能够用来改动部分参数而进行的文本提取修改工具。
Java读取、修改utils.properties工具类,可直接拿去用。
Java 修改Properties文件,src下或者指定路径下的文件。 如果需要修改Properties文件,打成Jar包后又不可以修改。 只能把Properties文件提出jar外进行Properties资源文件修改。
此工具类只用于Java后端在操作Properties文件的时候写的工具类,方便properties文件的存取操作
java 改变Properties文件中的键值 java 改变Properties文件中的键值
NULL 博文链接:https://it586.iteye.com/blog/1676577
主要介绍了Java实现的properties文件动态修改并自动保存工具类,可实现针对properties配置文件的相关修改与保存功能,需要的朋友可以参考下
本资源是解决写Properties出现中文乱码的源代码,不用作任何修改就可以将中文写入Properties,跟乱码说拜拜
直接用Eclipse打开就可以运行,运行后结果在bin目录下。
Properties Editor属性资源文件编辑修改工具-含JRE环境安装版
NULL 博文链接:https://shangwq.iteye.com/blog/1699032
ava中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件,配置文件中很多变量是经常改变的,这样做也是为了方便用户,让用户能够脱离程序本身去...
通俗点讲就相当于定义一个变量,在这个文件里面定义这些变量的值,在程序里面可以调用这些变量,好处就是,如果程序中的参数值需要变动,直接来改这个.property文件就可以了,不用在去修改源代码。 优点在于有利于...
Windows 7 System Properties Logo Changer 修改系统默认徽标
4.在myeclipse中刷新新建的web工程之后找到resources/jeecg目录下 jeecg_config.properties与jeecg_database.properties修改此2个文件达到你自身项目所需要 5.右键项目build path一下 configuration build path 后将...
主要介绍了在python中修改.properties文件的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
java打印日志文件所需要的配置文件log4j.properties,根据自己的需求进行修改。
eclipse用插件会把中文转换...这个插件不是propedit,是SimplePropertiesEditor,是别人写的,功能差不多,但是存在几个bug,而且和propedit一样会把ascii转为小写,我在其基础上修改了我看到的bug,另外把ascii转换为大写
主要介绍了Python实现加载及解析properties配置文件的方法,结合实例形式分析了Python针对properties配置文件的加载、读取及解析相关操作技巧,需要的朋友可以参考下