[seam-commits] Seam SVN: r7594 - in trunk/src/main/org/jboss/seam: navigation and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Mar 17 19:04:00 EDT 2008


Author: norman.richards at jboss.com
Date: 2008-03-17 19:03:59 -0400 (Mon, 17 Mar 2008)
New Revision: 7594

Added:
   trunk/src/main/org/jboss/seam/navigation/Header.java
Modified:
   trunk/src/main/org/jboss/seam/navigation/Page.java
   trunk/src/main/org/jboss/seam/navigation/Pages.java
   trunk/src/main/org/jboss/seam/pages-2.1.xsd
Log:
JBSEAM-273

Added: trunk/src/main/org/jboss/seam/navigation/Header.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Header.java	                        (rev 0)
+++ trunk/src/main/org/jboss/seam/navigation/Header.java	2008-03-17 23:03:59 UTC (rev 7594)
@@ -0,0 +1,41 @@
+package org.jboss.seam.navigation;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.seam.core.Expressions.ValueExpression;
+
+public class Header {
+    public String name;
+    public ValueExpression<Object> expression;
+    
+    public String getName() {
+        return name;
+    }
+    public void setName(String name) {
+        this.name = name;
+    }
+    public ValueExpression<Object> getValue() {
+        return expression;
+    }
+    public void setValue(ValueExpression<Object> valueExpression) {
+        this.expression = valueExpression;
+    }
+    
+    public void sendHeader(HttpServletResponse response) {
+        response.addHeader(name, evaluateValue());
+    }
+    
+    private String evaluateValue() {
+        String result = "";
+        
+        if (expression != null) {
+            Object value = expression.getValue();
+       
+            if (value != null) {
+                result = value.toString(); 
+            }
+        }
+        
+        return result;
+    }
+}

Modified: trunk/src/main/org/jboss/seam/navigation/Page.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Page.java	2008-03-15 22:54:06 UTC (rev 7593)
+++ trunk/src/main/org/jboss/seam/navigation/Page.java	2008-03-17 23:03:59 UTC (rev 7594)
@@ -7,6 +7,7 @@
 
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpServletResponse;
 
 import org.jboss.seam.core.Events;
 import org.jboss.seam.core.Interpolator;
@@ -39,6 +40,7 @@
    private ConversationIdParameter conversationIdParameter;
    private String eventType;
    private List<Pattern> rewritePatterns = new ArrayList<Pattern>();
+   private List<Header> httpHeaders = new ArrayList<Header>();
    
    /**
     * The scheme (http/https) required by this page.
@@ -238,6 +240,8 @@
    public boolean preRender(FacesContext facesContext)
    {
       checkPermission(facesContext, "render");     
+     
+      sendHeaders(facesContext);
       
       boolean result = false;
       
@@ -283,6 +287,19 @@
       
       return result;
    }
+
+    private void sendHeaders(FacesContext facesContext) {
+        Object value = facesContext.getExternalContext().getResponse();
+        
+        if (value == null || !(value instanceof HttpServletResponse)) {
+            return;
+        }
+        
+        HttpServletResponse response = (HttpServletResponse) value;
+        for (Header header: httpHeaders) {
+            header.sendHeader(response);
+        }
+    }
    
    public List<Input> getInputs()
    {
@@ -378,4 +395,8 @@
         return id;
     }
 
+    public List<Header> getHeaders() {
+        return httpHeaders;
+    }
+
 }

Modified: trunk/src/main/org/jboss/seam/navigation/Pages.java
===================================================================
--- trunk/src/main/org/jboss/seam/navigation/Pages.java	2008-03-15 22:54:06 UTC (rev 7593)
+++ trunk/src/main/org/jboss/seam/navigation/Pages.java	2008-03-17 23:03:59 UTC (rev 7594)
@@ -1019,6 +1019,11 @@
          String expr = restrict.getTextTrim();
          if ( !Strings.isEmpty(expr) ) page.setRestriction(expr);
       }
+      
+      List<Element> headers = element.elements("header");
+      for (Element header: headers) {
+         page.getHeaders().add(parseHeader(header));
+      }
    }
    
    public ConversationIdParameter getConversationIdParameter(String conversationName)
@@ -1343,6 +1348,22 @@
       return param;
    }
    
+   private static Header parseHeader(Element element)
+   {
+       Header header = new Header();
+
+       String name = element.attributeValue("name");
+       header.setName(name);
+
+       String valueExpression = element.attributeValue("value");
+       if (valueExpression==null) {
+           valueExpression = element.getTextTrim();
+       }
+       header.setValue(Expressions.instance().createValueExpression(valueExpression));
+
+       return header;
+   }
+   
    /**
     * Parse rule
     */

Modified: trunk/src/main/org/jboss/seam/pages-2.1.xsd
===================================================================
--- trunk/src/main/org/jboss/seam/pages-2.1.xsd	2008-03-15 22:54:06 UTC (rev 7593)
+++ trunk/src/main/org/jboss/seam/pages-2.1.xsd	2008-03-17 23:03:59 UTC (rev 7594)
@@ -52,6 +52,7 @@
                 <xs:element ref="pages:restrict"/>
                 <xs:element ref="pages:description"/>
                 <xs:element ref="pages:param"/>
+                <xs:element ref="pages:header" />
                 <xs:element ref="pages:begin-conversation"/>
                 <xs:element ref="pages:end-conversation"/>
                 <xs:element ref="pages:start-task"/>
@@ -105,6 +106,7 @@
             <xs:attributeGroup ref="pages:attlist.param"/>
         </xs:complexType>
     </xs:element>
+
     <xs:attributeGroup name="attlist.param">
         <xs:attribute name="name"/>
         <xs:attribute name="value"/>
@@ -114,6 +116,18 @@
         <xs:attribute name="validatorId"/>
         <xs:attribute name="required" type="xs:boolean"/>
     </xs:attributeGroup>
+    
+    <xs:element name="header">
+        <xs:complexType mixed="true">
+            <xs:attributeGroup ref="pages:attlist.header"/>
+        </xs:complexType>
+    </xs:element>
+    
+    <xs:attributeGroup name="attlist.header">
+        <xs:attribute name="name" use="required"/>
+        <xs:attribute name="value" />
+    </xs:attributeGroup>
+    
     <xs:element name="action">
         <xs:complexType>
             <xs:attributeGroup ref="pages:attlist.action"/>




More information about the seam-commits mailing list