[Jsxe-cvs] SF.net SVN: jsxe: [994] trunk/jsxe
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-07-07 03:46:29
|
Revision: 994 Author: ian_lewis Date: 2006-07-06 20:46:17 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=994&view=rev Log Message: ----------- Added support for countries and language variants Modified Paths: -------------- trunk/jsxe/Changelog trunk/jsxe/src/net/sourceforge/jsxe/JARClassLoader.java trunk/jsxe/src/net/sourceforge/jsxe/gui/Messages.java trunk/jsxe/src/net/sourceforge/jsxe/jsXe.java trunk/jsxe/src/net/sourceforge/jsxe/util/Log.java Added Paths: ----------- trunk/jsxe/messages/messages Removed Paths: ------------- trunk/jsxe/messages/messages.en Modified: trunk/jsxe/Changelog =================================================================== --- trunk/jsxe/Changelog 2006-07-07 02:32:49 UTC (rev 993) +++ trunk/jsxe/Changelog 2006-07-07 03:46:17 UTC (rev 994) @@ -2,8 +2,7 @@ * Rewrote the Messages class. Now it loads messages on demand and only loads the messages that it needs but allows the Locale to be changed at - any time. Though this implementation is inefficient as it checks for - messages files in plugins every time a message is requested. + any time. It also now supports different countries and variants. 06/27/2006 Ian Lewis <Ian...@me...> Copied: trunk/jsxe/messages/messages (from rev 989, trunk/jsxe/messages/messages.en) =================================================================== --- trunk/jsxe/messages/messages (rev 0) +++ trunk/jsxe/messages/messages 2006-07-07 03:46:17 UTC (rev 994) @@ -0,0 +1,250 @@ +# JSXE English properties file +# $Id$ +#:mode=properties: +#:tabSize=4:indentSize=4:noTabs=true: +#:folding=explicit:collapseFolds=1: + +#{{{ common properties + +common.ok=OK +common.cancel=Cancel +common.open=Open +common.save=Save +common.save.as=Save As +common.close=Close +common.apply=Apply +common.more=More +common.insert=Insert +common.add=Add +common.remove=Remove +common.moveUp=Move Up +common.moveDown=Move Down +common.cut=Cut +common.copy=Copy +common.paste=Paste +common.find=Find... +common.findnext=Find Next + +#}}} + +#{{{ XML Terminology + +#{{{ XML Node Types +xml.element=Element +xml.processing.instruction=Processing Instruction +xml.cdata=CDATA Section +xml.text=Text +xml.entity.reference=Entity Reference +xml.declaration=Element Declaration +xml.notation=Notation +xml.entity=Entity Declaration +xml.comment=Comment +xml.attribute=Attribute +xml.doctype=Document Type +#}}} + +xml.attribute.value.short=Value +xml.attribute.value=Attribute Value +xml.document=XML Document +xml.namespace=Namespace +xml.namespace.prefix=Namespace Prefix +xml.namespace.prefix.short=Prefix +xml.namespace.decl=Namespace Declaration +xml.doctypedef=Document Type Definition +xml.doctype.name=Name +xml.doctype.public=Public Id +xml.doctype.system=System Id +xml.schema=XML Schema +#}}} + +#{{{ Global Options +Global.Options.Dialog.Title=Global Options +Global.Options.Title=General +Global.Options.Max.Recent.Files=Recent files to remember: +Global.Options.Max.Recent.Files.ToolTip=The maximum number of files that jsXe remembers in the recent files menu. +Global.Options.network-off=Always cache without asking +Global.Options.network-cache=Ask first, then cache remote files +Global.Options.network-always=Always download without asking +Global.Options.network=DTD and schema downloading: +Global.Options.Menu.Spill.Over=Number of items before menus spill over + + +Shortcuts.Options.Title=Shortcuts +#}}} + +#{{{ Document Options +Document.Options.Title=XML Document Options +Document.Options.Message=This dialog changes settings for the current\n document only. To change settings on an\n editor-wide basis, see the\n Tools->Global Options dialog box. +Document.Options.Line.Separator=Line Separator: +Document.Options.Line.Separator.ToolTip=The line separator. Usually you'll pick the line separator used by your operating system. +Document.Options.Encoding=Encoding: +Document.Options.Encoding.ToolTip=The encoding that jsXe uses to write the file. +Document.Options.Indent.Width=Indent width: +Document.Options.Indent.Width.ToolTip=The width used when formatting and displaying tab characters. +Document.Options.Format.XML=Format XML output +Document.Options.Format.XML.ToolTip=If this box is checked then XML will be formatted automatically. +Document.Options.Validate=Validate if DTD or Schema Available +Document.Options.Validate.ToolTip=If this box is checked jsXe will validate the XML document. +Document.Options.Soft.Tabs=Soft tabs (emulated with spaces) +Document.Options.Soft.Tabs.ToolTip=If this box is checked then tab characters are replaced by spaces. +#}}} + +#{{{ Plugin Manager +Plugin.Manager.Title=Plugin Manager +Plugin.Manager.Name.Column.Header=Name +Plugin.Manager.Version.Column.Header=Version +Plugin.Manager.Status.Column.Header=Status +Plugin.Manager.Loaded.Status=Loaded +Plugin.Manager.Not.Loaded.Status=Not Loaded +Plugin.Manager.Broken.Status=Error +#}}} + +#{{{ Menu Items + +File.Menu=File +Edit.Menu=Edit +View.Menu=View +Tools.Menu=Tools +Help.Menu=Help + +#{{{ File Menu Items +new-file.label=New +open-file.label=Open... +File.Recent=Recent Files +File.Recent.None=No Recent Files +save-file.label=Save +save-as.label=Save As... +reload-file.label=Reload +File.Recent=Recent Files +close-file.label=Close +close-all.label=Close All +exit.label=Exit +#}}} + +general-options.label=Global Options... +document-options.label=Document Options... +plugin-manager.label=Plugin Manager... +validation-errors.label=Validation Errors... +about-jsxe.label=About jsXe... +#}}} + +#{{{ Messages + +#{0} file name +DocumentBuffer.Reload.Message={0} unsaved!\n You will lose all unsaved changes if you reload!\n\nContinue? +DocumentBuffer.Reload.Message.Title=Document Modified +DocumentBuffer.SaveAs.Message=The file {0} already exists. Are you sure you want to overwrite it? +DocumentBuffer.SaveAs.Message.Title=File Exists +DocumentBuffer.Close.Message={0} unsaved! Save it now? +DocumentBuffer.Close.Message.Title=Unsaved Changes + +#{0} file name +DocumentBuffer.Saved.Message={0} Saved +DocumentBuffer.Closed.Message={0} Closed +DocumentBuffer.Loaded.Message={0} Loaded +DocumentBuffer.Reloaded.Message={0} Reloaded + +#{0} plugin name +DocumentView.Not.Found=No plugin a with name of {0} exists. + +#{{{ Plugin Load Messages + +# {0} plugin name +Plugin.Load.Already.Loaded=Plugin {0} already loaded. +Plugin.Load.Wrong.Main.Class=Main class is not a plugin class. +Plugin.Load.No.Plugin.Class=No plugin class defined. +Plugin.Load.No.Plugin.Name=No plugin name defined. +Plugin.Load.No.Plugin.HR.Name=No plugin human-readable name defined. +Plugin.Load.No.Plugin.Version=No plugin version defined. + +# {0} plugin name +# {1} requirement name +# {2} required version +# {3} found version +Plugin.Dependency.Message={0} requires {1} version {2} but only version {3} was found. +# {0} plugin name +# {1} requirement name +# {2} required version +Plugin.Dependency.Not.Found={0} requires {1} version {2} but {1} was not found. +# {0} plugin name +# {1} requirement name +Plugin.Dependency.Not.Found2={0} requires {1} but {1} was not found. +# {0} plugin name +# {1} invalid dependency +Plugin.Dependency.Invalid={0} has an invalid dependency: {1} +# {0} invalid version +Plugin.Dependency.Invalid.jsXe.Version=Invalid jsXe version number: {0} +# {0} plugin name +# {1} requirement name +Plugin.Dependency.No.Version=Cannot load plugin {0}, {1} has no version. +# {0} plugin name +# {1} requirement name +Plugin.Dependency.Failed.Load={0} requires plugin {1} but {1} did not load properly. + +#}}} + +#{{{ Error Messages +No.Xerces.Error={0} not found. jsXe requires Apache {0}. +No.Xerces.Error.Title={0} not found. +IO.Error.Title=I/O Error +#}}} + +#}}} + +#{{{ Dialogs + +#{{{ Download resource dialog +xml.download-resource.title=Getting resource from remote server + +#{0} URL +xml.download-resource.message=This XML file depends on a resource which is stored at the following\n\ + Internet address:\n\ + \n\ + {0}\n\ + \n\ + Do you want the XML plugin to download the resource and cache it\n\ + for future use?\n\ + \n\ + If you want resources to be downloaded every time without prompting,\n\ + disable the resource cache in jsXe's global options. +#}}} + +#{{{ Dirty Files Dialog +DirtyFilesDialog.Dialog.Title=Unsaved Changes +DirtyFilesDialog.Dialog.Message=The following files have unsaved changes: +DirtyFilesDialog.Button.SelectAll.Title=Select All +#DirtyFilesDialog.Button.SelectAll.ToolTip=Select All +DirtyFilesDialog.Button.SaveSelected.Title=Save Selected +#DirtyFilesDialog.Button.SaveSelected.ToolTip=Save Selected +DirtyFilesDialog.Button.DiscardSelected.Title=Discard Selected +#DirtyFilesDialog.Button.DiscardSelected.ToolTip=Discard Selected +#}}} + +#{{{ Activity Log Dialog +activity-log.label = Activity Log +ActivityLogDialog.Dialog.Title = Activity Log +ActivityLogDialog.Dialog.Message = Activity Log contents: +#}}} + +#{{{ About dialag +about.title=About jsXe +about.message=Released under the terms of the GNU General Public License\n\n\ + Active Contributors:\n\ + \ \ \ \ Ian Lewis <Ian...@me...>\n\ + \ \ \ \ Trish Hartnett <tri...@us...>\n\n\ + Translators:\n\ + \ \ \ \ German (de) - Bianca Schoen\n\ + \ \ \ \ Swedish (sv) - Patrik Johansson <pa...@it...>\n\n\ + Past Contributers:\n\ + \ \ \ \ Aaron Flatten <afl...@us...>\n\ + \ \ \ \ Bilel Remmache <rb...@us...>\n\ + \ \ \ \ SVM <svm...@us...>\n\n\ + Homepage: http://jsxe.sourceforge.net/ +#}}} + +#{{{ Validation Errors Dialog +ValidationErrors.title=Validation Errors +ValidationErrors.message=Validation Errors +#}}} + +#}}} \ No newline at end of file Deleted: trunk/jsxe/messages/messages.en =================================================================== --- trunk/jsxe/messages/messages.en 2006-07-07 02:32:49 UTC (rev 993) +++ trunk/jsxe/messages/messages.en 2006-07-07 03:46:17 UTC (rev 994) @@ -1,250 +0,0 @@ -# JSXE English properties file -# $Id$ -#:mode=properties: -#:tabSize=4:indentSize=4:noTabs=true: -#:folding=explicit:collapseFolds=1: - -#{{{ common properties - -common.ok=OK -common.cancel=Cancel -common.open=Open -common.save=Save -common.save.as=Save As -common.close=Close -common.apply=Apply -common.more=More -common.insert=Insert -common.add=Add -common.remove=Remove -common.moveUp=Move Up -common.moveDown=Move Down -common.cut=Cut -common.copy=Copy -common.paste=Paste -common.find=Find... -common.findnext=Find Next - -#}}} - -#{{{ XML Terminology - -#{{{ XML Node Types -xml.element=Element -xml.processing.instruction=Processing Instruction -xml.cdata=CDATA Section -xml.text=Text -xml.entity.reference=Entity Reference -xml.declaration=Element Declaration -xml.notation=Notation -xml.entity=Entity Declaration -xml.comment=Comment -xml.attribute=Attribute -xml.doctype=Document Type -#}}} - -xml.attribute.value.short=Value -xml.attribute.value=Attribute Value -xml.document=XML Document -xml.namespace=Namespace -xml.namespace.prefix=Namespace Prefix -xml.namespace.prefix.short=Prefix -xml.namespace.decl=Namespace Declaration -xml.doctypedef=Document Type Definition -xml.doctype.name=Name -xml.doctype.public=Public Id -xml.doctype.system=System Id -xml.schema=XML Schema -#}}} - -#{{{ Global Options -Global.Options.Dialog.Title=Global Options -Global.Options.Title=General -Global.Options.Max.Recent.Files=Recent files to remember: -Global.Options.Max.Recent.Files.ToolTip=The maximum number of files that jsXe remembers in the recent files menu. -Global.Options.network-off=Always cache without asking -Global.Options.network-cache=Ask first, then cache remote files -Global.Options.network-always=Always download without asking -Global.Options.network=DTD and schema downloading: -Global.Options.Menu.Spill.Over=Number of items before menus spill over - - -Shortcuts.Options.Title=Shortcuts -#}}} - -#{{{ Document Options -Document.Options.Title=XML Document Options -Document.Options.Message=This dialog changes settings for the current\n document only. To change settings on an\n editor-wide basis, see the\n Tools->Global Options dialog box. -Document.Options.Line.Separator=Line Separator: -Document.Options.Line.Separator.ToolTip=The line separator. Usually you'll pick the line separator used by your operating system. -Document.Options.Encoding=Encoding: -Document.Options.Encoding.ToolTip=The encoding that jsXe uses to write the file. -Document.Options.Indent.Width=Indent width: -Document.Options.Indent.Width.ToolTip=The width used when formatting and displaying tab characters. -Document.Options.Format.XML=Format XML output -Document.Options.Format.XML.ToolTip=If this box is checked then XML will be formatted automatically. -Document.Options.Validate=Validate if DTD or Schema Available -Document.Options.Validate.ToolTip=If this box is checked jsXe will validate the XML document. -Document.Options.Soft.Tabs=Soft tabs (emulated with spaces) -Document.Options.Soft.Tabs.ToolTip=If this box is checked then tab characters are replaced by spaces. -#}}} - -#{{{ Plugin Manager -Plugin.Manager.Title=Plugin Manager -Plugin.Manager.Name.Column.Header=Name -Plugin.Manager.Version.Column.Header=Version -Plugin.Manager.Status.Column.Header=Status -Plugin.Manager.Loaded.Status=Loaded -Plugin.Manager.Not.Loaded.Status=Not Loaded -Plugin.Manager.Broken.Status=Error -#}}} - -#{{{ Menu Items - -File.Menu=File -Edit.Menu=Edit -View.Menu=View -Tools.Menu=Tools -Help.Menu=Help - -#{{{ File Menu Items -new-file.label=New -open-file.label=Open... -File.Recent=Recent Files -File.Recent.None=No Recent Files -save-file.label=Save -save-as.label=Save As... -reload-file.label=Reload -File.Recent=Recent Files -close-file.label=Close -close-all.label=Close All -exit.label=Exit -#}}} - -general-options.label=Global Options... -document-options.label=Document Options... -plugin-manager.label=Plugin Manager... -validation-errors.label=Validation Errors... -about-jsxe.label=About jsXe... -#}}} - -#{{{ Messages - -#{0} file name -DocumentBuffer.Reload.Message={0} unsaved!\n You will lose all unsaved changes if you reload!\n\nContinue? -DocumentBuffer.Reload.Message.Title=Document Modified -DocumentBuffer.SaveAs.Message=The file {0} already exists. Are you sure you want to overwrite it? -DocumentBuffer.SaveAs.Message.Title=File Exists -DocumentBuffer.Close.Message={0} unsaved! Save it now? -DocumentBuffer.Close.Message.Title=Unsaved Changes - -#{0} file name -DocumentBuffer.Saved.Message={0} Saved -DocumentBuffer.Closed.Message={0} Closed -DocumentBuffer.Loaded.Message={0} Loaded -DocumentBuffer.Reloaded.Message={0} Reloaded - -#{0} plugin name -DocumentView.Not.Found=No plugin a with name of {0} exists. - -#{{{ Plugin Load Messages - -# {0} plugin name -Plugin.Load.Already.Loaded=Plugin {0} already loaded. -Plugin.Load.Wrong.Main.Class=Main class is not a plugin class. -Plugin.Load.No.Plugin.Class=No plugin class defined. -Plugin.Load.No.Plugin.Name=No plugin name defined. -Plugin.Load.No.Plugin.HR.Name=No plugin human-readable name defined. -Plugin.Load.No.Plugin.Version=No plugin version defined. - -# {0} plugin name -# {1} requirement name -# {2} required version -# {3} found version -Plugin.Dependency.Message={0} requires {1} version {2} but only version {3} was found. -# {0} plugin name -# {1} requirement name -# {2} required version -Plugin.Dependency.Not.Found={0} requires {1} version {2} but {1} was not found. -# {0} plugin name -# {1} requirement name -Plugin.Dependency.Not.Found2={0} requires {1} but {1} was not found. -# {0} plugin name -# {1} invalid dependency -Plugin.Dependency.Invalid={0} has an invalid dependency: {1} -# {0} invalid version -Plugin.Dependency.Invalid.jsXe.Version=Invalid jsXe version number: {0} -# {0} plugin name -# {1} requirement name -Plugin.Dependency.No.Version=Cannot load plugin {0}, {1} has no version. -# {0} plugin name -# {1} requirement name -Plugin.Dependency.Failed.Load={0} requires plugin {1} but {1} did not load properly. - -#}}} - -#{{{ Error Messages -No.Xerces.Error={0} not found. jsXe requires Apache {0}. -No.Xerces.Error.Title={0} not found. -IO.Error.Title=I/O Error -#}}} - -#}}} - -#{{{ Dialogs - -#{{{ Download resource dialog -xml.download-resource.title=Getting resource from remote server - -#{0} URL -xml.download-resource.message=This XML file depends on a resource which is stored at the following\n\ - Internet address:\n\ - \n\ - {0}\n\ - \n\ - Do you want the XML plugin to download the resource and cache it\n\ - for future use?\n\ - \n\ - If you want resources to be downloaded every time without prompting,\n\ - disable the resource cache in jsXe's global options. -#}}} - -#{{{ Dirty Files Dialog -DirtyFilesDialog.Dialog.Title=Unsaved Changes -DirtyFilesDialog.Dialog.Message=The following files have unsaved changes: -DirtyFilesDialog.Button.SelectAll.Title=Select All -#DirtyFilesDialog.Button.SelectAll.ToolTip=Select All -DirtyFilesDialog.Button.SaveSelected.Title=Save Selected -#DirtyFilesDialog.Button.SaveSelected.ToolTip=Save Selected -DirtyFilesDialog.Button.DiscardSelected.Title=Discard Selected -#DirtyFilesDialog.Button.DiscardSelected.ToolTip=Discard Selected -#}}} - -#{{{ Activity Log Dialog -activity-log.label = Activity Log -ActivityLogDialog.Dialog.Title = Activity Log -ActivityLogDialog.Dialog.Message = Activity Log contents: -#}}} - -#{{{ About dialag -about.title=About jsXe -about.message=Released under the terms of the GNU General Public License\n\n\ - Active Contributors:\n\ - \ \ \ \ Ian Lewis <Ian...@me...>\n\ - \ \ \ \ Trish Hartnett <tri...@us...>\n\n\ - Translators:\n\ - \ \ \ \ German (de) - Bianca Schoen\n\ - \ \ \ \ Swedish (sv) - Patrik Johansson <pa...@it...>\n\n\ - Past Contributers:\n\ - \ \ \ \ Aaron Flatten <afl...@us...>\n\ - \ \ \ \ Bilel Remmache <rb...@us...>\n\ - \ \ \ \ SVM <svm...@us...>\n\n\ - Homepage: http://jsxe.sourceforge.net/ -#}}} - -#{{{ Validation Errors Dialog -ValidationErrors.title=Validation Errors -ValidationErrors.message=Validation Errors -#}}} - -#}}} \ No newline at end of file Modified: trunk/jsxe/src/net/sourceforge/jsxe/JARClassLoader.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/JARClassLoader.java 2006-07-07 02:32:49 UTC (rev 993) +++ trunk/jsxe/src/net/sourceforge/jsxe/JARClassLoader.java 2006-07-07 03:46:17 UTC (rev 994) @@ -192,6 +192,8 @@ return null; }//}}} + //}}} + //{{{ getPluginResources() /** * Finds all resources matching the name in the jar files specified in the @@ -216,8 +218,6 @@ return findResource(name); }//}}} - //}}} - //{{{ addJarFile() /** * Adds a jar file to the search path for the class loader and @@ -409,6 +409,9 @@ * @return an ArrayList of errors (either Strings or Exceptions). */ public ArrayList startPlugins() { + + Messages.initPluginMessages(); + Iterator jarItr = m_jarFiles.keySet().iterator(); ArrayList errors = new ArrayList(); Modified: trunk/jsxe/src/net/sourceforge/jsxe/gui/Messages.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/gui/Messages.java 2006-07-07 02:32:49 UTC (rev 993) +++ trunk/jsxe/src/net/sourceforge/jsxe/gui/Messages.java 2006-07-07 03:46:17 UTC (rev 994) @@ -60,8 +60,8 @@ * The Messages class searches these files in the following order. * * <ul> - * <li>messages.<code>language</code>.<code>country</code>.<code>variant</code></li> - * <li>messages.<code>language</code>.<code>country</code></li> + * <li>messages.<code>language</code>_<code>country</code>_<code>variant</code></li> + * <li>messages.<code>language</code>_<code>country</code></li> * <li>messages.<code>language</code></li> * <li>messages</li> * </ul> @@ -76,152 +76,206 @@ //{{{ Private static members /** - * A Locale to Properties object map which is used when searching - * for a message resource. + * properties containing the messages for jsXe */ - private static HashMap m_messagesMap = new HashMap(); + private static Properties m_messages; /** - * This is a list of URLs messages files for plugins which have been loaded. + * plugin properties */ - private static ArrayList m_resources = new ArrayList(); - /** - * The default properties file - */ - private static Properties m_default; + private static Properties m_pluginMessages; + private static Locale m_locale = Locale.getDefault(); + private static boolean initialized = false; + private static boolean plugins_initialized = false; + //{{{ getMessagesFileName() private static String getMessagesFileName(Locale locale) { StringBuffer messagesFile = new StringBuffer("messages"); if (locale != null) { - String language = locale.getLanguage(); - if (language != null && !language.equals("")) { - messagesFile.append(".").append(language); + messagesFile.append(".").append(locale.toString()); + // String language = locale.getLanguage(); + // if (language != null && !language.equals("")) { + // messagesFile.append(".").append(language); - String country = locale.getCountry(); - if (country != null && !country.equals("")) { - messagesFile.append(".").append(country); + // String country = locale.getCountry(); + // if (country != null && !country.equals("")) { + // messagesFile.append(".").append(country); - String variant = locale.getVariant(); - if (variant != null && !variant.equals("")) { - messagesFile.append(".").append(variant); - } - } - } + // String variant = locale.getVariant(); + // if (variant != null && !variant.equals("")) { + // messagesFile.append(".").append(variant); + // } + // } + // } } return messagesFile.toString(); }//}}} //{{{ loadMessages() - /** - * @param locale the locale to use when searching for the messages file. - * The language, country, and variant must be exact. Null - * loads the default messages file. - */ - private static Properties loadMessages(Locale locale) { - Properties props = null; + private static void loadMessages(Locale locale) { + + String messagesFile = getMessagesFileName(locale); + try { - if (locale != null) { - props = (Properties)m_messagesMap.get(locale); - } else { - props = m_default; - } + //create input stream from messages file + FileInputStream in = new FileInputStream(jsXe.getInstallDirectory()+ + System.getProperty("file.separator")+ + "messages"+ + System.getProperty("file.separator")+ + messagesFile); - if (props == null) { - //{{{ Load the properties file - - String messagesFile = getMessagesFileName(locale); - - //create input stream from messages file - FileInputStream in = new FileInputStream(jsXe.getInstallDirectory()+ - System.getProperty("file.separator")+ - "messages"+ - System.getProperty("file.separator")+ - messagesFile.toString()); - Log.log(Log.NOTICE, Messages.class, "Loading messages file: "+messagesFile); - props = new Properties(); - props.load(in); - if (locale != null) { - m_messagesMap.put(locale, props); - } else { - m_default = props; - } - //}}} - } + Properties props = new Properties(); + + Log.log(Log.NOTICE, Messages.class, "Loading message file: "+messagesFile); + + props.load(in); + + m_messages = MiscUtilities.mergeProperties(m_messages, props); + } catch (FileNotFoundException e) { // just fall through } catch(IOException e) { Log.log(Log.ERROR, Messages.class, e); } + }//}}} + + //{{{ loadPluginMessages() + private static void loadPluginMessages(Locale locale) { - //{{{ Check for plugin resources - // Log.log(Log.DEBUG, Messages.class, "loading plugin messages"); + String messagesFile = getMessagesFileName(locale); + JARClassLoader loader = jsXe.getPluginLoader(); + + //create input stream from messages file try { - JARClassLoader loader = jsXe.getPluginLoader(); - if (loader != null) { - String messagesFile = getMessagesFileName(locale); - //TODO: inefficient - Enumeration pluginMessages = loader.getPluginResources("messages/"+messagesFile); - // Log.log(Log.DEBUG, Messages.class, "looking for: "+"messages/"+messagesFile); - while (pluginMessages.hasMoreElements()) { - URL resource = (URL)pluginMessages.nextElement(); - // Log.log(Log.DEBUG, Messages.class, resource.toString()); - if (!m_resources.contains(resource)) { - Properties resourceProps = new Properties(); - Log.log(Log.NOTICE, Messages.class, "Loading plugin messages file: "+resource.toString()); - resourceProps.load(resource.openStream()); - props = MiscUtilities.mergeProperties(props, resourceProps); - m_resources.add(resource); - if (locale != null) { - m_messagesMap.put(locale, props); - } else { - m_default = props; - } - } + Enumeration resources = loader.getPluginResources("messages/"+messagesFile); + + while (resources.hasMoreElements()) { + try { + Properties props = new Properties(); + URL resource = (URL)resources.nextElement(); + + Log.log(Log.NOTICE, Messages.class, "Loading plugin message file: "+resource.toString()); + + props.load(resource.openStream()); + + m_pluginMessages = MiscUtilities.mergeProperties(m_pluginMessages, props); + } catch (FileNotFoundException e) { + //fall through + } catch(IOException e) { + Log.log(Log.ERROR, Messages.class, e); } } } catch(IOException e) { Log.log(Log.ERROR, Messages.class, e); - }//}}} - - return props; + } + }//}}} - //{{{ getMessages() - /** - * Searches the available resources for a resource where it can draw - * the messages that are needed for the current locale. - */ - private static Properties getMessages(Locale locale) { - Properties messages = loadMessages(locale); - if (messages == null) { - messages = loadMessages(new Locale(locale.getLanguage(), locale.getCountry())); - if (messages == null) { - messages = loadMessages(new Locale(locale.getLanguage())); - if (messages == null) { - messages = loadMessages(null); - } + //}}} + + //{{{ initMessages() + public static void initMessages() { + if (!initialized) { + + Log.log(Log.NOTICE, Messages.class, "Loading localized messages: "+m_locale.toString()); + + m_messages = new Properties(); + + //{{{ load messages files that match the locale + + boolean hasLang = (m_locale.getLanguage() != null && !m_locale.getLanguage().equals("")); + boolean hasCountry = (m_locale.getCountry() != null && !m_locale.getCountry().equals("")); + boolean hasVariant = (m_locale.getVariant() != null && !m_locale.getVariant().equals("")); + + if (hasVariant) { + // use full locale + loadMessages(m_locale); } + + if (hasCountry) { + //use only language and country + loadMessages(new Locale(m_locale.getLanguage(), m_locale.getCountry())); + } + + if (hasLang) { + //use only the language + loadMessages(new Locale(m_locale.getLanguage())); + } + + //}}} + + // load the default messages + + loadMessages(null); + + initialized = true; } - return messages; }//}}} - //}}} + //{{{ initPluginMessages() + public static void initPluginMessages() { + if (!plugins_initialized) { + m_pluginMessages = new Properties(); + + Log.log(Log.NOTICE, Messages.class, "Loading localized messages for plugins: "+m_locale.toString()); + + //{{{ load messages files that match the locale + + boolean hasLang = (m_locale.getLanguage() != null && !m_locale.getLanguage().equals("")); + boolean hasCountry = (m_locale.getCountry() != null && !m_locale.getCountry().equals("")); + boolean hasVariant = (m_locale.getVariant() != null && !m_locale.getVariant().equals("")); + + if (hasVariant) { + // use full locale + loadPluginMessages(m_locale); + } + + if (hasCountry) { + //use only language and country + loadPluginMessages(new Locale(m_locale.getLanguage(), m_locale.getCountry())); + } + if (hasLang) { + //use only the language + loadPluginMessages(new Locale(m_locale.getLanguage())); + } + + //}}} + + // load the default messages. + + loadPluginMessages(null); + + plugins_initialized = true; + } + }//}}} //{{{ getLocale() + /** + * The current locale that jsXe is using to display localized messages. + */ public Locale getLocale() { return m_locale; }//}}} //{{{ setLocale() /** - * @param locale the new locale The ISO-639 language code + * @param locale the new locale */ public static void setLocale(Locale locale) { m_locale = locale; + if (initialized) { + initialized = false; + initMessages(); + + if (plugins_initialized) { + plugins_initialized = false; + initPluginMessages(); + } + } }//}}} //{{{ getMessage() @@ -237,11 +291,14 @@ */ public static synchronized String getMessage(String propertyName){ - Properties messages = getMessages(m_locale); + //search in order, localized messages->default messages->plugin messages + String message = m_messages.getProperty(propertyName); - //search in order, localized messages->default messages->plugin messages - String message = messages.getProperty(propertyName); if (message == null) { + message = m_pluginMessages.getProperty(propertyName); + } + + if (message == null) { Log.log(Log.WARNING, Messages.class, "Unregistered message requested: "+propertyName); } return message; Modified: trunk/jsxe/src/net/sourceforge/jsxe/jsXe.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/jsXe.java 2006-07-07 02:32:49 UTC (rev 993) +++ trunk/jsxe/src/net/sourceforge/jsxe/jsXe.java 2006-07-07 03:46:17 UTC (rev 994) @@ -147,10 +147,28 @@ initDefaultProps(); //}}} + //{{{ start logging + Log.init(true, Log.ERROR, false); + try { + BufferedWriter stream = new BufferedWriter(new FileWriter(getSettingsDirectory()+fileSep+"jsXe.log")); + stream.flush(); + stream.write("Log file created on " + new Date()); + stream.write(System.getProperty("line.separator")); + + Log.setLogWriter(stream); + + } catch (IOException ioe) { + Log.log(Log.ERROR, jsXe.class, ioe); + } + //}}} + + //{{{ start locale + Messages.initMessages(); + //}}} + //{{{ parse command line arguments String viewname = null; ArrayList files = new ArrayList(); - boolean debug = false; for (int i=0; i<args.length; i++) { if (args[i].equals("--help") || args[i].equals("-h")) { printUsage(); @@ -162,7 +180,7 @@ } if (args[i].equals("--debug")) { - debug = true; + Log.setDebug(true); } else { files.add(args[i]); } @@ -189,21 +207,7 @@ int y = (dim.height-h)/2; progressScreen.setLocation(x, y); progressScreen.setVisible(true); - //}}} - //{{{ start logging - Log.init(true, Log.ERROR, debug); - try { - BufferedWriter stream = new BufferedWriter(new FileWriter(getSettingsDirectory()+fileSep+"jsXe.log")); - stream.flush(); - stream.write("Log file created on " + new Date()); - stream.write(System.getProperty("line.separator")); - - Log.setLogWriter(stream); - - } catch (IOException ioe) { - Log.log(Log.ERROR, jsXe.class, ioe); - } progressScreen.updateSplashScreenDialog(10); //}}} @@ -462,7 +466,6 @@ return jsXeHome; } //}}} - //{{{ getHomeDirectory() method /** * Returns the path to the user's home directory. Modified: trunk/jsxe/src/net/sourceforge/jsxe/util/Log.java =================================================================== --- trunk/jsxe/src/net/sourceforge/jsxe/util/Log.java 2006-07-07 02:32:49 UTC (rev 993) +++ trunk/jsxe/src/net/sourceforge/jsxe/util/Log.java 2006-07-07 03:46:17 UTC (rev 994) @@ -240,7 +240,17 @@ } } }//}}} - + + //{{{ setDebug() + /** + * Sets whether debug is recorded to the log. + * @param debug If true, debug will be printed to the log even if it is not + * at or higher than the level. + */ + public static void setDebug(boolean debug) { + Log.debug = debug; + }//}}} + //{{{ Private members private static Object LOCK = new Object(); private static Document logDocument; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |