[richfaces-svn-commits] JBoss Rich Faces SVN: r19012 - in branches/RFPL-434/core: commons/src/main/java/org/richfaces/l10n and 3 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Aug 30 09:04:18 EDT 2010


Author: nbelaevski
Date: 2010-08-30 09:04:17 -0400 (Mon, 30 Aug 2010)
New Revision: 19012

Added:
   branches/RFPL-434/core/api/src/main/java/org/richfaces/application/MessageFactory.java
   branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java
Removed:
   branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageFactory.java
   branches/RFPL-434/core/commons/src/test/java/org/richfaces/l10n/BundleLoaderAppMessages.java
Modified:
   branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/BundleLoader.java
   branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageBundle.java
   branches/RFPL-434/core/commons/src/main/java/org/richfaces/log/CoreMessages.java
   branches/RFPL-434/core/commons/src/main/java/org/richfaces/log/FacesMessages.java
   branches/RFPL-434/core/commons/src/test/java/org/richfaces/l10n/BundleLoaderTest.java
   branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/DefaultModule.java
Log:
https://jira.jboss.org/browse/RFPL-434

Added: branches/RFPL-434/core/api/src/main/java/org/richfaces/application/MessageFactory.java
===================================================================
--- branches/RFPL-434/core/api/src/main/java/org/richfaces/application/MessageFactory.java	                        (rev 0)
+++ branches/RFPL-434/core/api/src/main/java/org/richfaces/application/MessageFactory.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.application;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public interface MessageFactory {
+
+    public FacesMessage createMessage(FacesContext facesContext, Enum<?> messageKey, Object... args);
+
+    public FacesMessage createMessage(FacesContext facesContext, Severity severity, Enum<?> messageKey, Object... args);
+
+}

Modified: branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/BundleLoader.java
===================================================================
--- branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/BundleLoader.java	2010-08-30 13:02:12 UTC (rev 19011)
+++ branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/BundleLoader.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -59,19 +59,12 @@
     }
 
     public ResourceBundle getApplicationBundle(FacesContext facesContext, Enum<?> messageKey, Locale locale)
