[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Gavin King
gavin.king at jboss.com
Sun Nov 26 22:00:15 EST 2006
User: gavin
Date: 06/11/26 22:00:15
Modified: src/main/org/jboss/seam/core Manager.java Page.java
Pages.java ResourceBundle.java
Log:
JBSEAM-397, wildcarded view id support for page parameters, resource bundles, noconversationviewid
Revision Changes Path
1.122 +5 -5 jboss-seam/src/main/org/jboss/seam/core/Manager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Manager.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Manager.java,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -b -r1.121 -r1.122
--- Manager.java 24 Nov 2006 23:15:17 -0000 1.121
+++ Manager.java 27 Nov 2006 03:00:15 -0000 1.122
@@ -42,7 +42,7 @@
*
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.121 $
+ * @version $Revision: 1.122 $
*/
@Scope(ScopeType.EVENT)
@Name("org.jboss.seam.core.manager")
@@ -1048,9 +1048,9 @@
noConversation();
//stuff from jPDL takes precedence
- org.jboss.seam.core.FacesPage page = org.jboss.seam.core.FacesPage.instance();
- String pageflowName = page.getPageflowName();
- String pageflowNodeName = page.getPageflowNodeName();
+ org.jboss.seam.core.FacesPage facesPage = org.jboss.seam.core.FacesPage.instance();
+ String pageflowName = facesPage.getPageflowName();
+ String pageflowNodeName = facesPage.getPageflowNodeName();
String noConversationViewId = null;
if (pageflowName==null || pageflowNodeName==null)
@@ -1059,7 +1059,7 @@
Pages pages = Pages.instance();
if (pages!=null) //for tests
{
- noConversationViewId = pages.getPage(viewId).getNoConversationViewId();
+ noConversationViewId = pages.getNoConversationViewId(viewId);
}
}
else
1.5 +2 -4 jboss-seam/src/main/org/jboss/seam/core/Page.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Page.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Page.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- Page.java 20 Nov 2006 20:31:16 -0000 1.4
+++ Page.java 27 Nov 2006 03:00:15 -0000 1.5
@@ -113,7 +113,7 @@
int loc = viewId.lastIndexOf('.');
if ( loc>0 && viewId.startsWith("/") )
{
- this.setResourceBundleName(viewId.substring(1, loc));
+ this.setResourceBundleName( viewId.substring(1, loc) );
}
}
}
@@ -197,9 +197,7 @@
public String getNoConversationViewId()
{
- return noConversationViewId==null ?
- Pages.instance().getNoConversationViewId() :
- noConversationViewId;
+ return noConversationViewId;
}
public void setResourceBundleName(String resourceBundleName)
1.54 +140 -69 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.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- Pages.java 24 Nov 2006 23:51:22 -0000 1.53
+++ Pages.java 27 Nov 2006 03:00:15 -0000 1.54
@@ -4,11 +4,13 @@
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.ResourceBundle;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -53,6 +55,7 @@
private static final Log log = LogFactory.getLog(Pages.class);
private Map<String, Page> pagesByViewId = Collections.synchronizedMap( new HashMap<String, Page>() );
+ private Map<String, List<Page>> pageStacksByViewId = Collections.synchronizedMap( new HashMap<String, List<Page>>() );
private String noConversationViewId;
private SortedSet<String> wildcardViewIds = new TreeSet<String>(
@@ -274,30 +277,53 @@
return loc<0 ? null : viewId.substring(0, loc) + suffix;
}
- public boolean callAction()
+ protected List<Page> getPageStack(String viewId)
{
- boolean result = false;
- FacesContext facesContext = FacesContext.getCurrentInstance();
- String viewId = facesContext.getViewRoot().getViewId();
+ List<Page> stack = pageStacksByViewId.get(viewId);
+ if (stack==null)
+ {
+ stack = createPageStack(viewId);
+ pageStacksByViewId.put(viewId, stack);
+ }
+ return stack;
+ }
+
+ private List<Page> createPageStack(String viewId)
+ {
+ List<Page> stack = new ArrayList<Page>(1);
if (viewId!=null)
{
for (String wildcard: wildcardViewIds)
{
if ( viewId.startsWith( wildcard.substring(0, wildcard.length()-1) ) )
{
- result = callAction(facesContext, wildcard) || result;
+ stack.add( getPage(wildcard) );
+ }
}
}
+ Page page = getPage(viewId);
+ if (page!=null) stack.add(page);
+ return stack;
+ }
+
+ /**
+ * Call page actions, from most general view id to most specific
+ */
+ public boolean callActions(FacesContext facesContext)
+ {
+ boolean result = false;
+ String viewId = facesContext.getViewRoot().getViewId();
+ for ( Page page: getPageStack(viewId) )
+ {
+ result = callAction(page, facesContext) || result;
}
- result = callAction(facesContext, viewId) || result;
return result;
}
- private boolean callAction(FacesContext facesContext, String viewId)
+ private boolean callAction(Page page, FacesContext facesContext)
{
boolean result = false;
- Page page = getPage(viewId);
page.beginOrEndConversation();
String outcome = page.getOutcome();
@@ -375,15 +401,34 @@
return result;
}
+ /**
+ * Build a list of page-scoped resource bundles, from most
+ * specific view id, to most general.
+ */
+ public List<ResourceBundle> getResourceBundles(String viewId)
+ {
+ List<ResourceBundle> result = new ArrayList<ResourceBundle>(1);
+ List<Page> stack = getPageStack(viewId);
+ for (int i=stack.size()-1; i>=0; i++)
+ {
+ Page page = stack.get(i);
+ ResourceBundle bundle = page.getResourceBundle();
+ if ( bundle!=null ) result.add(bundle);
+ }
+ return result;
+ }
+
public Map<String, Object> getConvertedParameters(FacesContext facesContext, String viewId)
{
return getConvertedParameters(facesContext, viewId, Collections.EMPTY_SET);
}
- public Map<String, Object> getParameters(String viewId)
+ protected Map<String, Object> getParameters(String viewId)
{
Map<String, Object> parameters = new HashMap<String, Object>();
- for ( Page.PageParameter pageParameter: getPage(viewId).getPageParameters() )
+ for ( Page page: getPageStack(viewId) )
+ {
+ for ( Page.PageParameter pageParameter: page.getPageParameters() )
{
Object value = pageParameter.getValueBinding().getValue();
if (value!=null)
@@ -391,13 +436,16 @@
parameters.put(pageParameter.getName(), value);
}
}
+ }
return parameters;
}
public Map<String, Object> getConvertedParameters(FacesContext facesContext, String viewId, Set<String> overridden)
{
Map<String, Object> parameters = new HashMap<String, Object>();
- for ( Page.PageParameter pageParameter: getPage(viewId).getPageParameters() )
+ for ( Page page: getPageStack(viewId) )
+ {
+ for ( Page.PageParameter pageParameter: page.getPageParameters() )
{
if ( !overridden.contains(pageParameter.getName()) )
{
@@ -420,6 +468,7 @@
}
}
}
+ }
return parameters;
}
@@ -427,7 +476,9 @@
{
String viewId = facesContext.getViewRoot().getViewId();
Map<String, String[]> requestParameters = Parameters.getRequestParameters();
- for ( Page.PageParameter pageParameter: getPage(viewId).getPageParameters() )
+ for ( Page page: getPageStack(viewId) )
+ {
+ for ( Page.PageParameter pageParameter: page.getPageParameters() )
{
String[] parameterValues = requestParameters.get(pageParameter.getName());
if (parameterValues==null || parameterValues.length==0)
@@ -457,12 +508,14 @@
pageParameter.getValueBinding().setValue(value);
}
}
+ }
public void applyViewRootValues(FacesContext facesContext)
{
String viewId = facesContext.getViewRoot().getViewId();
-
- for (Page.PageParameter pageParameter: getPage(viewId).getPageParameters())
+ for ( Page page: getPageStack(viewId) )
+ {
+ for ( Page.PageParameter pageParameter: page.getPageParameters() )
{
Object object = Contexts.getPageContext().get(pageParameter.getName());
if (object!=null)
@@ -471,6 +524,7 @@
}
}
}
+ }
public String getNoConversationViewId()
{
@@ -489,9 +543,9 @@
* @param viewId the JSF view id of the page
* @return the URL with parameters appended
*/
- public String encodePageParameters(String url, String viewId)
+ public String encodePageParameters(FacesContext facesContext, String url, String viewId)
{
- Map<String, Object> parameters = getConvertedParameters( FacesContext.getCurrentInstance(), viewId );
+ Map<String, Object> parameters = getConvertedParameters(facesContext, viewId);
return Manager.instance().encodeParameters(url, parameters);
}
@@ -501,13 +555,30 @@
public void storePageParameters(FacesContext facesContext)
{
String viewId = facesContext.getViewRoot().getViewId();
- if (viewId!=null)
- {
for ( Map.Entry<String, Object> param: getParameters(viewId).entrySet() )
{
Contexts.getPageContext().set( param.getKey(), param.getValue() );
}
}
+
+ /**
+ * Search for a defined no-conversation-view-id, beginning with
+ * the most specific view id, then wildcarded view ids, and
+ * finally the global setting
+ */
+ public String getNoConversationViewId(String viewId)
+ {
+ List<Page> stack = getPageStack(viewId);
+ for (int i=stack.size()-1; i>=0; i++)
+ {
+ Page page = stack.get(i);
+ String noConversationViewId = page.getNoConversationViewId();
+ if (noConversationViewId!=null)
+ {
+ return noConversationViewId;
+ }
+ }
+ return this.noConversationViewId;
}
public static String getSuffix()
1.23 +10 -18 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.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- ResourceBundle.java 24 Nov 2006 23:15:17 -0000 1.22
+++ ResourceBundle.java 27 Nov 2006 03:00:15 -0000 1.23
@@ -5,6 +5,7 @@
import java.io.Serializable;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.MissingResourceException;
@@ -117,17 +118,12 @@
@Override
public Enumeration<String> getKeys()
{
- int size = littleBundles.size();
- java.util.ResourceBundle pageBundle = getPageResourceBundle();
- if (pageBundle!=null)
- {
- ++size;
- }
- Enumeration<String>[] enumerations = new Enumeration[ littleBundles.size() + 1 ];
+ List<java.util.ResourceBundle> pageBundles = getPageResourceBundles();
+ Enumeration<String>[] enumerations = new Enumeration[ littleBundles.size() + pageBundles.size() ];
int i=0;
- if (pageBundle!=null)
+ for (; i<pageBundles.size(); i++)
{
- enumerations[i++] = pageBundle.getKeys();
+ enumerations[i++] = pageBundles.get(i).getKeys();
}
for (; i<littleBundles.size(); i++)
{
@@ -139,8 +135,8 @@
@Override
protected Object handleGetObject(String key)
{
- java.util.ResourceBundle pageBundle = getPageResourceBundle();
- if (pageBundle!=null)
+ List<java.util.ResourceBundle> pageBundles = getPageResourceBundles();
+ for (java.util.ResourceBundle pageBundle: pageBundles)
{
try
{
@@ -164,7 +160,7 @@
throw new MissingResourceException("Can't find resource in bundles: " + key, getClass().getName(), key );
}
- private java.util.ResourceBundle getPageResourceBundle()
+ private List<java.util.ResourceBundle> getPageResourceBundles()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext!=null)
@@ -172,14 +168,10 @@
UIViewRoot viewRoot = facesContext.getViewRoot();
if (viewRoot!=null)
{
- String viewId = viewRoot.getViewId();
- if (viewId!=null)
- {
- return Pages.instance().getPage(viewId).getResourceBundle();
+ return Pages.instance().getResourceBundles( viewRoot.getViewId() );
}
}
- }
- return null;
+ return Collections.EMPTY_LIST;
}
};
More information about the jboss-cvs-commits
mailing list