/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: I18n.java,v 1.3 2008/06/25 05:41:41 qcheng Exp $
*
*/
/**
* Portions Copyrighted [2011] [ForgeRock AS]
*/
/**
* The <code>I18n</code> class provides methods for applications and services
* to internationalize their messages.
* <p>
* In order for <code>I18n</code> to internationalize messages, it needs to
* determine the resource bundle name, i.e., properties file name.
* <code>I18n</code> supports two techniques by which applications and
* services can specify their I18N resource bundle name. The recommendation is
* to specify them during service (or application) registration via <b> SMS</b>
* using a XML file (see <code>com.iplanet.services.ServiceManager
* </code> and
* service registration DTD). The XML file could specify the resource bundle
* name (the attribute defined in the DTD is <code>i18nFileName</code>) and
* optionally URL of the jar file which contains the property file (the
* attribute defined in the DTD is <code>resourceBundleURL</code>). If URL
* for the jar file is not specified it is assumed that the resource bundle is
* in the <code>
* CLASSPATH</code>. Using this technique it is possible to
* customize resource bundle name and URL of the jar file by using SMS APIs,
* commands (CLI) or GUI. The solution makes internationalization of messages
* very dynamic and highly customizable.
* <p>
* <code>I18n</code> class be instantiated by calling the static
* <code>getInstance(String serviceName)</code> method. The parameter
* <code>serviceName</code> specifies the name of the service as mentioned in
* the XML file at the time of service registration.
* <p>
* Alternatively services and application can instantiate <code>I18n</code>
* object by specifying the resource bundle name (i.e., properties file name).
* Using this technique it is not possible to customize at runtime either the
* resource bundle name or the URL of the jar file that contains the properties
* file name. It is assumed that the properties file is present in
* <code>CLASSPATH</code>
*
* @supported.api
*/
public class I18n {
/* ASCII ISO */
/* Static varibale that holds all the I18n objects */
// private static SSOToken userSSOToken = null;
/* Instance variable */
private boolean initialized = false;
/**
* This constructor takes the name of the component as an argument and it
* should match with name of the resource bundle
*/
this.serviceName = serviceName;
}
private void initialize() {
if (initialized)
return;
// %%% Hack to get around cyclic dependency on I18n
// and other components that call I18n
initialized = true;
}
/**
* Method to get an instance of I18n object that has been either previously
* created or to obtain a new instance if it does'nt exist
*
* @param serviceName
* name of the service for which messages must be
* internationalized
* @return I18n object
* @supported.api
*/
if (serviceName == null)
return (null);
synchronized (i18nMap) {
}
}
return (i18nobj);
}
/**
* Method to obtain Locale object given its string representation
*
* @param stringformat
* Locale in a string format
* @return Locale object
*/
if (stringformat == null)
if (tk.hasMoreTokens())
if (tk.hasMoreTokens())
if (tk.hasMoreTokens())
}
/**
* Returns the resource file name associated with the service
*
* @return Returns the the ResourceBundle name associated with the service
*/
initialize();
return i18nFile;
}
/* Gets the resource bundle */
.get(stringformat);
} else {
}
if (initialized)
}
return (bundle);
}
/* Get the default locale stored in config */
/* %%% Get the default locale stored in config - to be implemented */
return (loc);
}
/**
* Method to obtain internationalized message from the
* resource bundle given the key and locale.
*
* @param key
* key string in the properties file
* @param locale
* locale in a string format
* @return returns internationalized message for the specified key
* @supported.api
*/
initialize();
return null;
}
}
/**
* Method to obtain internationalized message from the
* resource bundle given the key.
*
* @param key
* Key string in the properties file
* @return Returns value to the specified key
* @supported.api
*/
initialize();
return null;
}
}
/**
* Method to obtain internationalized message from the
* resource bundle given the key, locale and parameters.
*
* @param key
* key string in the properties file
* @param locale
* locale in a string format
* @param params
* parameters to be applied to the message
* @return returns internationalized message for the specified key
* @supported.api
*/
initialize();
return (null);
}
/**
* Method to obtain internationalized message from the
* resource bundle given the key and parameters.
*
* @param key
* Key string in the properties file
* @param params
* parameters to be applied to the message
* @return Returns value to the specified key
* @supported.api
*/
initialize();
return (null);
}
/**
* Decodes the string into specified charset
*
* @param s
* string to be decoded
* @param charset
* character set in which the string to be decoded
* @return Returns the decoded string
*/
if (s == null) {
return null;
}
try {
} catch (UnsupportedEncodingException uee) {
return s;
}
}
/**
* Checks whether the string is ascii or not
*
* @param s
* string to be checked
* @return true if the string is ascii, otherwise false
*/
if (s == null) {
return true;
}
try {
{
return false;
}
return false;
}
return true;
}
.toString();
return msg;
}
/**
* Formats the objects into specified message format.
*
* @param pattern
* pattern for which the message to be formatted
* @param j
* Object to be formatted & substituted
* @param l
* locale in a string format
* @return Returns the formatted message
*/
return msg;
}
/**
* Formats the objects into specified message format.
*
* @param pattern
* pattern for which the message to be formatted
* @param i
* Integer to be formatted & substituted
* @param l
* locale in a string format
* @return Returns the formatted message
*/
return msg;
}
/**
* Formats the objects into specified message format
*
* @param pattern
* pattern for which the message to be formatted
* @param d
* date
* @param tz
* Timezone
* @param l
* locale in a string format
* @return Returns the formatted message
*/
}
}
}
}