[jboss-cvs] jboss-seam/src/main/org/jboss/seam/mock ...
Peter Muir
peter at bleepbleep.org.uk
Thu Mar 1 11:21:15 EST 2007
User: pmuir
Date: 07/03/01 11:21:15
Modified: src/main/org/jboss/seam/mock MockFacesContext.java
Log:
JBSEAM-892 (JSF 1.1)
Revision Changes Path
1.12 +231 -189 jboss-seam/src/main/org/jboss/seam/mock/MockFacesContext.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: MockFacesContext.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/mock/MockFacesContext.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- MockFacesContext.java 12 Feb 2007 17:36:20 -0000 1.11
+++ MockFacesContext.java 1 Mar 2007 16:21:15 -0000 1.12
@@ -1,9 +1,7 @@
/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
+ * * JBoss, Home of Professional Open Source * * Distributable under LGPL
+ * license. * See terms of license at gnu.org.
+ */
package org.jboss.seam.mock;
import java.util.ArrayList;
@@ -12,7 +10,10 @@
import java.util.List;
import java.util.Map;
+import javax.el.ELContext;
+import javax.faces.FactoryFinder;
import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIViewRoot;
@@ -21,26 +22,46 @@
import javax.faces.context.ResponseStream;
import javax.faces.context.ResponseWriter;
import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+
+import com.sun.facelets.el.LegacyELContext;
/**
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.11 $
+ * @version $Revision: 1.12 $
*/
public class MockFacesContext extends FacesContext
{
private UIViewRoot viewRoot;// = new UIViewRoot();
+
private Map<FacesMessage, String> messages = new HashMap<FacesMessage, String>();
+
private ExternalContext externalContext;
+
private ResponseWriter responseWriter;
+ private RenderKitFactory renderKitFactory;
+
+ private ELContext elContext;
+
public MockFacesContext(ExternalContext externalContext, Application application)
{
this.externalContext = externalContext;
this.application = application;
}
+ // Create a MockFacesContext using a ApplicationFactory to get the Application
+ public MockFacesContext(ExternalContext externalContext)
+ {
+ application = ((ApplicationFactory) FactoryFinder
+ .getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
+ renderKitFactory = (RenderKitFactory) FactoryFinder
+ .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+ this.externalContext = externalContext;
+ }
+
private Application application;
@Override
@@ -65,9 +86,9 @@
public Severity getMaximumSeverity()
{
Severity max = null;
- for (FacesMessage msg: messages.keySet())
+ for (FacesMessage msg : messages.keySet())
{
- if (max==null || msg.getSeverity().compareTo(max)>0)
+ if (max == null || msg.getSeverity().compareTo(max) > 0)
{
max = msg.getSeverity();
}
@@ -85,11 +106,11 @@
public Iterator getMessages(String clientId)
{
List list = new ArrayList();
- for (Map.Entry<FacesMessage, String> entry: messages.entrySet())
+ for (Map.Entry<FacesMessage, String> entry : messages.entrySet())
{
- if ( clientId.equals( entry.getValue() ) )
+ if (clientId.equals(entry.getValue()))
{
- list.add( entry.getKey() );
+ list.add(entry.getKey());
}
}
return list.iterator();
@@ -98,8 +119,15 @@
@Override
public RenderKit getRenderKit()
{
+ if (getViewRoot() == null || getViewRoot().getRenderKitId() == null)
+ {
return MockRenderKit.INSTANCE;
}
+ else
+ {
+ return renderKitFactory.getRenderKit(this, getViewRoot().getRenderKitId());
+ }
+ }
private boolean renderResponse;
@@ -160,7 +188,9 @@
}
@Override
- public void release() {}
+ public void release()
+ {
+ }
@Override
public void renderResponse()
@@ -183,7 +213,19 @@
public MockFacesContext createViewRoot()
{
viewRoot = new UIViewRoot();
+ viewRoot.setRenderKitId(getApplication().getViewHandler().calculateRenderKitId(this));
return this;
}
+
+ // JSF 1.2 only
+ public ELContext getELContext() {
+ // TODO Does this work on JSF 1.2?
+ if (elContext == null)
+ {
+ elContext = new LegacyELContext(this);
+ }
+ return elContext;
+ }
+
}
More information about the jboss-cvs-commits
mailing list