-        throws MissingResourceException, IllegalArgumentException  {
+        throws MissingResourceException {
         
-        MessageBundle messageBundle = asMessageBundle(messageKey);
-        
         if (facesContext == null) {
             throw new MissingResourceException("FacesContext is null", getClass().getName(), messageKey.toString());
         }
 
-        if (!messageBundle.useApplicationBundle()) {
-            throw new MissingResourceException("MessageBundle annotation doesn't declare application bundle as used", 
-                getClass().getName(), messageKey.toString());
-        }
-        
         Application application = facesContext.getApplication();
         
         if (application == null || application.getMessageBundle() == null) {

Modified: branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageBundle.java
===================================================================
--- branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageBundle.java	2010-08-30 13:02:12 UTC (rev 19011)
+++ branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageBundle.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -36,6 +36,4 @@
 
     public String baseName(); 
     
-    public boolean useApplicationBundle() default false;
-    
 }

Deleted: branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageFactory.java
===================================================================
--- branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageFactory.java	2010-08-30 13:02:12 UTC (rev 19011)
+++ branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageFactory.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -1,138 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.l10n;
-
-import java.text.MessageFormat;
-import java.util.Locale;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.application.FacesMessage.Severity;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Nick Belaevski
- * 
- */
-public class MessageFactory {
-
-    private BundleLoader bundleLoader;
-
-    public MessageFactory(BundleLoader bundleLoader) {
-        super();
-        this.bundleLoader = bundleLoader;
-    }
-
-    private Locale detectLocale(FacesContext context) {
-        UIViewRoot viewRoot = context.getViewRoot();
-        if (viewRoot != null && viewRoot.getLocale() != null) {
-            return viewRoot.getLocale();
-        }
-
-        return null;
-    }
-
-    public FacesMessage createMessage(FacesContext facesContext, Enum<?> messageKey, Object... args) {
-        return createMessage(facesContext, FacesMessage.SEVERITY_INFO, messageKey, args);
-    }
-
-    public FacesMessage createMessage(FacesContext facesContext, Severity severity, Enum<?> messageKey, Object... args) {
-        if (facesContext == null) {
-            throw new NullPointerException("context");
-        }
-        
-        if (severity == null) {
-            throw new NullPointerException("severity");
-        }
-        
-        if (messageKey == null) {
-            throw new NullPointerException("messageKey");
-        }
-        
-        FacesMessage result = null;
-
-        Locale locale = detectLocale(facesContext);
-        if (locale != null) {
-            result = createMessage(facesContext, severity, locale, messageKey, args);
-        }
-
-        if (result == null) {
-            Locale defaultLocale = Locale.getDefault();
-            
-            if (!defaultLocale.equals(locale)) {
-                result = createMessage(facesContext, severity, defaultLocale, messageKey, args);
-            }
-            
-        }
-
-        return result;
-    }
-
-    protected FacesMessage createMessage(FacesContext context, Severity severity, Locale locale, Enum<?> messageKey,
-        Object... args) {
-        
-        MessageBundle messageBundle = messageKey.getClass().getAnnotation(MessageBundle.class);
-
-        if (messageBundle == null) {
-            return null;
-        }
-
-        String messageId = messageKey.toString();
-
-        String summary = null;
-        String detail = null;
-
-        try {
-            ResourceBundle bundle = bundleLoader.getApplicationBundle(context, messageKey, locale);
-            summary = bundle.getString(messageId);
-            detail = bundle.getString(messageId + "_detail");
-        } catch (MissingResourceException e) {
-            // do nothing
-        }
-
-        if (summary == null) {
-            try {
-                ResourceBundle bundle = bundleLoader.getBundle(messageKey, locale);
-                summary = bundle.getString(messageId);
-                detail = bundle.getString(messageId + "_detail");
-            } catch (MissingResourceException e) {
-                // do nothing
-            }
-        }
-
-        if (summary == null) {
-            return null;
-        }
-        
-        String formattedSummary = MessageFormat.format(summary, args);
-        String formattedDetail = null;
-
-        if (detail != null) {
-            formattedDetail = MessageFormat.format(detail, args);
-        }
-
-        return new FacesMessage(severity, formattedSummary, formattedDetail);
-    }
-
-}

Modified: branches/RFPL-434/core/commons/src/main/java/org/richfaces/log/CoreMessages.java
===================================================================
--- branches/RFPL-434/core/commons/src/main/java/org/richfaces/log/CoreMessages.java	2010-08-30 13:02:12 UTC (rev 19011)
+++ branches/RFPL-434/core/commons/src/main/java/org/richfaces/log/CoreMessages.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -28,7 +28,7 @@
  * @author Nick Belaevski
  * 
  */
- at MessageBundle(baseName = "org.richfaces.Messages", useApplicationBundle = true)
+ at MessageBundle(baseName = "org.richfaces.Messages")
 public final class CoreMessages {
 
     private CoreMessages() {}

Modified: branches/RFPL-434/core/commons/src/main/java/org/richfaces/log/FacesMessages.java
===================================================================
--- branches/RFPL-434/core/commons/src/main/java/org/richfaces/log/FacesMessages.java	2010-08-30 13:02:12 UTC (rev 19011)
+++ branches/RFPL-434/core/commons/src/main/java/org/richfaces/log/FacesMessages.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -29,7 +29,7 @@
  * @author Nick Belaevski
  * 
  */
- at MessageBundle(baseName = FacesMessage.FACES_MESSAGES, useApplicationBundle = true)
+ at MessageBundle(baseName = FacesMessage.FACES_MESSAGES)
 public enum FacesMessages {
 
     UIINPUT_CONVERSION("javax.faces.component.UIInput.CONVERSION"),

Deleted: branches/RFPL-434/core/commons/src/test/java/org/richfaces/l10n/BundleLoaderAppMessages.java
===================================================================
--- branches/RFPL-434/core/commons/src/test/java/org/richfaces/l10n/BundleLoaderAppMessages.java	2010-08-30 13:02:12 UTC (rev 19011)
+++ branches/RFPL-434/core/commons/src/test/java/org/richfaces/l10n/BundleLoaderAppMessages.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -1,33 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.l10n;
-
-/**
- * @author Nick Belaevski
- * 
- */
- at MessageBundle(baseName = "org.richfaces.l10n.BundleLoaderMessages", useApplicationBundle = true)
-public enum BundleLoaderAppMessages {
-
-    message
-    
-}

Modified: branches/RFPL-434/core/commons/src/test/java/org/richfaces/l10n/BundleLoaderTest.java
===================================================================
--- branches/RFPL-434/core/commons/src/test/java/org/richfaces/l10n/BundleLoaderTest.java	2010-08-30 13:02:12 UTC (rev 19011)
+++ branches/RFPL-434/core/commons/src/test/java/org/richfaces/l10n/BundleLoaderTest.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -86,15 +86,15 @@
 
         assertEquals(
             "Welcome to app",
-            bundleLoader.getApplicationBundle(facesEnvironment.getFacesContext(), BundleLoaderAppMessages.message,
+            bundleLoader.getApplicationBundle(facesEnvironment.getFacesContext(), BundleLoaderCoreMessages.message,
                 Locale.US).getString("message"));
         assertEquals(
             "Dobro pozhalovat'",
-            bundleLoader.getApplicationBundle(facesEnvironment.getFacesContext(), BundleLoaderAppMessages.message,
+            bundleLoader.getApplicationBundle(facesEnvironment.getFacesContext(), BundleLoaderCoreMessages.message,
                 new Locale("by", "BY")).getString("message"));
 
         try {
-            bundleLoader.getApplicationBundle(facesEnvironment.getFacesContext(), BundleLoaderAppMessages.message,
+            bundleLoader.getApplicationBundle(facesEnvironment.getFacesContext(), BundleLoaderCoreMessages.message,
                 new Locale("ru", "RU"));
             fail();
         } catch (MissingResourceException e) {

Modified: branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/DefaultModule.java
===================================================================
--- branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/DefaultModule.java	2010-08-30 13:02:12 UTC (rev 19011)
+++ branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/DefaultModule.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -3,6 +3,7 @@
 import org.ajax4jsf.cache.Cache;
 import org.ajax4jsf.context.InitParametersStorage;
 import org.ajax4jsf.renderkit.AJAXDataSerializer;
+import org.richfaces.l10n.BundleLoader;
 import org.richfaces.resource.DefaultResourceCodec;
 import org.richfaces.resource.ResourceCodec;
 import org.richfaces.skin.SkinFactory;
@@ -18,6 +19,7 @@
         factory.setInstance(Uptime.class, new Uptime());
         factory.setInstance(DependencyInjector.class, new DependencyInjectionServiceImpl());
         factory.setInstance(InitParametersStorage.class, new InitParametersStorage());
+        factory.setInstance(MessageFactory.class, new MessageFactoryImpl(new BundleLoader()));
     }
 
 }

Copied: branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java (from rev 19010, branches/RFPL-434/core/commons/src/main/java/org/richfaces/l10n/MessageFactory.java)
===================================================================
--- branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java	                        (rev 0)
+++ branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java	2010-08-30 13:04:17 UTC (rev 19012)
@@ -0,0 +1,141 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.application;
+
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.l10n.BundleLoader;
+import org.richfaces.l10n.MessageBundle;
+
+/**
+ * @author Nick Belaevski
+ * 
+ */
+public class MessageFactoryImpl implements MessageFactory {
+
+    private BundleLoader bundleLoader;
+
+    public MessageFactoryImpl(BundleLoader bundleLoader) {
+        super();
+        this.bundleLoader = bundleLoader;
+    }
+
+    private Locale detectLocale(FacesContext context) {
+        UIViewRoot viewRoot = context.getViewRoot();
+        if (viewRoot != null && viewRoot.getLocale() != null) {
+            return viewRoot.getLocale();
+        }
+
+        return null;
+    }
+
+    public FacesMessage createMessage(FacesContext facesContext, Enum<?> messageKey, Object... args) {
+        return createMessage(facesContext, FacesMessage.SEVERITY_INFO, messageKey, args);
+    }
+
+    public FacesMessage createMessage(FacesContext facesContext, Severity severity, Enum<?> messageKey, Object... args) {
+        if (facesContext == null) {
+            throw new NullPointerException("context");
+        }
+        
+        if (severity == null) {
+            throw new NullPointerException("severity");
+        }
+        
+        if (messageKey == null) {
+            throw new NullPointerException("messageKey");
+        }
+        
+        FacesMessage result = null;
+
+        Locale locale = detectLocale(facesContext);
+        if (locale != null) {
+            result = createMessage(facesContext, severity, locale, messageKey, args);
+        }
+
+        if (result == null) {
+            Locale defaultLocale = Locale.getDefault();
+            
+            if (!defaultLocale.equals(locale)) {
+                result = createMessage(facesContext, severity, defaultLocale, messageKey, args);
+            }
+            
+        }
+
+        return result;
+    }
+
+    protected FacesMessage createMessage(FacesContext context, Severity severity, Locale locale, Enum<?> messageKey,
+        Object... args) {
+        
+        MessageBundle messageBundle = messageKey.getClass().getAnnotation(MessageBundle.class);
+
+        if (messageBundle == null) {
+            return null;
+        }
+
+        String messageId = messageKey.toString();
+
+        String summary = null;
+        String detail = null;
+
+        try {
+            ResourceBundle bundle = bundleLoader.getApplicationBundle(context, messageKey, locale);
+            summary = bundle.getString(messageId);
+            detail = bundle.getString(messageId + "_detail");
+        } catch (MissingResourceException e) {
+            // do nothing
+        }
+
+        if (summary == null) {
+            try {
+                ResourceBundle bundle = bundleLoader.getBundle(messageKey, locale);
+                summary = bundle.getString(messageId);
+                detail = bundle.getString(messageId + "_detail");
+            } catch (MissingResourceException e) {
+                // do nothing
+            }
+        }
+
+        if (summary == null) {
+            return null;
+        }
+        
+        String formattedSummary = MessageFormat.format(summary, args);
+        String formattedDetail = null;
+
+        if (detail != null) {
+            formattedDetail = MessageFormat.format(detail, args);
+        }
+
+        return new FacesMessage(severity, formattedSummary, formattedDetail);
+    }
+
+}



More information about the richfaces-svn-commits mailing list