
The branch, master has been updated via 5419731c7a921a181da5dcd2ccaf7f13e80dbd19 (commit) from c67c69e96c0f7b174f755a44eb4f60f1c8c5bd40 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://git.qos.ch/gitweb/?p=cal10n.git;a=commit;h=5419731c7a921a181da5dcd2cc... http://github.com/ceki/cal10n/commit/5419731c7a921a181da5dcd2ccaf7f13e80dbd1... commit 5419731c7a921a181da5dcd2ccaf7f13e80dbd19 Author: Ceki Gulcu <ceki@qos.ch> Date: Thu Sep 3 21:43:14 2009 +0200 - adding encoding tests diff --git a/cal10n-api/src/main/java/ch/qos/cal10n/util/CAL10NResourceBundle.java b/cal10n-api/src/main/java/ch/qos/cal10n/util/CAL10NResourceBundle.java index a586380..d584cd7 100644 --- a/cal10n-api/src/main/java/ch/qos/cal10n/util/CAL10NResourceBundle.java +++ b/cal10n-api/src/main/java/ch/qos/cal10n/util/CAL10NResourceBundle.java @@ -43,7 +43,8 @@ public class CAL10NResourceBundle extends ResourceBundle { File hostFile; volatile long nextCheck; long lastModified; - + CAL10NResourceBundle parent; + public CAL10NResourceBundle(Reader r, File file) throws IOException { read(r); @@ -57,8 +58,9 @@ public class CAL10NResourceBundle extends ResourceBundle { } - public void setParent(ResourceBundle parent) { - super.setParent(parent); + public void setParent(CAL10NResourceBundle parent) { + this.parent = (parent); + //super.setParent(parent); } public boolean hasChanged() { @@ -87,11 +89,14 @@ public class CAL10NResourceBundle extends ResourceBundle { public void resetCheckTimes() { nextCheck = 0; lastModified = 0; - } + } @Override public Enumeration<String> getKeys() { Hashtable<String, String> ht = new Hashtable<String, String>(map); + if(parent != null) { + ht.putAll(parent.map); + } return ht.keys(); } @@ -100,6 +105,10 @@ public class CAL10NResourceBundle extends ResourceBundle { if (key == null) { throw new NullPointerException(); } - return map.get(key); + Object o = map.get(key); + if(o == null && parent != null) { + o = parent.handleGetObject(key); + } + return o; } } diff --git a/cal10n-api/src/test/java/ch/qos/cal10n/util/PackageTest.java b/cal10n-api/src/test/java/ch/qos/cal10n/util/PackageTest.java index f5622df..037b77f 100644 --- a/cal10n-api/src/test/java/ch/qos/cal10n/util/PackageTest.java +++ b/cal10n-api/src/test/java/ch/qos/cal10n/util/PackageTest.java @@ -29,6 +29,6 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses( { AnnotationExtractorTest.class, MiscUtilTest.class, TokenStreamTest.class, ParserTest.class, - PropertyResourceBundleFinderTest.class }) + PropertyResourceBundleFinderTest.class, ResourceBundleEncodingTest.class }) public class PackageTest { } diff --git a/cal10n-api/src/test/java/ch/qos/cal10n/util/ResourceBundleEncodingTest.java b/cal10n-api/src/test/java/ch/qos/cal10n/util/ResourceBundleEncodingTest.java new file mode 100644 index 0000000..eda9155 --- /dev/null +++ b/cal10n-api/src/test/java/ch/qos/cal10n/util/ResourceBundleEncodingTest.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2009 QOS.ch All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package ch.qos.cal10n.util; + +import static org.junit.Assert.assertEquals; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +import ch.qos.cal10n.Cal10nTestConstants; + +/** + * + * @author Ceki Gülcü + * + */ +public class ResourceBundleEncodingTest { + + + // Useful links: + + // http://www.terena.org/activities/multiling/ml-docs/iso-8859.html + + Map<String, String> map = new HashMap<String, String>(); + Map<String, String> witness = new HashMap<String, String>(); + + // encoding for Greek "ISO8859_7" + @Test + public void greek() throws IOException { + FileInputStream fis = new FileInputStream(Cal10nTestConstants.TEST_CLASSES + + "/encodings/a_el_GR.properties"); + Reader reader = new InputStreamReader(fis, "ISO8859_7"); + Parser parser = new Parser(reader, map); + parser.parseAndPopulate(); + + String alpha = "\u03b1"; + witness.put("A", alpha); + + // char alphaChar = alpha.charAt(0); + // System.out.println("alphaChar="+((int) alphaChar)); + // String suspected = map.get("A"); + // char suspectedChar = suspected.charAt(0); + // System.out.println("suspectedChar="+((int) suspectedChar)); + + assertEquals(witness, map); + } + + + // encoding for Turkish "ISO8859_3" + @Test + public void turkish() throws IOException { + FileInputStream fis = new FileInputStream(Cal10nTestConstants.TEST_CLASSES+"/encodings/a_tr_TR.properties"); + Reader reader = new InputStreamReader(fis, "ISO8859_3"); + Parser parser = new Parser(reader, map); + parser.parseAndPopulate(); + + // 0xBA 0x015F # LATIN SMALL LETTER S WITH CEDILLA + char sCedilla = '\u015F'; + + // 0xB9 0x0131 # LATIN SMALL LETTER DOTLESS I + char iDotless = '\u0131'; + + // nisan pronounced (nIshan) + String witnessValue = "n"+iDotless+sCedilla+"an"; + witness.put("A", witnessValue); + assertEquals(witness, map); + } +} diff --git a/cal10n-api/src/test/resources/encodings/#a_tr_TR.properties# b/cal10n-api/src/test/resources/encodings/#a_tr_TR.properties# new file mode 100644 index 0000000..e4dec3d --- /dev/null +++ b/cal10n-api/src/test/resources/encodings/#a_tr_TR.properties# @@ -0,0 +1 @@ +A=nýsan \ No newline at end of file diff --git a/cal10n-api/src/test/resources/encodings/a_el_GR.properties b/cal10n-api/src/test/resources/encodings/a_el_GR.properties new file mode 100644 index 0000000..13cf8d6 --- /dev/null +++ b/cal10n-api/src/test/resources/encodings/a_el_GR.properties @@ -0,0 +1 @@ +A=á diff --git a/cal10n-api/src/test/resources/encodings/a_tr_TR.properties b/cal10n-api/src/test/resources/encodings/a_tr_TR.properties new file mode 100644 index 0000000..95d9564 --- /dev/null +++ b/cal10n-api/src/test/resources/encodings/a_tr_TR.properties @@ -0,0 +1 @@ +A=n¹ºan \ No newline at end of file ----------------------------------------------------------------------- Summary of changes: .../ch/qos/cal10n/util/CAL10NResourceBundle.java | 19 ++++-- .../test/java/ch/qos/cal10n/util/PackageTest.java | 2 +- ...erTest.java => ResourceBundleEncodingTest.java} | 73 ++++++++++++-------- .../test/resources/encodings/#a_tr_TR.properties# | 1 + .../test/resources/encodings/a_el_GR.properties | 1 + .../test/resources/encodings/a_tr_TR.properties | 1 + 6 files changed, 62 insertions(+), 35 deletions(-) copy cal10n-api/src/test/java/ch/qos/cal10n/util/{ParserTest.java => ResourceBundleEncodingTest.java} (51%) create mode 100644 cal10n-api/src/test/resources/encodings/#a_tr_TR.properties# create mode 100644 cal10n-api/src/test/resources/encodings/a_el_GR.properties create mode 100644 cal10n-api/src/test/resources/encodings/a_tr_TR.properties hooks/post-receive -- Compiler assisted localization library