Archive for September, 2007

Ipower web hosting - key=value Example 12-3 displays a properties file called

Sunday, September 16th, 2007

key=value Example 12-3 displays a properties file called StorefrontMessageResources.properties that can be loaded by the Struts framework. Example 12-3. A simple Struts resource bundle global.title=Virtual Shopping with Struts global.error.invalidlogin=The login was unsuccessful! Please try again. global.required={0} is a required value. label.featuredproducts=This Weeks Featured Products label.email=Email Address label.password=Password label.returning label.firstName=First Name label.lastName=Last Name label.address=Address label.city=City label.state=State label.postalCode=Postal Code label.zip=Zip label.country=Country label.phone=Phone button.add=Add Me button.delete=Delete button.checkout=Checkout button.saveorder=Save Order errors.required={0} is required. errors.minlength={0} can not be less than {1} characters. errors.maxlength={0} can not be greater than {1} characters. errors.invalid={0} is invalid. errors.byte={0} must be a byte. errors.short={0} must be a short. errors.integer={0} must be an integer. errors.long={0} must be a long. errors.float={0} must be a float. errors.double={0} must be a double. errors.date={0} is not a date. errors.range={0} is not in the range {1} through {2}. errors.creditcard={0} is not a valid credit card number. errors.email={0} is not a valid e-mail address. You must be sure to name the message resource file with the extension .properties, or the Struts framework will not be able to load it.
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Web site design and hosting - Using compound messages in your resource bundles can

Saturday, September 15th, 2007

Using compound messages in your resource bundles can make translation a little harder because the text contains substitution values that are not known until runtime. Also, human translators must take into account where the variable text goes in the localized message, because the substitution values may need to be in different positions in the message for different languages. The Struts framework includes the capabilities of the MessageFormat class but encapsulates the functionality behind the components within the framework. 12.2.4 Multilingual Support Most of us cringe at the thought of supporting user groups that are in one of several possible locales. In many cases, however, once an application has been installed and localized, it’s like any other single- locale application. The users that access the application are either all from the same locale or are from locales similar enough that the language and cultural differences are insignificant. Multilingual applications, on the other hand, take internationalization to the next level by allowing users from different locales to access the same application. This means that the application has to be flexible enough to detect the user’s locale and format everything based on that locale. This is much harder to do than just localizing an application. The discussion of building multilingual applications is so large that it can’t be covered satisfactorily in this book. For the remainder of this chapter, we’ll stick with just the everyday internationalization problems that you’ll face, and not focus on multilingual support. 12.3 Internationalizing Your Struts Applications The internationalization support provided by the Struts framework focuses almost exclusively on the presentation of text and images for the application. Functionality such as accepting input from nontraditional languages is not covered within the Struts framework. As you’ve already seen, depending on your Struts configuration settings, the framework can determine the preferred locale for a user and store it into the user’s session. Once the user’s locale has been determined, Struts can use this locale to look up text and other resources from the resource bundles. The resource bundles are essential components in the Struts framework. 12.3.1 The Struts Resource Bundle As you saw in Chapter 4, each of your application modules can be configured with one or more resource bundles. The information within each bundle is available to actions, action forms, JSP pages, and custom tags alike. 12.3.1.1 Creating a Struts resource bundle Resource bundles that you create must follow the conventions of the PropertyResourceBundle class from the Java core library. That is, you need to create a text file for your resource bundle that has a .properties extension and that adheres to the guidelines discussed in the JavaDoc for the java.util.Properties class. The most important of these guidelines is that the format of the messages within this file is:
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Top ten web hosting - import java.util.ResourceBundle; import java.util.Locale; import java.text.MessageFormat; public class

Friday, September 14th, 2007

