📄 wrapper.java
字号:
/**
* $file: Paser.java $
* $Revision: 1.0 $
* $ Modified Record:
* $2003.4.6: Created.
* Copyright (C) 2003 www.studyjava.com All rights reserved.
*/
package com.everstar.util;
import java.io.*;
import java.util.*;
/**
* this class read properties from a defined properties file like ../path/webstar.properties
* all the needed output information strings including error string and waring or information
* are stored in this properties file. thus client side programmers only need redirect to Error.jsp
* with a URL parameter "message", which should be in the form of predefined MACRO like "NEWS_ERROR_NOFILE"
* Error.jsp will get the reference of a instance of class Paser and invoke a method with parameter " message"
* whenever we need to update the information strings, what we need to do is merely update the properties file
*/
public class Wrapper
{
/**
* stores the necessary properties load from the properties file
*/
private Properties information;
/**
* string for the final output
*/
private String msgOutput=null;
/**
*propsName defines the name of properties file used here
*/
private static String resourceURI = "/jive.properties";
private final String defaultName="SYSTEM_DEFAULT";
//private PropertyManager manager=null;
private String defaultValue;
/**
* The Constructor method will be called only once since there will be only
* one instance of this class within the whole application;thus the timeconsuming
* work of loading all properties and their values from properties file is run here
* later,each time .jsp file calls Error.jsp will get proper output string from the
* same properties instance "information" through calling Wrapper.output(String msgInput)
* a instance of PropertyManager was created too to load properties from property file
* cause we dont want to interfere with the loading detail in Wrapper
*/
public Wrapper()
{
information=new Properties();
loadProp();
//Enumeration propNames=manager.propNames();
// while(propNames.hasMoreElements())
// { String propName=propNames.nextElement();
// String propValue=manager.getProp(propName);
// information.put(propName,propValue);
}
/**
* Error.jsp will call this method to print out proper message
*@param in message passed in from Error.jsp
*@return the proper output string get from properties file
*/
public String output(String in)
{
//first try to get according value from properties "information"
msgOutput=getProperties(in);
if(msgOutput!=null)
{
return msgOutput;
}
return getDefault(in);
}
private String getProperties(String in )
{
return (String)information.get(in);
}
private String getDefault(String in)
{
// here I want to parse the input string first to judge its module name and then try to get module's default output string
String defaultPropName=getModuleName(in)+"_DEFAULT";
if (( defaultValue=getProperties(defaultPropName))!=null)
return defaultValue;
//if the default exception information has not been found, we just take it as a system level exception
if (getProperties(defaultName)==null)
// both module default and system default exception cant be found(properties file was not properly defined)
return "there is no exception information defined yet ";
return getProperties(defaultName);
//return (String)prop.get(DEFULT);
}
private void loadProp()
{
InputStream in = null;
try
{
in = getClass().getResourceAsStream(resourceURI);
information.load(in);
}
catch (Exception e)
{
System.err.println("Error reading Jive properties in PropertyManager.loadProps() " + e);
e.printStackTrace();
}
finally
{
try
{
in.close();
}
catch (Exception e) { }
}
}
private String getModuleName(String in)
{
if(in!=null)
{
String f=in.substring(0,in.indexOf('_'));
return f;
}
// if there is no such module name in the property file, we just take it as system level exception
return getModuleName(defaultName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -