📄 textresource.java
字号:
package de.fhm.jkf.launch.cl;
import java.util.PropertyResourceBundle;
/**
* @author Theodor Willax
*
* <br><br><center><table border="1" width="80%"><hr>
* <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
* <p>
* Copyright (C) 2002 by Theodor Willax
* <p>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* <p>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* <p>
* You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
* GNU Lesser General Public License</a> along with this library; if not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
* <hr></table></center>
*
* This class contains the resources given to the <tt>application.properties</tt>
* file, which is packed to the launcher archive from the <tt>LaunchServlet</tt>.
*
* @see de.fhm.jkf.launch.sv.LaunchServlet
*/
public class TextResource {
/**
* The resource bundle where strings are looked up.
*/
private static PropertyResourceBundle bundle = null;
/**
* Instance count for this class. If it drops to zero (in finalize()),
* then the static resource bundle will be released.
*/
private static int instanceCount = 0;
/**
* Creates a new TextResource. If <tt>instanceCount</tt> is zero, a new
* resource bundle is allocated. Increments the instance count by one.
* <tt>application.properties</tt> will be loaded (root dir of jar archive).
*/
public TextResource() {
if (instanceCount == 0) {
bundle = (PropertyResourceBundle)
PropertyResourceBundle.getBundle("application");
}
instanceCount++;
}
/**
* Retrieves the value for the given key from this resource bundle.
*
* @param key the key to look for.
* @return the value to the given key or the empty string if key not found.
*/
public String getString(String key) {
try {
return bundle.getString(key);
} catch (java.util.MissingResourceException e) {
System.err.println("value for key " + key + " in locale " +
bundle.getLocale() + " not found");
e.printStackTrace();
return "";
}
}
/**
* Releases the static resource bundle if no more instances of
* this class are alive. Just to save memory if we have a large
* resource file.
*/
protected void finalize() {
instanceCount--;
if (instanceCount == 0) {
System.out.println("releasing " + this);
bundle = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -