[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Gavin King gavin.king at jboss.com
Mon Oct 30 21:21:19 EST 2006


  User: gavin   
  Date: 06/10/30 21:21:19

  Modified:    src/main/org/jboss/seam/core   Pages.java
                        ResourceBundle.java
  Log:
  page-scoped resource bundles
  
  Revision  Changes    Path
  1.38      +26 -0     jboss-seam/src/main/org/jboss/seam/core/Pages.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Pages.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Pages.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -b -r1.37 -r1.38
  --- Pages.java	27 Oct 2006 12:58:09 -0000	1.37
  +++ Pages.java	31 Oct 2006 02:21:19 -0000	1.38
  @@ -9,6 +9,7 @@
   import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
  +import java.util.MissingResourceException;
   import java.util.Set;
   import java.util.SortedSet;
   import java.util.TreeSet;
  @@ -67,8 +68,25 @@
         MethodBinding action;
         String outcome;
         String noConversationViewId;
  +      String resourceBundleName;
         List<PageParameter> pageParameters = new ArrayList<PageParameter>();
         
  +      java.util.ResourceBundle getResourceBundle()
  +      {
  +         try
  +         {
  +            return java.util.ResourceBundle.getBundle(
  +                  resourceBundleName, 
  +                  Locale.instance(), 
  +                  Thread.currentThread().getContextClassLoader()
  +               );
  +         }
  +         catch (MissingResourceException mre)
  +         {
  +            return null;
  +         }
  +      }
  +      
         @Override
         public String toString()
         {
  @@ -183,6 +201,9 @@
                  }
               }
               
  +            String bundle = page.attributeValue("bundle");
  +            entry.resourceBundleName = bundle==null ? viewId.substring(1, viewId.indexOf('.')) : bundle;
  +            
               List<Element> children = page.elements("param");
               for (Element param: children)
               {
  @@ -303,6 +324,11 @@
         }
      }
      
  +   public java.util.ResourceBundle getResourceBundle(String viewId)
  +   {
  +      return getPage(viewId).getResourceBundle();
  +   }
  +   
      public static Pages instance()
      {
         if ( !Contexts.isApplicationContextActive() )
  
  
  
  1.16      +27 -0     jboss-seam/src/main/org/jboss/seam/core/ResourceBundle.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ResourceBundle.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ResourceBundle.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- ResourceBundle.java	25 Oct 2006 15:14:35 -0000	1.15
  +++ ResourceBundle.java	31 Oct 2006 02:21:19 -0000	1.16
  @@ -8,6 +8,9 @@
   import java.util.List;
   import java.util.MissingResourceException;
   
  +import javax.faces.component.UIViewRoot;
  +import javax.faces.context.FacesContext;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.seam.Component;
  @@ -113,6 +116,29 @@
                  @Override
                  protected Object handleGetObject(String key)
                  {
  +                  FacesContext facesContext = FacesContext.getCurrentInstance();
  +                  if (facesContext!=null)
  +                  {
  +                     UIViewRoot viewRoot = facesContext.getViewRoot();
  +                     if (viewRoot!=null)
  +                     {
  +                        String viewId = viewRoot.getViewId();
  +                        if (viewId!=null)
  +                        {
  +                           java.util.ResourceBundle pageBundle = Pages.instance().getResourceBundle(viewId);
  +                           if (pageBundle!=null)
  +                           {
  +                              try
  +                              {
  +                                 return pageBundle.getObject(key);
  +                              }
  +                              catch (MissingResourceException mre) {}
  +                           
  +                           }
  +                        }
  +                     }
  +                  }
  +                  
                     for (java.util.ResourceBundle littleBundle: littleBundles)
                     {
                        if (littleBundle!=null)
  @@ -124,6 +150,7 @@
                           catch (MissingResourceException mre) {}
                        }
                     }
  +                  
                     throw new MissingResourceException("Can't find resource in bundles: " + key, getClass().getName(), key );
                  }
                  
  
  
  



More information about the jboss-cvs-commits mailing list