Letters to the Editor (2/20/99)

Mark Johnson responds to questions about his "XML JavaBeans, Part 1," article; a reader expresses a positive opinion about the version-number feature of 1.2 compilers and VMs; Bill Day helps a reader use Java 3D to move a "camera" view; and Geoff Friesen explains how to write an application based on the Telugu language, used in parts of India.

1 2 Page 2
Page 2 of 2

Linhua, Java 3D does not have a "camera" per se, but you can move the ViewPlatform, which moves your view into the world (and thus, appears to move the camera). More information on this distinction is available from: http://java.sun.com/products/java-media/mail-archive/3D/0530.html This Java 3d-interest mailing list also contains information on how you can move the ViewPlatform in your code. An in-depth discussion is available from my columns (search for "ViewPlatform" and "View" for more). Updated versions of both columns are available at: http://www.gamasutra.com/features/programming/19990115/java3d_01.htm and http://www.gamasutra.com/features/programming/19990122/java3d_02.htm Bill Day

"Internationalize your software, Part 3" by Geoff Friesen

Read

Read

Read

Work around unsupported local languages in Java 2

Geoff,

I want to write a Word for Windows-type application/applet for the TELUGU language (Unicode language code TE), one of the languages used in India (Unicode country code IN). But the list of LOCALES supported by Java 2 does not contain te_IN.

My question: Can I use Java to do my project? If so, how?

Srinivas Nimmagadda

Srinivas, Thanks for writing. It certainly is a problem when Java 2 does not support a particular locale. However, you can still write an application from this locale's perspective. You'll just have to do a lot more work. If you read my "

Internationalize your software, Part 2

," article you might recall my discussion about umbrella classes. I had this to say:

An umbrella class is an abstract base class that describes either a common entity (such as a calendar) or a common operation (such as sorting). This class shields code from the many concrete (as opposed to abstract) subclass implementation differences by providing a common interface to these implementations. Umbrella classes contain static factory methods, giving code the ability to instantiate objects from concrete subclasses without needing to know any details about those subclasses.

You typically pass a locale object, for your desired locale, to the factory method. But you can't do this if a locale is not supported. So what do you do? You work directly with the concrete subclasses. For example, suppose you needed a currency formatter for an unsupported locale. You wouldn't be able to work with

NumberFormat

by calling its

getCurrencyInstance

methods. Instead, you would need to work directly with the

DecimalFormat

and

DecimalFormatSymbols

classes. I didn't bother to include an example that uses these classes in the third part of my series because it would have increased the size of an already long article. However, I did point out that there is a good example at Sun's Java Tutorial site. You can visit the Java Tutorial by going to the following address:

http://java.sun.com/docs/books/tutorial/index.html

Geoff Friesen

Solutions to jar file problems in an internationalization applet

Geoff,

I've been trying to use an internationalization applet. I use a jar file with the classes and properties files.

I've read your articles about internationalization, particularly the comment about using jar files with properties files.

However, my applet doesn't run. Netscape always shows the message: "java.util.MissingResourceException: Can't find resource."

My applet is:

 
<HTML>
<HEAD>
<TITLE> A simple program </TITLE>
</HEAD>
<BODY>
<APPLET CODE=internationalDynamic.class
archive=i.jar
WIDTH=800 HEIGHT=600>
</APPLET>
</BODY>
</HTML>

And a jar file includes all classes and properties files.

What can I do to read properties files into a jar file?

Javier Sanz Alamillo

Javier, Thanks for writing. I'm going to answer your question by first providing the following excerpt from my

"Internationalize your software, Part 2,"

article:

Remember last month's Example3 applet -- the applet that works with property resource bundles? I mentioned that this applet would not run under Netscape because it tries to access the user's machine to read the underlying property file, and this activity results in a security violation. This security violation causes the Java runtime code to throw a MissingResourceException object. So how can we get past this problem? The solution is to place Example3's class and property files in a jar file, and to include a reference to this jar file in the <APPLET> tag. The following code fragment uses the jar command (under Windows 95) to create a jar file called example3.jar. This command places example3.class and all files that end with a .properties extension into this jar file:
jar -cvf example3.jar example3.class *.properties
The following code fragment shows the <APPLET> tag with the new ARCHIVE attribute. This attribute is used to identify the jar file.
<APPLET ARCHIVE="example3.jar" 
    CODEBASE="/javaworld/jw-01-1999/internationalize" 
    CODE="example3.class" 
    WIDTH=200 
    HEIGHT=220>
</APPLET>
And now for the grand finale! The following PropertyResourceBundle example shows the same Example3 applet we were introduced to in last month's installment. The source code and class files are the same. The only differences are that the Example3 class and properties files have been placed into a jar file, and that the <APPLET> tag has an ARCHIVE attribute.

This leads me to ask you the following questions:

  1. Have you placed all of your properties files in the jar file? You need to place the properties file for each supported locale in the jar file. You should also include the class file in the jar file. The CODE attribute in the <APPLET> tag simply identifies the class file within the jar file.
  2. Is your jar file in the same directory as your class file? In other words, do i.jar and internationalDynamic.class reside in the same directory on the server? If they don't, you will need to include the CODEBASE attribute in your <APPLET> tag. You will set the value of CODEBASE to the directory containing the jar file.

Geoff Friesen

Related:
1 2 Page 2
Page 2 of 2