incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1102314 - in /sling/trunk/contrib/extensions/i18n/src/main: java/org/apache/sling/i18n/impl/JcrResourceBundle.java java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java resources/OSGI-INF/metatype/metatype.properties
Date Thu, 12 May 2011 14:02:27 GMT
Author: justin
Date: Thu May 12 14:02:26 2011
New Revision: 1102314

URL: http://svn.apache.org/viewvc?rev=1102314&view=rev
Log:
SLING-2061 - just preloading all bundles. much simpler

Modified:
    sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
    sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
    sling/trunk/contrib/extensions/i18n/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java?rev=1102314&r1=1102313&r2=1102314&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
(original)
+++ sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundle.java
Thu May 12 14:02:26 2011
@@ -38,13 +38,15 @@ public class JcrResourceBundle extends R
 
     private static final Logger log = LoggerFactory.getLogger(JcrResourceBundle.class);
 
-    private static final String JCR_PATH = "jcr:path";
+    static final String JCR_PATH = "jcr:path";
 
-    private static final String PROP_KEY = "sling:key";
+    static final String PROP_KEY = "sling:key";
 
-    private static final String PROP_VALUE = "sling:message";
+    static final String PROP_VALUE = "sling:message";
 
-    private static final String PROP_BASENAME = "sling:basename";
+    static final String PROP_BASENAME = "sling:basename";
+
+    static final String PROP_LANGUAGE = "jcr:language";
 
     private final HashMap<String, Object> resources;
 

Modified: sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java?rev=1102314&r1=1102313&r2=1102314&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
(original)
+++ sling/trunk/contrib/extensions/i18n/src/main/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider.java
Thu May 12 14:02:26 2011
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -34,10 +35,10 @@ import javax.jcr.Session;
 import javax.jcr.observation.EventIterator;
 import javax.jcr.observation.EventListener;
 import javax.jcr.observation.ObservationManager;
+import javax.jcr.query.Query;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.PropertyUnbounded;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.ReferencePolicy;
@@ -53,6 +54,8 @@ import org.osgi.service.component.Compon
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.sling.i18n.impl.JcrResourceBundle.*;
+
 /**
  * The <code>JcrResourceBundleProvider</code> implements the
  * <code>ResourceBundleProvider</code> interface creating
@@ -72,9 +75,6 @@ public class JcrResourceBundleProvider i
 
     @Property(value = "en")
     private static final String PROP_DEFAULT_LOCALE = "locale.default";
-    
-    @Property(value = "en", unbounded = PropertyUnbounded.ARRAY)
-    private static final String PROP_PRELOAD_BUNDLES = "preload.bundles";
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
@@ -119,8 +119,6 @@ public class JcrResourceBundleProvider i
     private BundleContext bundleContext;
     
     private List<ServiceRegistration> bundleServiceRegistrations;
-    
-    private String[] preloadBundles;
 
     // ---------- ResourceBundleProvider ---------------------------------------
 
@@ -198,7 +196,6 @@ public class JcrResourceBundleProvider i
         String localeString = OsgiUtil.toString(props.get(PROP_DEFAULT_LOCALE),
             null);
         this.defaultLocale = toLocale(localeString);
-        this.preloadBundles = OsgiUtil.toStringArray(props.get(PROP_PRELOAD_BUNDLES));
 
         this.bundleContext = context.getBundleContext();
         this.bundleServiceRegistrations = new ArrayList<ServiceRegistration>();
@@ -268,7 +265,7 @@ public class JcrResourceBundleProvider i
                             });
             } else {
                 synchronized (this) {
-                    Dictionary serviceProps = new Hashtable();
+                    Dictionary<Object, Object> serviceProps = new Hashtable<Object,
Object>();
                     if (key.baseName != null) {
                         serviceProps.put("baseName", key.baseName);
                     }
@@ -418,7 +415,6 @@ public class JcrResourceBundleProvider i
     
     private void clearCache() {
         resourceBundleCache.clear();
-        resourceBundleCache.clear();
         synchronized (this) {
             for (ServiceRegistration serviceReg : bundleServiceRegistrations) {
                 serviceReg.unregister();
@@ -428,15 +424,16 @@ public class JcrResourceBundleProvider i
     }
     
     private void preloadBundles() {
-        if (preloadBundles != null) {
-            for (String bundleSpec : preloadBundles) {
-                int idx = bundleSpec.indexOf("|");
-                if (idx > -1) {
-                    String baseName = bundleSpec.substring(0, idx);
-                    Locale locale = toLocale(bundleSpec.substring(idx + 1));
-                    getResourceBundle(baseName, locale);
+        @SuppressWarnings("deprecation")
+        Iterator<Map<String, Object>> bundles = getResourceResolver().queryResources(
+                "//element(*,mix:language)", Query.XPATH);
+        while (bundles.hasNext()) {
+            Map<String,Object> bundle = bundles.next();
+            if (bundle.containsKey(PROP_LANGUAGE)) {
+                Locale locale = toLocale(bundle.get(PROP_LANGUAGE).toString());
+                if (bundle.containsKey(PROP_BASENAME)) {
+                    getResourceBundle(bundle.get(PROP_BASENAME).toString(), locale);
                 } else {
-                    Locale locale = toLocale(bundleSpec);
                     getResourceBundle(locale);
                 }
             }

Modified: sling/trunk/contrib/extensions/i18n/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1102314&r1=1102313&r2=1102314&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/contrib/extensions/i18n/src/main/resources/OSGI-INF/metatype/metatype.properties
Thu May 12 14:02:26 2011
@@ -37,7 +37,3 @@ locale.default.name = Default Locale
 locale.default.description = The default locale to assume if none can be \
  resolved otherwise. This value must be in the form acceptable to the \
  java.util.Locale class.
-
-preload.bundles.name = Bundles to Preload
-preload.bundles.description = A list of resource bundles which should be pre-loaded \
- automatically on startup or when a content change is detected.



Mime
View raw message