import java.util.ResourceBundle; import java.util.Locale; import java.text.MessageFormat; public class FormatExample { public static void main(String[] args) { // Load the resource bundle ResourceBundle bundle = ResourceBundle.getBundle( “ApplicationResources” ); // Get the message templateString requiredFieldMessage = bundle.getString( “error.requiredfield” ); // Create a String array of size one to hold the argumentsString[] messageArgs = new String[1]; // Get the “Name” field from the bundle and load it in asan argumentmessageArgs[0] = bundle.getString( “label.name” ); // Format the message using the message and the argumentsString formattedNameMessage = MessageFormat.format( requiredFieldMessage, messageArgs ); System.out.println( formattedNameMessage ); // Get the “Phone” field from the bundle and load it in asan argumentmessageArgs[0] = bundle.getString( “label.phone” ); // Format the message using the message and the argumentsString formattedPhoneMessage = MessageFormat.format( requiredFieldMessage, messageArgs ); System.out.println( formattedPhoneMessage ); } } Messages that contain variable data are known as compound messages. Using compound messages allows you to substitute application-specific data into messages from the resource bundle at runtime. It can also reduce the number of messages that your application requires in the resource bundle, which can decrease the amount of time that it takes to translate to other locales.
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

The Struts framework does not use (Web site template) the ResourceBundle

Thursday, September 13th, 2007

The Struts framework does not use the ResourceBundle class provided by the core language. Instead, it provides similar functionality with the classes within its framework. The org.apache.struts.util.MessageResources class and its only concrete subclass, org.apache.struts.util.PropertyMessageResources , are used to perform parallel functionality to that of the ResourceBundle hierarchy. If you understand the fundamentals of the ResourceBundle in the code library, you basically understand how the version within the Struts framework operates. In retrospect, the class should at least have been a subclass of the Java ResourceBundle. You’ll see an example of creating a resource bundle for a Struts application later in this chapter in Section 12.3.1. 12.2.3 The MessageFormat Class The Java ResourceBundle and the Struts MessageResources class allow for both static and dynamic text. Static text is used for elements such as field and button labels where the localized strings are used exactly as they are in the bundle in other words, when the text for the message is known ahead of time. With dynamic text, part of the message may not be known until runtime. To help make the difference clearer, let’s look at an example. Suppose you need to display a message to the user informing him that the name and phone input fields are required in order to save. One approach would be to add entries like these to the resource bundle: error.requiredfield.name=The Name field is required to save. error.requiredfield.phone=The Phone field is required to save. // other resource messages This approach works fine, but what if there were hundreds of required fields? You would need a resource message for each required field, and the resource bundle would become very large and difficult to maintain. Note, however, that the only difference between the two messages is the name of the field that is required. A much easier and more maintainable approach is to use the functionality of the java.text.MessageFormat class. This allows you to do something like this: error.requiredfield=The {0} field is required to save. label.phone=Phonelabel.name=Name The values that are not known until runtime are substituted in the message by a set of braces and an integer value. The integer inside the braces is used as an index into an Object[]that is passed in with the format( ) message of the MessageFormatclass. Example 12-2 provides an example of this. Example 12-2. Using the MessageFormat class to format messages with variable text
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Unable to start debugging on the web server - Getting the user’s locale within the Struts framework

Wednesday, September 12th, 2007

Getting the user’s locale within the Struts framework is easy. There are, in fact, several ways of getting the stored Locale for the user, depending on where you are trying to access it. If you are within an Action class, for example, you can simply call the getLocale( )method defined in the Struts base Action class. The following fragment shows the getLocale( ) method: protected Locale getLocale(HttpServletRequest request) { HttpSession session = request.getSession( ); Locale locale = (Locale) session.getAttribute(LOCALE_KEY); if (locale == null) locale = defaultLocale; return (locale); } You will need to pass the request object to this method because it will need to use the HttpSession to obtain the locale. The getLocale( )method will always return an instance of the Locale, even if one isn’t stored in the session for the user. The method will return the defaultLocale if necessary. The defaultLocale property is stored as a static member variable that every Action subclass has access to: protected static Locale defaultLocale = Locale.getDefault( ); Obtaining the user’s locale from anywhere else is also straightforward. You can simply get it directly from the session as the getLocale( )method does, using the Action.LOCALE_KEY: Locale userLocale = (Locale)session.getAttribute( Action.LOCALE_KEY); // With this approach, always check the Locale to see if it’snull if ( userLocale != null ){ // Access the Locale} Because it’s possible that no Locale is stored in the user’s session, you should compare the returned Locale to null before attempting to use it. If your application allows a user to change locales on the fly, you may have to call the getLocale( )method on each new request to see if the user has changed locales. An example of doing this was shown in the CustomRequestProcessor class in Example 5-4. 12.2.2 Java Resource Bundles The java.util.ResourceBundle class provides the ability to group together a set of resources for a given locale. The resources are usually textual elements such as field and button labels and status messages, but they can also be items such as image names, error messages, and page titles.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Tuesday, September 11th, 2007

out.println(”

    “); while( allUserSupportedLocales.hasMoreElements( ) ){ Locale supportedLocale = (Locale)allUserSupportedLocales.nextElement( ); StringBuffer buf = new StringBuffer( ); buf.append(”
  • “); buf.append(”Locale: “); buf.append( supportedLocale ); buf.append( ” - ” ); buf.append( supportedLocale.getDisplayName( ) ); buf.append(”
  • “); // Print out the line for a single Localeout.println( buf.toString( ) ); } out.println(”

“); // Get the container’s default localeLocale servletContainerLocale = Locale.getDefault( ); out.println(”

The container’s Locale ” + servletContainerLocale + “

“); out.println(”“); } } When you execute the servlet in Example 12-1, you should see output similar to the browser output in Figure 12-1. Figure 12-1. Browser output from Example 12-1 The output may be different if you have different locales configured for your system. Most web browsers allow you to configure the locales you prefer to support. With Microsoft Internet Explorer, for example, you can edit the languages in the Tools Internet Options pulldown menu.
We highly recommend you visit
web and email hosting services if you need stable and cheap web hosting platform for your web applications.

