Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 65772 invoked from network); 5 Apr 2011 07:36:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Apr 2011 07:36:35 -0000 Received: (qmail 46360 invoked by uid 500); 5 Apr 2011 07:36:35 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 46329 invoked by uid 500); 5 Apr 2011 07:36:34 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 46322 invoked by uid 99); 5 Apr 2011 07:36:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Apr 2011 07:36:34 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Apr 2011 07:36:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A2B3B23889D7; Tue, 5 Apr 2011 07:36:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1088913 - in /sling/trunk/contrib/extensions/i18n/src: main/java/org/apache/sling/i18n/impl/ test/java/org/apache/sling/i18n/impl/ Date: Tue, 05 Apr 2011 07:36:09 -0000 To: commits@sling.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110405073609.A2B3B23889D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmeschbe Date: Tue Apr 5 07:36:09 2011 New Revision: 1088913 URL: http://svn.apache.org/viewvc?rev=1088913&view=rev Log: SLING-2047 First commit: Testcases and pseudo root ResourceBundle Added: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/RootResourceBundle.java (with props) sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/RootResourceBundleTest.java (with props) Modified: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java Added: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/RootResourceBundle.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/RootResourceBundle.java?rev=1088913&view=auto ============================================================================== --- sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/RootResourceBundle.java (added) +++ sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/RootResourceBundle.java Tue Apr 5 07:36:09 2011 @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.i18n.impl; + +import java.util.Enumeration; +import java.util.Locale; +import java.util.NoSuchElementException; +import java.util.ResourceBundle; + +/** + * The RootResourceBundle is an extremely simple resource bundle + * which is used as the root resource bundle for the resource bundle hierarchies + * provided by the {@link JcrResourceBundleProvider}. It has the following + * functionality: + *
    + *
  • The {@link #getLocale()} returns a pseudo locale with empty values for + * all fields (language, country, and variant)
  • + *
  • The {@link #handleGetObject(String)} always returns the provided + * key as the value
  • + *
  • The {@link #getKeys()} method always returns an empty enumeration
  • + *
+ */ +public class RootResourceBundle extends ResourceBundle { + + // The empty enumeration returned fomr getKeys() + private final Enumeration EMPTY = new Enumeration() { + + public boolean hasMoreElements() { + return false; + } + + public String nextElement() { + throw new NoSuchElementException(); + } + }; + + // The pseudo Locale returned by getLocale() + private final Locale locale = new Locale(""); + + /** + * Returns a Locale with empty language, country, and variant. + */ + @Override + public Locale getLocale() { + return locale; + } + + /** + * Always returns the key parameter as its value. + */ + @Override + protected Object handleGetObject(String key) { + return key; + } + + /** + * Always returns an empty enumeration. + */ + @Override + public Enumeration getKeys() { + return EMPTY; + } + +} Propchange: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/RootResourceBundle.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/RootResourceBundle.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev Url Modified: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java?rev=1088913&r1=1088912&r2=1088913&view=diff ============================================================================== --- sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java (original) +++ sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleTest.java Tue Apr 5 07:36:09 2011 @@ -265,7 +265,7 @@ public class JcrResourceBundleTest exten add(MESSAGES_DE, new Message("s/p/o", "spoon", "L�ffel", true)); // 5. not present in DE - add(MESSAGES_DE, PARENT_MSG); + add(MESSAGES_EN, PARENT_MSG); // 6. same as 1.-4., but different translations for overwriting into apps for (Message msg : MESSAGES_DE.values()) { @@ -319,6 +319,7 @@ public class JcrResourceBundleTest exten public void test_handle_missing_key() { // test if key is returned if no entry found in repo JcrResourceBundle bundle = new JcrResourceBundle(new Locale("de"), null, resolver); + bundle.setParent(new RootResourceBundle()); assertEquals("missing", bundle.getString("missing")); } @@ -339,8 +340,10 @@ public class JcrResourceBundleTest exten JcrResourceBundle bundle = new JcrResourceBundle(new Locale("de"), null, resolver); JcrResourceBundle parentBundle = new JcrResourceBundle(new Locale("en"), null, resolver); bundle.setParent(parentBundle); + parentBundle.setParent(new RootResourceBundle()); assertEquals(PARENT_MSG.message, bundle.getObject(PARENT_MSG.key)); + assertEquals("missing", bundle.getString("missing")); } public void test_search_path() throws Exception { Added: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/RootResourceBundleTest.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/RootResourceBundleTest.java?rev=1088913&view=auto ============================================================================== --- sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/RootResourceBundleTest.java (added) +++ sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/RootResourceBundleTest.java Tue Apr 5 07:36:09 2011 @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sling.i18n.impl; + +import java.util.Enumeration; +import java.util.Locale; +import java.util.NoSuchElementException; +import java.util.ResourceBundle; + +import junit.framework.TestCase; + +/** + * The RootResourceBundleTest tests the assertions of the + * RootResourceBundle: getObject and + * getString return the key as the value and getKeys() + * returns an empty Enumeration. + */ +public class RootResourceBundleTest extends TestCase { + + public void test_Locale() { + Locale rrl = new RootResourceBundle().getLocale(); + assertEquals("Expecting empty language", "", rrl.getLanguage()); + assertEquals("Expecting empty country", "", rrl.getCountry()); + assertEquals("Expecting empty variant", "", rrl.getVariant()); + } + + public void test_getKeys() { + Enumeration keys = new RootResourceBundle().getKeys(); + assertNotNull("Expecting a keys enumeration", keys); + assertFalse("Expecting empty keys enumeration", keys.hasMoreElements()); + + try { + keys.nextElement(); + fail("Expecting NoŜuchElementException on nextElement"); + } catch (NoSuchElementException nsee) { + // expected + } + } + + public void test_get_methods() { + ResourceBundle b = new RootResourceBundle(); + String key = "testKey"; + + assertSame("Expecting key as object value", key, b.getObject(key)); + assertSame("Expecting key as string value", key, b.getString(key)); + + try { + b.getStringArray(key); + fail("Expecting ClassCastException on getStringArray"); + } catch (ClassCastException cce) { + // expected + } + } +} Propchange: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/RootResourceBundleTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/RootResourceBundleTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev Url