cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java request.xsl
Date Thu, 14 Dec 2000 13:36:57 GMT
dims        00/12/14 05:36:56

  Modified:    src/org/apache/cocoon/components/language/markup/xsp Tag:
                        xml-cocoon2 XSPRequestHelper.java
               src/org/apache/cocoon/components/language/markup/xsp/java
                        Tag: xml-cocoon2 request.xsl
  Log:
  Patches for "Added getSessionAttribute to request logicsheet" from
  Lassi Immonen <limmonen@malla.urova.fi>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.6   +58 -1     xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPRequestHelper.java
  
  Index: XSPRequestHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/Attic/XSPRequestHelper.java,v
  retrieving revision 1.1.2.5
  retrieving revision 1.1.2.6
  diff -u -r1.1.2.5 -r1.1.2.6
  --- XSPRequestHelper.java	2000/08/31 16:41:59	1.1.2.5
  +++ XSPRequestHelper.java	2000/12/14 13:36:49	1.1.2.6
  @@ -10,6 +10,7 @@
   import java.util.Enumeration;
   
   import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpSession;
   
   import org.xml.sax.ContentHandler;
   import org.xml.sax.helpers.AttributesImpl;
  @@ -21,7 +22,7 @@
    * The <code>HttpServletRequest</code> object helper
    *
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.5 $ $Date: 2000/08/31 16:41:59 $
  + * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/12/14 13:36:49 $
    */
   public class XSPRequestHelper extends XSPObjectHelper {
     /**
  @@ -220,4 +221,60 @@
   
       end(contentHandler, "header-names");
     }
  +
  +  /**
  +   * Return the given session attribute value or a user-provided default if
  +   * none was specified.
  +   *
  +   * @param request The HttpServletRequest request
  +   * @param name The parameter name
  +   * @param defaultValue Value to substitute in absence of a parameter value
  +   */
  +  public static String getSessionAttribute(
  +	HttpServletRequest request, 
  +	String name, 
  +	String defaultValue) {
  + 
  +	HttpSession session = request.getSession(false);
  +	String value = null;
  +
  +	if (session != null) {
  +		value = (String) session.getAttribute(name);
  +	}
  +
  +	if (value == null) {
  +		value = defaultValue;
  +	}
  +
  +	return value;
  +  }  
  +
  +  /**
  +   * Output the given session attribute value or a user-provided default if
  +   * none was specified.
  +   *
  +   * @param request The HttpServletRequest request
  +   * @param contentHandler The SAX content handler
  +   * @param name The parameter name
  +   * @param defaultValue Value to substitute in absence of a parameter value
  +   * @exception SAXException If a SAX error occurs
  +   */
  +  public static void getSessionAttribute(
  +	HttpServletRequest request,
  +	ContentHandler contentHandler,
  +	String name,
  +	String defaultValue
  +  )
  +	throws SAXException
  +  {
  +	AttributesImpl attr = new AttributesImpl();
  +	addAttribute(attr, "name", name);
  +
  +	elementData(
  +	  contentHandler,
  +	  "attribute",
  +	  getSessionAttribute(request, name, defaultValue),
  +	  attr
  +	);
  +  }   
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.7   +38 -1     xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/request.xsl
  
  Index: request.xsl
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/components/language/markup/xsp/java/Attic/request.xsl,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- request.xsl	2000/08/31 15:52:37	1.1.2.6
  +++ request.xsl	2000/12/14 13:36:53	1.1.2.7
  @@ -11,7 +11,7 @@
   
   <!--
    * @author <a href="mailto:ricardo@apache.org>Ricardo Rocha</a>
  - * @version CVS $Revision: 1.1.2.6 $ $Date: 2000/08/31 15:52:37 $
  + * @version CVS $Revision: 1.1.2.7 $ $Date: 2000/12/14 13:36:53 $
   -->
   
   <!-- XSP Request logicsheet for the Java language -->
  @@ -39,6 +39,43 @@
   	<!-- <xsp-request:uri> -->
           <xsp:logic>
             XSPRequestHelper.getUri(request, this.contentHandler);
  +        </xsp:logic>
  +      </xsl:when>
  +    </xsl:choose>
  +  </xsl:template>
  +
  +  <xsl:template match="xsp-request:get-session-attribute">
  +    <xsl:variable name="name">
  +      <xsl:call-template name="value-for-name"/>
  +    </xsl:variable>
  +
  +	<xsl:variable name="as">
  +      <xsl:call-template name="value-for-as">
  +        <xsl:with-param name="default" select="'string'"/>
  +      </xsl:call-template>
  +    </xsl:variable>
  +
  +    <xsl:variable name="default">
  +      <xsl:choose>
  +        <xsl:when test="@default">"<xsl:value-of select="@default"/>"</xsl:when>
  +        <xsl:when test="default">
  +          <xsl:call-template name="get-nested-content">
  +            <xsl:with-param name="content" select="xsp-request:default"/>
  +          </xsl:call-template>
  +        </xsl:when>
  +        <xsl:otherwise>null</xsl:otherwise>
  +      </xsl:choose>
  +    </xsl:variable>
  +
  +    <xsl:choose>
  +       <xsl:when test="$as = 'string'">
  +        <xsp:expr>
  +          (XSPRequestHelper.getSessionAttribute(request, <xsl:copy-of select="$name"/>,
<xsl:copy-of select="$default"/>))
  +        </xsp:expr>
  +      </xsl:when>
  +      <xsl:when test="$as = 'xml'">
  +        <xsp:logic>
  +          XSPRequestHelper.getSessionAttribute(request, this.contentHandler, <xsl:copy-of
select="$name"/>, <xsl:copy-of select="$default"/>);
           </xsp:logic>
         </xsl:when>
       </xsl:choose>
  
  
  

Mime
View raw message