001 /* PAVLOV -- Multiple Choice Study System 002 * Copyright (C) 2000 - 2004 T.J. Willis 003 * 004 * This program is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU General Public License 006 * as published by the Free Software Foundation; either version 2 007 * of the License, or (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, write to the Free Software 016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. 017 * 018 * $Header: /cvsroot/pavlov/net/sourceforge/pavlov/main/standalone/ResourceBroker.java,v 1.4 2004/07/01 05:50:20 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.main.standalone; 021 import java.util.MissingResourceException; 022 import java.util.ResourceBundle; 023 import java.io.File; 024 import java.net.URL; 025 026 public class ResourceBroker 027 { 028 029 // From SwingUIFactory 030 public static final String SKINS_DEFAULT_DIR = "skins.default"; 031 public static final String THEMES_DEFAULT_DIR = "themes.default"; 032 public static final String ABOUT_IMAGE = "about.image"; 033 public static final String INCORRECT_TITLE = "incorrect.title"; 034 public static final String SKINS_ERROR_DEFAULT = "skins.error.default"; 035 public static final String QUIT = "pavlov.quit"; 036 public static final String LIBRARY_ERROR = "library.error"; 037 public static final String USER_NULL = "user.null"; 038 //public static String CHAPTER_NULL = "chapter.null"; 039 public static final String QUIZVIEW_ERROR_CREATE = "quizview.error.create"; 040 public static final String LOGIN_ERROR = "login.error"; 041 public static final String HARDCOPY_ERROR = "hardcopy.error"; 042 public static final String HELPSET_URL = "helpset.url"; 043 public static final String BOOK_NULL = "book.null"; 044 public static final String CHAPTER_NULL = "chapter.null"; 045 public static final String LIBRARY_NULL = "library.null"; 046 047 //from AbstractPavlovApplication.java 048 public static final String LIBRARY_DIR = "library.dir"; 049 public static final String STATUS_LOADING_PLUGLETS = "status.loading.pluglets"; 050 public static final String STATUS_LOADING_LIBRARY = "status.loading.library"; 051 public static final String STATUS_LOGGING_IN = "status.logging.in"; 052 public static final String STATUS_VALIDATING_STATISTICS= "status.validating.statistics"; 053 public static final String STATUS_CONFIGURING_THEMES = "status.configuring.themes"; 054 public static final String STATUS_CONFIGURING_UI = "status.configuring.ui"; 055 public static final String STATUS_CREATING_LIBRARY_VIEW = "status.creating.library.view"; 056 public static final String STATUS_CLOSING_SPLASH_SCREEN = "status.closing.splash.screen"; 057 public static final String USER_SAVING_ERROR = "user.saving.error"; 058 public static final String FEEDBACK_PLUGLET_DIRECTORY = "pluglet.feedback.directory"; 059 public static final String VELOCITY_PLUGLET_DIRECTORY = "pluglet.velocity.directory"; 060 public static final String STRATEGY_PLUGLET_DIRECTORY = "pluglet.strategy.directory"; 061 public static final String TOOL_PLUGLET_DIRECTORY = "pluglet.tool.directory"; 062 063 064 //from Pavlov.java 065 public static final String TITLE ="pavlov.title"; 066 067 // General use 068 public static final String CORRECT = "pavlov.correct"; 069 public static final String INCORRECT = "pavlov.incorrect"; 070 public static final String PAVLOV_CORRECT = "pavlov.correct"; 071 public static final String PAVLOV_INCORRECT = "pavlov.incorrect"; 072 public static final String PAVLOV_QUESTIONS = "pavlov.questions"; 073 public static final String PAVLOV_ANSWERS = "pavlov.answers"; 074 public static final String PAVLOV_QUIZ = "pavlov.quiz"; 075 public static final String PAVLOV_QUIZZES = "pavlov.quizzes"; 076 public static final String PAVLOV_SCORE = "pavlov.score"; 077 public static final String PAVLOV_LOGIN = "pavlov.login"; 078 079 static ResourceBundle resources = null; 080 static ResourceBroker instance = null; 081 082 private ResourceBroker() 083 { 084 super(); 085 try { 086 resources = ResourceBundle.getBundle("Pavlov"); 087 } catch (MissingResourceException mre) { 088 System.out.println("Couldn't load Pavlov.properties" +mre); 089 System.out.println("Current locale is: " +java.util.Locale.getDefault()); 090 } 091 } 092 093 094 public static ResourceBroker getInstance(){ 095 if(instance==null){ 096 instance = new ResourceBroker(); 097 } 098 return instance; 099 } 100 101 public String getString(final String key){ 102 return getString(key,null); 103 } 104 105 106 /** 107 * Returns the named resource value or the given default, if the 108 * resource value is unavailable. 109 * 110 * @param key a <code>String</code> value 111 * @param def a <code>String</code> value 112 * @return a <code>String</code> value 113 */ 114 public String getString(final String key, final String def) 115 { 116 try { 117 String la = resources.getString(key); 118 if(la!=null) return la; 119 System.out.println("Can't find resource string: " + key); 120 return def; 121 } catch (Exception ex) { 122 System.out.println("Can't find resource string: " + key); 123 return def; 124 } 125 } 126 127 public File getFile(final String key) 128 { 129 return new File(getString(key)); 130 } 131 132 public URL getURL(final String key) 133 throws java.net.MalformedURLException 134 { 135 return new URL(getString(key)); 136 } 137 138 139 }