package com.util;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
import java.text.MessageFormat;
/**
* 获得配置资源(默认的为src/properties/message.properties文件)中的key的value信息
* 也可用Utility.setResourcePath(resourcePathStr)来改变资源的位置
* @author Administrator
*
*/
public class Utility {
public static final String module = Utility.class.getName();
// store resource bundle(默认放在properties文件夹下的message.properties文件中)
private static String csResourcePath = "properties.message";
public static String getResourcePath() {
return csResourcePath;
}
public static void setResourcePath(String asResourcePath) {
csResourcePath = asResourcePath;
}
/**
* Gary: get user locale from langcd
* @param asLangCd:国家语言参数
* @return
*/
public static Locale getUserLocale(String asLangCd) {
Locale lsUserLocale = Locale.ENGLISH;
if (asLangCd.equals("zht"))
lsUserLocale = Locale.TRADITIONAL_CHINESE;
else if (asLangCd.equals("zhs"))
lsUserLocale = Locale.SIMPLIFIED_CHINESE;
else if (asLangCd.equals("en"))
lsUserLocale = Locale.ENGLISH;
return lsUserLocale;
}
public static Locale getUserLocale() {
//the default locale is SIMPLIFIED_CHINESE
return Locale.SIMPLIFIED_CHINESE;
}
/**
* Gary: Functions to get message from resource
* @param asKey
* @param asLangCd
* @return
*/
public static String getMessage(String asKey) {
return getMessage(asKey, getUserLocale());
}
public static String getMessage(String asKey, String asLangCd) {
return getMessage(asKey, getUserLocale(asLangCd));
}
public static String getMessage(String asKey, Locale asLocale) {
ResourceBundle bundle = ResourceBundle.getBundle(Utility
.getResourcePath(), asLocale);
return bundle.getString(asKey);
}
public static String getMessage(String asKey, String asLangCd, String arg0,
String arg1, String arg2) {
return getMessage(asKey, getUserLocale(asLangCd), arg0, arg1, arg2);
}
public static String getMessage(String asKey, Locale asLocale, String arg0,
String arg1, String arg2) {
String msg = getMessage(asKey, asLocale);
String[] messageArgs = new String[3];
messageArgs[0] = arg0;
messageArgs[1] = arg1;
messageArgs[2] = arg2;
return MessageFormat.format(msg, messageArgs);
}
public static boolean isEmpty(String string) {
boolean isEmpty = true;
if (string != null && !"".equals(string) && string.trim().length() > 0)
isEmpty = false;
return isEmpty;
}
/**
* 自己的
* 加载配置文件中的所有键值对,并保存在Properties中
* @param propertyFileName:属性文件名
* @return
* 如getBundlePros("properties/email"); //在src/properties包下的email.properties文件
public Properties getBundleProps(String propertyFileName){
Properties props = new Properties();
ResourceBundle bundle = ResourceBundle.getBundle(propertyFileName.trim());
Enumeration enume = bundle.getKeys();
String key = "";
String value = "";
while(enume.hasMoreElements()){
key = (String)enume.nextElement();
value = bundle.getString(key.toString());
props.put(key, value);
}
return props;
}
*/
}
分享到:
相关推荐
web应用程序获取资源文件的key-value;web应用程序获取资源文件的key-value
真实项目中常用到的 自己写的工具类,包括读资源文件(传入相应的key就可取出相应的value),读取COOKIE,存储COOKIE,把Bean序列化后存储到COOKIE中,返序列化从COOKIEk中取出Bean
#资源达人分享计划#
资源文件是key-value对,每个资源文件中的key是不变的,但value则随不同国家、语言改变。 Java程序的国际化主要通过如下三个类完成: Ø java.util.ResourceBundle:用于加载一个国家、语言资源包。 Ø java.util...
资源包中的文件手册部分,详细记录了Android开发的核心知识点和常用技术。无论是初学者还是有一定经验的开发者,都能从中找到所需的学习资料。手册采用了简洁明了的排版方式,使得查阅更加方便快捷。同时,手册内容...
将某班学生的《Python程序设计》这门课程的成绩保存在字典中,学号为键(key),分数为值(value)。实现如下功能: (1)向字典中添加学生成绩。 (2)修改字典中指定学生成绩。 (3)删除指定学生成绩。 (4)查询...
本资源参考网上原版为存取英文字符的ini操作,未考虑中文乱码问题。而网上另外也有资料如何...iniFile.WriteValue(SectionName, KeyName, KeyValue); 3.取数据 iniFile.GetString(SectionName,KeyName,DefaultValue);
/// /// key:Key,value:xaml Path <see>SkinDesc /// 用于获取对应skin资源文件,key和SkinDesc相同 /// public static Dictionary, string> SkinDict = new Dictionary, string>();
获取properties文件中设定好key值的value值
简单的KeyValue转换器 这是什么? Valve正在使用类似JSON格式的KeyValues存储某种数据(例如资源列表,脚本,材料,dota 2构建文件等)。 详细信息: : 该库最初用于将Dota 2 .build文件(使用相同的格式)转换...
<add key="ExcelToTxtTemplate" value="C:\Documents and Settings\kiki\桌面\简历导入工具\Template\ExcelToTxtTemplate.txt"/> <add key="ExcelRowKey" value="姓名"/> <add key="ExistKeyCount" value="3"/> ...
数据库连接的资源文件: 后缀properties是一种属性文件。 这种文件以key=value格式存储内容 Java中可以使用Properties类来读取这个文件 String value=p.getProperty(key); 就能得到对应的数据 一般这个文件作为一些...
输出硬盘文件,提供下载 支持大文件、续传、速度限制、资源占用小 复制代码 FileDown 1.参数为虚拟路径 2.获取物理地址 3.普通下载 4.分块下载 5.输出硬盘文件,提供下载 支持大文件、续传、速度限制、资源占用...
1、用户前端UI点击上传excel文件,调用/general/importToRedis,解析excel数据和表头,分别储存到redis中,返回数据和表头对应的redis_key,并返回原始文件“导入文件表头字段:key=cell-index,value=cell-cnName”...
读取和修改都是基于key-value的:方便理解和修改;具备properties文件<->json文件互相转换的能力。 在实际项目中还用到properties属性文件或json文件和excel文件的相互转换的。 关于国际化,还需要考虑去重,考虑...
Spring2.5的国际化配置 基于浏览器语言的国际化配置 使用Spring的MVC,并且配置中有配置Resource文件 <!-- 资源文件绑定器 --> ...<property name="basename" value=...其中的info.login.title和你的资源文件对应
例子: mac_plist_value { 'meaningless unique name with no colons':file => '/path/to/settings.plist',key => ['key', 'key2'],value => 3, } mac_plist_value { '/path/to/settings.plist:key/key2':value => ...
【资源介绍】 ...> curl -L localhost:12100/key -XPUT -d value // 添加新的key-value pair > curl -L localhost:12100/key // 获取key的value > curl -L localhost:12100/key -XDELETE // 删除key
本代码是利用C#编写的XML文件,可以方便的读写数据,对于初学者来说是一个不错的资源。