logo       

r1774 - izpack-src/trunk/src/lib/com/izforge/izpack: msg#00011

Subject: r1774 - izpack-src/trunk/src/lib/com/izforge/izpack
Author: bartzkau
Date: 2007-03-09 15:56:41 +0100 (Fri, 09 Mar 2007)
New Revision: 1774

Modified:
   izpack-src/trunk/src/lib/com/izforge/izpack/LocaleDatabase.java
Log:
Extensions for new logging stuff.


Modified: izpack-src/trunk/src/lib/com/izforge/izpack/LocaleDatabase.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/LocaleDatabase.java     
2007-03-08 13:41:58 UTC (rev 1773)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/LocaleDatabase.java     
2007-03-09 14:56:41 UTC (rev 1774)
@@ -20,9 +20,12 @@
 package com.izforge.izpack;
 
 import java.io.InputStream;
+import java.text.MessageFormat;
 import java.util.TreeMap;
 import java.util.Vector;
 
+import com.izforge.izpack.util.StringTool;
+
 import net.n3.nanoxml.NonValidator;
 import net.n3.nanoxml.StdXMLBuilder;
 import net.n3.nanoxml.StdXMLParser;
@@ -52,6 +55,13 @@
         add(in);
     }
 
+    /**
+     * Adds the contents of the given stream to the data base. The stream have 
to contain key value
+     * pairs as declared by the DTD langpack.dtd.
+     * 
+     * @param in an InputStream to read the translation from.
+     * @throws Exception
+     */
     public void add(InputStream in) throws Exception
     {
         // Initialises the parser
@@ -98,8 +108,38 @@
         // At a change of the return value at val == null the method
         // com.izforge.izpack.installer.IzPanel.getI18nStringForClass
         // should be also addapted.
-        if (val == null) val = key;
+        if (val == null)
+            val = key;
         return val;
     }
+
+    /**
+     * Convenience method to retrieve an element and simultainiously insert 
variables into the
+     * string. A placeholder have to be build with the substring {n} where n 
is the parameter
+     * argument beginning with 0. The first argument is therefore {0}. If a 
parameter starts with a
+     * dollar sign the value will be used as key into the LocalDatabase. The 
key can be written as
+     * $MYKEY or ${MYKEY}. For all placeholder an argument should be exist and 
vis a versa.
+     * 
+     * @param key The key of the element to retrieve.
+     * @param variables the variables to insert
+     * @return The element value with the variables inserted or the key if not 
found.
+     */
+    public String getString(String key, String[] variables)
+    {
+        for (int i = 0; i < variables.length; ++i)
+        {
+            if (variables[i].startsWith("$"))
+            { // Argument is also a key into the LocaleDatabase.
+                String curArg = variables[i];
+                if (curArg.startsWith("${"))
+                    curArg = curArg.substring(2, curArg.length() - 1);
+                else
+                    curArg = curArg.substring(1);
+                variables[i] = getString(curArg);
+            }
+        }
+
+        return MessageFormat.format(getString(key), variables);
+    }
+
 }
-


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
web.pylons.gene...    hurd.l4/2002-10...    kernel.commits....    user-groups.lin...    yellowdog.gener...    java.drools.use...    security.openva...    package-managem...    linux.debian.us...    qnx.openqnx.dev...    genealogy.gramp...    file-systems.if...    voip.wengophone...    tex.context/200...    ietf.smime/2003...    audio.csound.de...    culture.region....    xfree86.devel/2...    mobile.kannel.u...    distributed.con...    education.engli...    org.user-groups...    bug-tracking.gn...    recreation.bicy...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe