Hi Naoto, On 06/22/2012 12:51 AM, Naoto Sato wrote:
OK so you want to limit the character counts for each format element, then I don't know of any way out of the box. You might want to create a subclass of DateFormatSymbols in which you want to truncate
It sounds reasonable but a little complex for this simple scenario. Anyway, Iet me try. Many thanks and best regards! Jonathan
each element with your need, then set it to SimpleDateFormat. Naoto On 6/19/12 11:36 PM, Jonathan Lu wrote:Hi Naoto, Thanks for your suggestion. I've tried SimpleDateFormat, but met the problem of making a common pattern string for all Locales. The Date.toString() approach is using pattern "EEE MMM dd HH:mm:ss zzz yyyy", but it does not work for me, failed cases are like "mar. déc. 3019:44:43 CST 0002" and "dim. sept. 30 02:49:58 CST 4992" in fr_FR locale.As described in Java spec, the text, month presentation will use full form if the number of pattern letters is 4/3 or more, other wise short form or number form will be used. But my problem is that the short/long forms in the same locale do not have the same length. So the only working pattern for me is "uu MM dd HH:mm:ss zzz yyyy" which is almost completely composed by numbers and looks the same in all locales. Any better idea on how to modify the pattern? I've made a simple test to test the vertical alignment of outputs, http://cr.openjdk.java.net/~luchsh/VerticalAlignmentTest.java Best regards Jonathan On 06/14/2012 05:02 AM, Naoto Sato wrote:Hi Jonathan, If you need to format dates with exact format you desire, you can use SimpleDateFormat class instead. That way the user would see months/weekdays localized and still you can control the output length. Downside is that the format you specify may not be the preferred one for the user for that locale. BTW, your regression test sets the default locale to some specific ones, and do not restore the original locale. That could result in some erroneous behavior in the succeeding tests. Original locale should be reset at the end. Naoto On 6/13/12 1:52 AM, Jonathan Lu wrote:Hello i18n-dev,Here's a question about output multiple lines in console under different locales, I firstly raised it in security-dev list, and proposed a patch http://mail.openjdk.java.net/pipermail/security-dev/2012-April/004760.htmlhttp://cr.openjdk.java.net/~luchsh/7163483/ but found no good solution for the problem of how to format the many fields of time string to be aligned in a column so far, so I'm forwarding the mail to i18n-dev, hope to get some suggestions since it is related to string format in different locales. Weijun has posted the question to core-libs-dev list, but no response yet.http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-April/010033.htmlCould anybody please help to take a look? Thanks - Jonathan -------- Original Message -------- Subject: Re: Code review request: 7163483 JarSigner -verify -verbose does not format date string according to locale Date: Tue, 24 Apr 2012 15:06:08 +0800 From: Weijun Wang <[email protected]> To: Jonathan Lu <[email protected]> CC: [email protected] Hi Jonathan Some comments: 1. Can you be sure that the new format always has the same length? jarsigner tries to output in a tabular style and each column should be aligned. 2. You might need to reformat the modified line to make it fit into 80 characters width. 3. Why not include the test inside the changeset? Thanks Max On 04/23/2012 05:46 PM, Jonathan Lu wrote:Hello security-dev, Here's a patch for bug 7163483, could anybody please help to take a look? http://cr.openjdk.java.net/~luchsh/7163483/ The problem is that command "jarsigner -verify -verbose my.jar" does not format date string according to current locale. following simple test case can be used to disclose this problem. /** Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ** This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as* published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License* version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA* or visitwww.oracle.com if you need additional information or have any* questions. */ /* * Portions Copyright (c) 2012 IBM Corporation */ import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Locale; import sun.security.tools.JarSigner; public class bug7163483 { public static void main(String[] args) throws Exception { final String[] arg = { "-verify", "-verbose", System.getProperty("java.home")+"/lib/jce.jar"}; ByteArrayOutputStream stream = new ByteArrayOutputStream(1024*64); PrintStream out = new PrintStream(stream); System.setOut(out); Locale.setDefault(Locale.GERMAN); JarSigner js = new JarSigner(); js.run(arg); out.flush(); String s1 = stream.toString(); s1 = s1.substring(0, s1.length()/2); stream.reset(); Locale.setDefault(Locale.FRANCE); js = new JarSigner(); js.run(arg); out.flush(); String s2 = stream.toString(); s2 = s2.substring(0, s2.length()/2); if (s1.equals(s2)) { System.err.println("Header output for GERMAN locale is:"+s1); System.err.println("Header output for FRANCE locale is:"+s2); throw new RuntimeException( "JarSigner verbose outputs are the same after setting locale!!"); } else { System.err.println("Header output for GERMAN locale is:"+s1); System.err.println("Header output for FRANCE locale is:"+s2); System.err.println("Test passed!"); } } } Thanks and best regards! - Jonathan Lu