Example 12-1. Determining the user’s locale information in (Michigan web site)

Monday, September 10th, 2007

Example 12-1. Determining the user’s locale information in a servlet import java.io.IOException; import java.io.PrintWriter; import java.util.Enumeration; import java.util.Locale; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * Prints out information about a user’s preferred locales */ public class LocaleServlet extends HttpServlet { private static final String CONTENT_TYPE = “text/html”; /** * Initialize the servlet */ public void init(ServletConfig config) throws ServletException { super.init(config); } /** * Process the HTTP Get request*/ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); PrintWriter out = response.getWriter( ); out.println(”“); out.println(”“); out.println(”“); // Retrieve and print out the user’s preferred localeLocale preferredLocale = request.getLocale( ); out.println(”

The user’s preffered Locale is ” + preferredLocale + “

“); // Retrieve all of the supported locales of the userout.println(”

A list of preferred Locales in descreasingorder

“); Enumeration allUserSupportedLocales = request.getLocales( );
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Photo web hosting - Locale locale1 = Locale.JAPAN; Locale locale2 = new

Sunday, September 9th, 2007

Locale locale1 = Locale.JAPAN; Locale locale2 = new Locale(”ja”, “JP”); 12.2.1.1 The default locale The JVM will query the operating system when it’s first started and set a default locale for the environment. You can obtain the information for this default locale by calling the getDefault( ) method on the Localeclass: Locale defaultLocale = Locale.getDefault( ); The web container will normally use the default locale for its local environment, while using the one passed from the client in the HttpServletRequest to display locale-sensitive information back to the end user. 12.2.1.2 Determining the user’s locale In the last section, you saw how to create Locale objects in Java by passing in the language and country code to the Localeconstructor. Within web applications, including those built using the Struts framework, you rarely have to create your own locale instances because the container does it for you. The ServletRequest interface contains two methods that can be called to retrieve the locale preferences of a client: public java.util.Locale getLocale( ); public java.util.Enumeration getLocales( ); Both of these methods use the Accept-Language header that is part of each client request sent to the servlet container. Because the web server doesn’t keep a long-term connection open with a browser, the client locale preference is sent to the servlet container with each request. Although the user’s locale information may be sent with each request, Struts will, by default, retrieve the information only once and store it into the user’s session. The Locale object, if stored into the session, is stored with a key of Action.LOCALE_KEY, which translates to the string org.apache.struts.action.LOCALE. You can configure whether Struts stores the user’s locale into the session by setting the locale attribute in the controller element within the Struts application configuration file. If you don’t provide a value for the locale attribute, it defaults to false. See Chapter 4 for more information on configuring the locale. Calling the getLocale( )method on the HttpServletRequestobject returns the preferred locale of the client, while the getLocales( )method returns an Enumerationof preferred locales in decreasing order of preference. If a client doesn’t have a preferred locale configured, the servlet container will return its default locale. Example 12-1 illustrates how to determine this information using a servlet.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

12.2.1 The Locale Class The java.util.Locale class is (Geocities web hosting)

Saturday, September 8th, 2007

