java中获取资源文件

本文介绍了一个基于Java实现的消息通知模块,该模块可以根据不同的接收者类型(个人、部门或角色)发送定制化的通知内容,并通过格式化配置文件中的模板来构造具体的通知信息。此外,还提供了任务完成后的消息发送功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class DrpToOAInfo {
@PersistenceContext
EntityManager entityManager;

private final static String CONFIGURETION_FILE = "send_message_zh.properties";
private static Properties properties = null;

public static Properties readConfiguretion()
{
if (properties == null)
{
try
{
properties = new Properties();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream inputStream = null;
if (cl != null)
{
inputStream = cl.getResourceAsStream(CONFIGURETION_FILE);
}
if (inputStream != null)
{
properties.load(inputStream);
inputStream.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
return properties;
}
/**
*
* @param type 接收者类型
* @param id 接收者id
* @param name 接收者名称
* @param contentVariable 内容中的变动部分
* @param url IP地址、端口号、项目
* @param value 生产计划单号
* @param configureInformType 通知类型
*/
public static void sendMessage(int type,
String id,
String name,
Object[] contentVariable,
String url,
Object[] value,
String configureInformType)
{
String applictionName = "";
String content = "";
String URL = "";
ReceiveType rt = ReceiveType.DEPARTMENT;

//读取资源文件
Properties properties = readConfiguretion();
applictionName = properties.getProperty("system.module.appliction.name");
content = MessageFormat.format(properties.getProperty(configureInformType), contentVariable);

URL = url + MessageFormat.format(properties.getProperty(configureInformType + ".url"), value);;


if(type == 0)
{
rt = ReceiveType.PEOPLE;
}
if(type == 1)
{
rt = ReceiveType.DEPARTMENT;
}
if(type == 2)
{
rt = ReceiveType.ROLE;
}

System.out.println("******************************************");
System.out.println("* 类型:"+rt);
System.out.println("* ID:"+id);
System.out.println("* 接收者名称:"+name);
System.out.println("* 内容:"+content);
System.out.println("* url:"+URL);
System.out.println("******************************************");
StartupMessage sm = new StartupMessage(applictionName, rt,"117", "tonywu", id, name, content, URL);

SendMessage s = new SendMessage();
s.sendMessage(sm);
}

/**
* 从request中得到地址中的参数,
* @param taskID 接收者类型
* @param processorID 处理者ID
* @param processorName 处理者名称
* @param processorTime 处理时间
*/
public static void overMessage(String[] processorInfo)
{
// 读取资源文件
Properties properties = readConfiguretion();
String applictionName = properties.getProperty("system.module.appliction.name");
// Calendar date = Calendar.getInstance();
// String t = date.get(Calendar.YEAR)+"-"+date.get(Calendar.MONTH)+"-"+date.get(Calendar.DATE);
BeOverMessage bm = new BeOverMessage(applictionName, processorInfo[1],
"117", "tonywu",new Date());

System.out.println("******************************************");
System.out.println("* taskID类型:"+processorInfo[1]);
System.out.println("* processorIDID:"+processorInfo[2]);
System.out.println("* processorName接收者名称:"+processorInfo[3]);
System.out.println("* 时间:"+new Date());
System.out.println("******************************************");

SendMessage s = new SendMessage();
s.sendMessage(bm);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值