From seam-commits at lists.jboss.org Thu May 27 21:36:22 2010 Content-Type: multipart/mixed; boundary="===============8212440959197845881==" MIME-Version: 1.0 From: seam-commits at lists.jboss.org To: seam-commits at lists.jboss.org Subject: [seam-commits] Seam SVN: r12878 - in modules/faces/trunk: impl/src/main/java/org/jboss/seam/faces/environment and 1 other directory. Date: Thu, 27 May 2010 21:36:21 -0400 Message-ID: <201005280136.o4S1aLJD006868@svn01.web.mwc.hst.phx2.redhat.com> --===============8212440959197845881== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: lincolnthree Date: 2010-05-27 21:36:21 -0400 (Thu, 27 May 2010) New Revision: 12878 Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/Flash= Context.java modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/= SeamExternalContext.java modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/= SeamExternalContextFactory.java Log: First stab at real FlashScope implementation #2 Added: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/F= lashContext.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/Flas= hContext.java (rev 0) +++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/context/Flas= hContext.java 2010-05-28 01:36:21 UTC (rev 12878) @@ -0,0 +1,55 @@ +/* + * 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.jboss.seam.faces.context; + +/** + * A context that lives from Restore View to the next Render Response. + * = + * @author Lincoln Baxter, III= + * = + */ +public interface FlashContext +{ + + /** + * Returns true if the current {@link FlashContext} contains no data. + */ + boolean isEmpty(); + + /** + * Return the current ID of this request's {@link FlashContext}. If the= ID + * has not yet been set as part of a redirect, the ID will be null. + */ + String getId(); + + /** + * Get a key value pair from the {@link FlashContext}. + */ + Object get(String key); + + /** + * Put a key value pair into the {@link FlashContext}. + */ + void put(String key, Object value); + +} Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environm= ent/SeamExternalContext.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment= /SeamExternalContext.java (rev 0) +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment= /SeamExternalContext.java 2010-05-28 01:36:21 UTC (rev 12878) @@ -0,0 +1,51 @@ +package org.jboss.seam.faces.environment; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.enterprise.context.RequestScoped; +import javax.faces.context.ExternalContext; +import javax.faces.context.ExternalContextWrapper; +import javax.inject.Inject; + +import org.jboss.seam.faces.context.FlashContext; +import org.jboss.seam.faces.context.FlashScopedContext; + +(a)RequestScoped +public class SeamExternalContext extends ExternalContextWrapper +{ + private ExternalContext wrapped; + + @Inject + FlashContext flash; + + @Inject + FlashScopedContext context; + + public void setWrapped(final ExternalContext wrapped) + { + this.wrapped =3D wrapped; + } + + @Override + public ExternalContext getWrapped() + { + return wrapped; + } + + @Override + public String encodeRedirectURL(final String baseUrl, Map> parameters) + { + if (!flash.isEmpty()) + { + if (parameters =3D=3D null) + { + parameters =3D new HashMap>(); + } + parameters.put(context.getRequestParameterName(), Arrays.asList(f= lash.getId())); + } + return super.encodeRedirectURL(baseUrl, parameters); + } +} Added: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environm= ent/SeamExternalContextFactory.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment= /SeamExternalContextFactory.java (rev 0) +++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment= /SeamExternalContextFactory.java 2010-05-28 01:36:21 UTC (rev 12878) @@ -0,0 +1,44 @@ +package org.jboss.seam.faces.environment; + +import javax.enterprise.inject.spi.BeanManager; +import javax.faces.FacesException; +import javax.faces.context.ExternalContext; +import javax.faces.context.ExternalContextFactory; + +import org.jboss.seam.faces.util.BeanManagerUtils; +import org.jboss.weld.extensions.beanManager.BeanManagerAccessor; + +public class SeamExternalContextFactory extends ExternalContextFactory +{ + private final ExternalContextFactory parent; + + public SeamExternalContextFactory(final ExternalContextFactory parent) + { + super(); + this.parent =3D parent; + } + + @Override + public ExternalContext getExternalContext(final Object context, final O= bject request, final Object response) throws FacesException + { + try + { + BeanManager manager =3D BeanManagerAccessor.getManager(); + + SeamExternalContext seamExternalContext =3D BeanManagerUtils.getC= ontextualInstance(manager, SeamExternalContext.class); + seamExternalContext.setWrapped(parent.getExternalContext(context,= request, response)); + + return seamExternalContext; + } + catch (Exception e) + { + throw new IllegalStateException("Could not wrap ExternalContext",= e); + } + } + + @Override + public ExternalContextFactory getWrapped() + { + return parent; + } +} --===============8212440959197845881==--