12.2.1 The Locale Class The java.util.Locale class is undeniably the most important I18N class in the Java library. Almost all of the support for internationalization and localization in or around the Java language relies on this class. The Locale class provides Java with instances of the locale concept mentioned earlier. A particular instance of the Locale represents a unique language and region. When a class in the Java library modifies its functionality during runtime based on a Locale object, it’s said to be locale-sensitive. For example, the java.text.DateFormat is locale-sensitive because it will format a date differently depending on a particular Locale object. The Locale objects don’t do any of the I18N formatting or parsing work. They are used as identifiers by the locale-sensitive classes. When you acquire an instance of the DateFormat class, you can pass in a Localeobject for the United States. The DateFormatclass does all of the locale-sensitive parsing and formatting; it relies on the Locale only to identify the proper format. Be very careful when using the java.text.Format class or any of its descendants, including DateFormat, NumberFormat, and SimpleDateFormat, because they are not thread-safe. The thread-safety problem exists because an instance of the Calendar class is stored as a member variable and accessed during the parse( )and format( ) method invocations. You will need to use a separate instance for each thread or synchronize access externally. Don’t store a single instance in somewhere like the application scope and allow multiple client threads to access it. You can, however, store instances in the users’ sessions and use different instances for each user to help ensure thread-safety. The thread-safety problem includes all versions of Java, including 1.4. The API documentation for the Format classes has been updated to indicate the known design issue. When you create a Locale object, you typically specify the language and country code. The following code fragment illustrates the creation of two Locale objects, one for the U.S. and the other for Great Britain: Locale usLocale = new Locale(”en”, “US”); Locale gbLocale = new Locale(”en”, “GB”); The first argument in the constructor is the language code. The language code consists of two lowercase letters and must conform to the ISO-639 specification. You can find a complete listing of the available language codes at http://www.unicode.org/unicode/onlinedat/languages.html. The second argument is the country code. It consists of two uppercase letters that must conform to the ISO-3166 specification. The list of available country codes is available at http://www.unicode.org/unicode/onlinedat/countries.html. The Locale class provides several static convenience constants that allow you to acquire an instance of the most-often-used locales. For example, to get an instance of a Japanese locale, you could use either of these:
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Web site design and hosting - Additional languages can be supported without requiring

Friday, September 7th, 2007

Additional languages can be supported without requiring code changes. Text elements, messages, and images are stored externally to the source code. Culturally dependent data such as dates and times, decimal values, and currencies are formatted correctly for the user’s language and geographic location. Nonstandard character sets are supported. The application can quickly be adapted to new languages and/or regions. When you internationalize an application, you can’t afford to pick and choose which options you want to support. You must implement all of them or the process breaks down. If a user visits your web site and all of the text, images, and buttons are in the correct language but the numbers and currency are not formatted correctly, it will make for an unpleasant user experience. Ensuring that the application can support multiple languages and regions is only the first step. You still must create localized versions of the application for each specific language and/or region that you want to support. Fortunately, here’s where the benefits of I18N on the Java platform pay off. For applications that have been properly internationalized, all of the work to support a new language or country is external to the source code. A locale is a region (usually geographic, but not necessarily so) that shares customs, culture, and language. Applications that are written for a single locale are commonly referred to as myopic. Localization (L10N) is the process of adapting your application, which has been properly internationalized, to a specific locale. For applications where I18N support hadn’t been planned or built in, this usually means changes to text, images, and messages that are embedded within the source code. After the changes are applied, the source code may need to be recompiled. Imagine doing this time and time again for each new locale you have to support! According to Richard Gillam from the Unicode Technology Group, which designed much of the I18N support in the Java libraries, “Internationalization is not a feature.” Users will expect that the products they use will work for them in their native languages. Things can go wrong, and users get unhappy when assumptions that you make are incorrect. Start planning early for I18N support in your applications. Even if it doesn’t look like you’re going to need it, if you do you’ll be that much further ahead, and it won’t hinder development as long as you do it right from the start. Not every application needs I18N support, and some developers and development organizations frown on adding in functionality that isn’t part of the requirements. However, even if your application has no requirements to support more than a single locale, there are still benefits that you can gain from including some aspects of I18N. For example, by using resource bundles for all of your static text, you can save development and, more importantly, maintenance time. We’ll see how this is true later in the chapter. 12.2 Support for I18N in Java Java provides a rich set of I18N features in the core library. This section briefly discusses a few of those core features. The I18N support in the Struts framework relies heavily on these components, and understanding how the Java I18N components cooperate with each other will help you understand how to internationalize your Struts applications. The topic of internationalization is too broad to cover in depth in this book. A more complete discussion of the topic can be found in the book JavaInternationalization by Andy Deitsch and David Czarnecki (O’Reilly).
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.