cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-cocoon2/webapp/docs/samples/xscript simple.xsp soap-getquote1.xsl soap-getquote1.xsp soap-getquote2.xsp soap-getquote3.xsl soap-getquote3.xsp
Date Wed, 10 Oct 2001 20:53:57 GMT
dims        01/10/10 13:53:57

  Modified:    src/org/apache/cocoon cocoon.roles
               src/org/apache/cocoon/components/source URLSource.java
               webapp   cocoon.xconf sitemap.xmap
               webapp/docs/samples samples.xml
  Added:       lib      HTTPClient.jar
               src/org/apache/cocoon/components/language/markup/xsp
                        SOAPHelper.java
               src/org/apache/cocoon/components/language/markup/xsp/java
                        soap.xsl xscript-lib.xsl xscript.xsl
               src/org/apache/cocoon/components/xscript
                        StringBufferContentHandler.java XScriptManager.java
                        XScriptManagerImpl.java XScriptObject.java
                        XScriptObjectFromURL.java
                        XScriptObjectInlineXML.java
                        XScriptObjectResult.java XScriptVariableScope.java
               src/org/apache/cocoon/components/xscript/xslt copy-of.xsl
                        value-of.xsl
               webapp/docs/samples/xscript simple.xsp soap-getquote1.xsl
                        soap-getquote1.xsp soap-getquote2.xsp
                        soap-getquote3.xsl soap-getquote3.xsp
  Log:
  New SOAP logicsheet from "Ovidiu Predescu" <ovidiu@cup.hp.com>
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/lib/HTTPClient.jar
  
  	<<Binary file>>
  
  
  1.23      +4 -0      xml-cocoon2/src/org/apache/cocoon/cocoon.roles
  
  Index: cocoon.roles
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/cocoon.roles,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- cocoon.roles	2001/09/19 19:37:55	1.22
  +++ cocoon.roles	2001/10/10 20:53:56	1.23
  @@ -108,4 +108,8 @@
          shorthand="profiler"
          default-class="org.apache.cocoon.components.profiler.SimpleProfiler"/>
   
  + <role name="org.apache.cocoon.components.xscript.XScriptManager"
  +       shorthand="xscript"
  +       default-class="org.apache.cocoon.components.xscript.XScriptManagerImpl"/>
  +
   </role-list>
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/SOAPHelper.java
  
  Index: SOAPHelper.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/package org.apache.cocoon.components.language.markup.xsp;
  
  import java.net.URL;
  import java.net.MalformedURLException;
  import java.io.OutputStream;
  import java.io.InputStreamReader;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.BufferedReader;
  
  import org.xml.sax.InputSource;
  import org.apache.cocoon.components.xscript.XScriptManager;
  import org.apache.cocoon.components.xscript.XScriptObject;
  import org.apache.cocoon.components.xscript.XScriptObjectInlineXML;
  import org.apache.cocoon.ProcessingException;
  
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  
  import HTTPClient.HTTPConnection;
  import HTTPClient.HttpOutputStream;
  import HTTPClient.HTTPResponse;
  import HTTPClient.NVPair;
  
  /**
   * Helper for the SOAP logicsheet.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since July 16, 2001
   */
  public class SOAPHelper
  {
    XScriptManager xscriptManager;
    URL url;
    String method = "";
    XScriptObject xscriptObject;
    
    public SOAPHelper(ComponentManager manager, String urlContext, String url,
                      String method, XScriptObject xscriptObject)
      throws MalformedURLException, ComponentException
    {
      this.xscriptManager = (XScriptManager)manager.lookup(XScriptManager.ROLE);
      URL context = new URL(urlContext);
      this.url = new URL(context, url);
      this.method = method;
      this.xscriptObject = xscriptObject;
    }
  
    public XScriptObject invoke()
      throws ProcessingException
    {
      try {
        if (method == null || method.equals(""))
          method = "\"\"";
  
        HTTPConnection conn = new HTTPConnection(url);
        NVPair[] headers = new NVPair[] {
          new NVPair("Content-type", "text/xml; charset=\"utf-8\""),
          new NVPair("SOAPAction", method)
        };
        HttpOutputStream out = new HttpOutputStream();
        
        HTTPResponse response = conn.Post(url.getPath(), out, headers);
  
        // Write the SOAP request
        InputSource saxInputStream = xscriptObject.getInputSource();
        InputStream is = saxInputStream.getByteStream();
        byte[] buffer = new byte[1024];
        int len;
        while ((len = is.read(buffer)) > 0)
          out.write(buffer, 0, len);
        is.close();
        out.flush();
        out.close();
  
        // Read the results from the server    
        InputStreamReader isr = new InputStreamReader(response.getInputStream());
        BufferedReader br = new BufferedReader(isr);
        StringBuffer resultBuffer = new StringBuffer();
  
        char[] cbuffer = new char[1024];
        try {
          while ((len = br.read(cbuffer)) > 0)
            resultBuffer.append(cbuffer, 0, len);
          br.close();
          isr.close();
          is.close();
        }
        catch (IOException ex) {
          if (resultBuffer.length() == 0)
            throw ex;
        }
  
        return new XScriptObjectInlineXML(xscriptManager, resultBuffer);
      }
      catch (Exception ex) {
        throw new ProcessingException(ex);
      }
    }
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/java/soap.xsl
  
  Index: soap.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    With ideas from an early prototype implemented by Pankaj Kumar
    "pankaj_kumar@hp.com"
  
    Date: July 21, 2001
   -->
  
  <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:xscript="http://apache.org/xsp/xscript/1.0"
    xmlns:soap="http://apache.org/xsp/soap/3.0"
    >
  
    <xsl:include href="xscript-lib.xsl"/>
  
    <xsl:template match="xsp:page">
      <xsp:page>
        <xsl:apply-templates select="@*"/>
        <xsp:structure>
          <xsp:include>org.apache.cocoon.components.language.markup.xsp.SOAPHelper</xsp:include>
        </xsp:structure>
        <xsl:apply-templates/>
      </xsp:page>
    </xsl:template>
  
    <xsl:template match="soap:call">
      <xsl:variable name="url">
        <xsl:choose>
          <xsl:when test="soap:url"><xsl:value-of select="soap:url"/></xsl:when>
          <xsl:when test="@url">"<xsl:value-of select="@url"/>"</xsl:when>
          <xsl:otherwise>""</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
  
      <xsl:variable name="method">
        <xsl:choose>
          <xsl:when test="soap:method"><xsl:value-of select="soap:method"/></xsl:when>
          <xsl:when test="@method">"<xsl:value-of select="@method"/>"</xsl:when>
          <xsl:otherwise>""</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
  
      <xsl:variable name="scope">
        <xsl:call-template name="xscript-get-scope">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:variable name="context">
        <xsl:call-template name="xscript-get-context">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:variable name="creation-scope">
        <xsl:call-template name="xscript-get-scope-for-creation">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:variable name="creation-context">
        <xsl:call-template name="xscript-get-context-for-creation">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xscript:variable name="soap:call">
        <xsl:choose>
          <xsl:when test="soap:env">
            <xsl:apply-templates select="soap:env"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:call-template name="soap-env"/>
          </xsl:otherwise>
        </xsl:choose>
      </xscript:variable>
      <xsl:variable name="object">
        <xsl:call-template name="xscript-get">
          <xsl:with-param name="name" select="'soap:call'"/>
          <xsl:with-param name="scope" select="$scope"/>
          <xsl:with-param name="context" select="$context"/>
          <xsl:with-param name="as" select="'object'"/>
        </xsl:call-template>
      </xsl:variable>
      <xsp:logic>
        getLogger().debug("URL context is " + XSPRequestHelper.getRequestedURL(objectModel));
        getLogger().debug("XScriptObject for soap:call is\n" + <xsl:value-of select="$object"/>);
        try {
          xscriptManager.put("soap:call",
            ((new SOAPHelper(manager,
                             XSPRequestHelper.getRequestedURL(objectModel),
                             <xsl:value-of select="$url"/>,
                             <xsl:value-of select="$method"/>,
                             <xsl:value-of select="$object"/>
                             )).invoke()),
            <xsl:value-of select="$creation-scope"/>,
            <xsl:value-of select="$creation-context"/>);
          getLogger().debug("SOAP result is\n" + <xsl:value-of select="$object"/>);
          <xscript:get name="soap:call"/>
        }
        catch (Exception ex) {
          <soap-err:error xmlns:soap-err="http://apache.org/xsp/soap/3.0"><xsp:expr>ex</xsp:expr></soap-err:error>
          getLogger().error(ex.toString(), ex);
        }
      </xsp:logic>
    </xsl:template>
  
    <xsl:template match="soap:env" name="soap-env">
      <SOAP-ENV:Envelope
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        >
        <xsl:if test="soap:header">
            <xsl:apply-templates select="soap:header"/>
        </xsl:if>
      <xsl:choose>
        <xsl:when test="soap:body">
            <xsl:apply-templates select="soap:body"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="soap-body"/>
        </xsl:otherwise>
      </xsl:choose>
      </SOAP-ENV:Envelope>
    </xsl:template>
  
    <xsl:template match="soap:header" name="soap-header">
        <SOAP-ENV:Header
          xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
          >
          <xsl:apply-templates select="*[name() != 'soap:url'
                                         and name() != 'soap:method'
                                         and name() != 'soap:namespace']"/>
        </SOAP-ENV:Header>
    </xsl:template>
    
    <xsl:template match="soap:body" name="soap-body">
      <xsp:logic>
        <xsl:for-each select="soap:namespace">
          // Generate the namespace defined with soap:namespace
          this.contentHandler.startPrefixMapping(
            "<xsl:value-of select="@prefix"/>",
            "<xsl:value-of select="@uri"/>");
        </xsl:for-each>
      </xsp:logic>
      <SOAP-ENV:Body
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        >
        <xsl:apply-templates select="*[name() != 'soap:url'
                                       and name() != 'soap:method'
                                       and name() != 'soap:namespace']"/>
      </SOAP-ENV:Body>
      <xsp:logic>
        <xsl:for-each select="soap:namespace">
          // End the namespace defined with soap:namespace
          this.contentHandler.endPrefixMapping(
            "<xsl:value-of select="@prefix"/>");
        </xsl:for-each>
      </xsp:logic>
    </xsl:template>
    
    <xsl:template match="soap:enc">
        <xsp:attribute name="SOAP-ENV:encodingStyle">http://schemas.xmlsoap.org/soap/encoding/</xsp:attribute>
    </xsl:template>
  
    <xsl:template match="@*|node()" priority="-1">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/java/xscript-lib.xsl
  
  Index: xscript-lib.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    Date: September 19, 2001
   -->
  
  <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
    xmlns:xscript="http://apache.org/xsp/xscript/1.0"
    xmlns:xalan="http://xml.apache.org/xalan"
    xmlns:saxon="http://icl.com/saxon"
    >
  
    <xsl:template name="xscript-variable">
      <!-- PUBLIC: create a new XScript variable -->
      <xsl:param name="name"/>
      <xsl:param name="href"/>
      <xsl:param name="scope"/>
      <xsl:param name="context"/>
  
      <xsl:choose>
        <xsl:when test="$href">
          <xsl:call-template name="xscript-variable-from-url">
            <xsl:with-param name="name" select="$name"/>
            <xsl:with-param name="scope" select="$scope"/>
            <xsl:with-param name="context" select="$context"/>
            <xsl:with-param name="href" select="$href"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="xscript-variable-inline">
            <xsl:with-param name="name" select="$name"/>
            <xsl:with-param name="scope" select="$scope"/>
            <xsl:with-param name="context" select="$context"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
  
    <xsl:template name="xscript-get">
      <!-- PUBLIC: obtain the value of an XScript variable -->
      <xsl:param name="name"/>
      <xsl:param name="as"/>
      <xsl:param name="scope"/>
      <xsl:param name="context"/>
  
      <xsl:variable name="object">
        <xsl:choose>
          <xsl:when test="contains($scope, 'ALL_SCOPES')">
            xscriptManager.getFirst("<xsl:value-of select="$name"/>",
                                    <xsl:value-of select="$context"/>)
          </xsl:when>
          <xsl:otherwise>
            xscriptManager.get("<xsl:value-of select="$name"/>",
                               <xsl:value-of select="$scope"/>,
                               <xsl:value-of select="$context"/>)
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="$as = 'object'">
          <xsp:logic><xsl:value-of select="$object"/></xsp:logic>
        </xsl:when>
        <xsl:otherwise>
          <!-- insert the content of the XScript variable in the SAX
               event stream -->
          <xsp:logic>
            try {
              <xsl:value-of select="$object"/>.toSAX(this.contentHandler);
            }
            catch (IllegalArgumentException ex) {
              <xscript:error><xsp:expr>ex.getMessage()</xsp:expr></xscript:error>
            }
          </xsp:logic>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
  
    <xsl:template name="xscript-remove">
      <!-- PUBLIC: undeclare an XScript variable -->
      <xsl:param name="name"/>
      <xsl:param name="scope"/>
      <xsl:param name="context"/>
      <xsp:logic>
        <xsl:choose>
          <xsl:when test="contains($scope, 'ALL_SCOPES')">
            xscriptManager.removeFirst("<xsl:value-of select="$name"/>",
                                       <xsl:value-of select="$context"/>);
          </xsl:when>
          <xsl:otherwise>
            xscriptManager.remove("<xsl:value-of select="$name"/>",
                                  <xsl:value-of select="$scope"/>,
                                  <xsl:value-of select="$context"/>);
          </xsl:otherwise>
        </xsl:choose>
      </xsp:logic>
    </xsl:template>
  
    <xsl:template name="xscript-transform">
      <!-- PUBLIC: transform an XScriptObject pointed to by a variable
           using another XScriptObject, which is assumed to contain an
           XSLT stylesheet. -->
      <xsl:param name="name"/>
      <xsl:param name="scope"/>
      <xsl:param name="context">""</xsl:param>
      <xsl:param name="stylesheet"/>
      <xsl:param name="stylesheet-scope"/>
      <xsl:param name="stylesheet-context">""</xsl:param>
      <xsl:param name="parameters"/>
  
      <xsl:variable name="object">
        <xsl:call-template name="xscript-get">
          <xsl:with-param name="name" select="$name"/>
          <xsl:with-param name="scope" select="$scope"/>
          <xsl:with-param name="context" select="$context"/>
          <xsl:with-param name="as" select="'object'"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:variable name="stylesheet-object">
        <xsl:call-template name="xscript-get">
          <xsl:with-param name="name" select="$stylesheet"/>
          <xsl:with-param name="scope" select="$stylesheet-scope"/>
          <xsl:with-param name="context" select="$stylesheet-context"/>
          <xsl:with-param name="as" select="'object'"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:variable name="params">
        params<xsl:value-of select="count(ancestor-or-self::*)"/>
      </xsl:variable>
  
      <xsp:logic>
        {
          Parameters <xsl:value-of select="$params"/> = new Parameters();
          <xsl:call-template name="xscript-parameter">
            <xsl:with-param name="params" select="$params"/>
            <xsl:with-param name="parameters" select="$parameters"/>
          </xsl:call-template>
          XScriptObject result = <xsl:value-of select="$object"/>.transform(
               <xsl:value-of select="$stylesheet-object"/>,
               <xsl:value-of select="$params"/>);
  <!--
          System.out.println("input source =\n" + <xsl:value-of select="$object"/>);
          System.out.println("stylesheet source =\n" + <xsl:value-of select="$stylesheet-object"/>);
          System.out.println("transformation result =\n" + result);
  -->
          result.toSAX(this.contentHandler);
        }
      </xsp:logic>
    </xsl:template>
  
  
    <!-- Helper templates used by this stylesheet, and possibly others
         as well -->
  
    <xsl:template name="xscript-variable-from-url">
      <!-- PUBLIC: create an XScript variable from an URL -->
      <xsl:param name="name"/>
      <xsl:param name="scope"/>
      <xsl:param name="context"/>
      <xsl:param name="href"/>
      <xsp:logic>
        xscriptManager.put("<xsl:value-of select="$name"/>",
                           new XScriptObjectFromURL(xscriptManager,
                                                    "<xsl:value-of select="$href"/>"),
                           <xsl:value-of select="$scope"/>,
                           <xsl:value-of select="$context"/>);
      </xsp:logic>
    </xsl:template>
  
    <xsl:template name="xscript-variable-inline">
      <!-- PUBLIC: create an XScript variable from inline XML -->
      <xsl:param name="name"/>
      <xsl:param name="scope"/>
      <xsl:param name="context"/>
  
      <xsl:variable name="xml-inline">
        xmlInline<xsl:value-of select="count(ancestor-or-self::*)"/>
      </xsl:variable>
  
      <xsl:variable name="oldHandler">
        oldHandler<xsl:value-of select="count(ancestor-or-self::*)"/>
      </xsl:variable>
  
      <xsp:logic>
        {
          XScriptObjectInlineXML <xsl:value-of select="$xml-inline"/>
            = new XScriptObjectInlineXML(xscriptManager);
          ContentHandler <xsl:value-of select="$oldHandler"/> = this.contentHandler;
          <xsl:value-of select="$xml-inline"/>.setNextContentHandler(<xsl:value-of select="$oldHandler"/>);
          this.contentHandler = <xsl:value-of select="$xml-inline"/>.getContentHandler();
          <xsl:apply-templates/>
          this.contentHandler = <xsl:value-of select="$oldHandler"/>;
          xscriptManager.put("<xsl:value-of select="$name"/>",
                             <xsl:value-of select="$xml-inline"/>,
                             <xsl:value-of select="$scope"/>,
                             <xsl:value-of select="$context"/>);
        }
      </xsp:logic>
  
    </xsl:template>
  
    <xsl:template name="xscript-get-scope">
      <!-- PUBLIC: obtain the Java expression for a given XScript
           variable scope. If no scope parameter is specified,
           ALL_SCOPES is assumed. -->
      <xsl:param name="scope" select="'all-scopes'"/>
      <xsl:choose>
        <xsl:when test="$scope = 'global'">org.apache.cocoon.components.xscript.XScriptManager.GLOBAL_SCOPE</xsl:when>
        <xsl:when test="$scope = 'page'">org.apache.cocoon.components.xscript.XScriptManager.PAGE_SCOPE</xsl:when>
        <xsl:when test="$scope = 'session'">org.apache.cocoon.components.xscript.XScriptManager.SESSION_SCOPE</xsl:when>
        <xsl:otherwise>org.apache.cocoon.components.xscript.XScriptManager.ALL_SCOPES</xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template name="xscript-get-scope-for-creation">
      <!-- PUBLIC: obtain the Java expression for a given XScript
           variable scope. Similar with xscript-get-scope, but when
           defining an XScript variable, ALL_SCOPES doesn't make
           sense: if no scope parameter is specified, SESSION_SCOPE is
           assumed. -->
      <xsl:param name="scope" select="'session'"/>
      <xsl:choose>
        <xsl:when test="$scope = 'global'">org.apache.cocoon.components.xscript.XScriptManager.GLOBAL_SCOPE</xsl:when>
        <xsl:when test="$scope = 'page'">org.apache.cocoon.components.xscript.XScriptManager.PAGE_SCOPE</xsl:when>
        <xsl:otherwise>org.apache.cocoon.components.xscript.XScriptManager.SESSION_SCOPE</xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template name="xscript-get-context">
      <!-- PUBLIC: obtain the Java expression for an XScript variable
           context. If the 'scope' parameter is not specified or when
           its value is 'all-scopes', an expression that contains both
           the session and the page scope is returned. This could be
           passed directly to the getFirst() method of XScriptManager.
           -->
      <xsl:param name="scope" select="'all-scopes'"/>
      <xsl:choose>
        <xsl:when test="$scope = 'global'">""</xsl:when>
        <!-- for the page scope use the context-path as context -->
        <xsl:when test="$scope = 'page'">(XSPRequestHelper.getContextPath(objectModel))</xsl:when>
        <xsl:when test="$scope = 'session'">(XSPRequestHelper.getSessionId(objectModel))</xsl:when>
        <xsl:otherwise>(XSPRequestHelper.getSessionId(objectModel)), (XSPRequestHelper.getContextPath(objectModel))</xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template name="xscript-get-context-for-creation">
      <!-- PUBLIC: obtain the Java expression for an XScript variable
           context. If the `scope' parameter is not specified, the
           default is SESSION_SCOPE.
           -->
      <xsl:param name="scope" select="'session'"/>
      <xsl:choose>
        <xsl:when test="$scope = 'global'">""</xsl:when>
        <!-- for the page scope use the context-path as context -->
        <xsl:when test="$scope = 'page'">(XSPRequestHelper.getContextPath(objectModel))</xsl:when>
        <xsl:otherwise>(XSPRequestHelper.getSessionId(objectModel))</xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template name="xscript-parameter">
      <xsl:param name="parameters"/>
      <xsl:param name="params"/>
  
      <xsl:choose>
        <xsl:when test="contains(system-property('xsl:vendor-url'), 'xalan')">
          <xsl:for-each select="xalan:nodeset($parameters)/xscript:parameter">
            <xsp:logic>
              <xsl:value-of select="$params"/>.setParameter(
                "<xsl:value-of select="@name"/>",
                "<xsl:value-of select="."/>");
            </xsp:logic>
          </xsl:for-each>
        </xsl:when>
        <xsl:when test="contains(system-property('xsl:vendor-url'), 'saxon')">
          <xsl:for-each select="saxon:node-set($parameters)/xscript:parameter">
            <xsp:logic>
              <xsl:value-of select="$params"/>.setParameter(
              "<xsl:value-of select="./@name"/>",
                "<xsl:value-of select="."/>");
            </xsp:logic>
          </xsl:for-each>
        </xsl:when>
      </xsl:choose>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/language/markup/xsp/java/xscript.xsl
  
  Index: xscript.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    Date: September 19, 2001
   -->
  
  <xsl:stylesheet
    version="1.0"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:xscript="http://apache.org/xsp/xscript/1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
  
    <xsl:include href="xscript-lib.xsl"/>
  
    <xsl:template match="xsp:page">
      <xsp:page>
        <xsl:apply-templates select="@*"/>
        <xsp:structure>
          <xsp:include>org.apache.cocoon.components.xscript.*</xsp:include>
          <xsp:include>org.apache.avalon.framework.parameters.Parameters</xsp:include>
          <xsp:include>org.xml.sax.ContentHandler</xsp:include>
        </xsp:structure>
  
        <xsp:logic>
        </xsp:logic>
  
        <xsp:init-page>
          XScriptManager xscriptManager;
          try {
            xscriptManager = (XScriptManager)this.manager.lookup(XScriptManager.ROLE);
          }
          catch (ComponentException ex) {
            throw new ProcessingException(ex);
          }
        </xsp:init-page>
  
        <xsl:apply-templates/>
      </xsp:page>
    </xsl:template>
  
  
    <xsl:template match="xscript:variable">
      <xsl:variable name="scope">
        <xsl:call-template name="xscript-get-scope-for-creation">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="context">
        <xsl:call-template name="xscript-get-context-for-creation">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:call-template name="xscript-variable">
        <xsl:with-param name="name" select="@name"/>
        <xsl:with-param name="href" select="@href"/>
        <xsl:with-param name="scope" select="$scope"/>
        <xsl:with-param name="context" select="$context"/>
      </xsl:call-template>
    </xsl:template>
  
  
    <xsl:template match="xscript:get">
      <xsl:variable name="scope">
        <xsl:call-template name="xscript-get-scope">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="context">
        <xsl:call-template name="xscript-get-context">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
      <xsp:logic>
        <xsl:call-template name="xscript-get">
          <xsl:with-param name="name" select="@name"/>
          <xsl:with-param name="as" select="@as"/>
          <xsl:with-param name="scope" select="$scope"/>
          <xsl:with-param name="context" select="$context"/>
        </xsl:call-template>
        ;
      </xsp:logic>
    </xsl:template>
  
    <xsl:template match="xscript:remove">
      <xsl:variable name="scope">
        <xsl:call-template name="xscript-get-scope">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="context">
        <xsl:call-template name="xscript-get-context">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:call-template name="xscript-remove">
        <xsl:with-param name="name" select="@name"/>
        <xsl:with-param name="scope" select="$scope"/>
        <xsl:with-param name="context" select="$context"/>
      </xsl:call-template>
    </xsl:template>
  
  
    <xsl:template match="xscript:transform">
      <xsl:variable name="name" select="@name"/>
      <xsl:variable name="scope">
        <xsl:call-template name="xscript-get-scope">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="context">
        <xsl:call-template name="xscript-get-context">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:variable name="stylesheet" select="@stylesheet"/>
      <xsl:variable name="stylesheet-scope">
        <xsl:call-template name="xscript-get-scope">
          <xsl:with-param name="stylesheet-scope" select="@stylesheet-scope"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="stylesheet-context">
        <xsl:call-template name="xscript-get-context">
          <xsl:with-param name="stylesheet-context" select="@stylesheet-context"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:variable name="parameters">
        <xsl:copy-of select="xscript:parameter"/>
      </xsl:variable>
  
      <xsl:call-template name="xscript-transform">
        <xsl:with-param name="name" select="$name"/>
        <xsl:with-param name="scope" select="$scope"/>
        <xsl:with-param name="context" select="$context"/>
        <xsl:with-param name="stylesheet" select="$stylesheet"/>
        <xsl:with-param name="stylesheet-scope" select="$stylesheet-scope"/>
        <xsl:with-param name="stylesheet-context" select="$stylesheet-context"/>
        <xsl:with-param name="parameters" select="$parameters"/>
      </xsl:call-template>
    </xsl:template>
  
  
    <xsl:template match="xscript:copy-of | xscript:value-of">
      <xsl:variable name="parameters">
        <xscript:parameter name="xpath">
          <xsl:value-of select="@select"/>
        </xscript:parameter>
      </xsl:variable>
      <xsl:call-template name="xscript-builtin">
        <xsl:with-param name="builtin" select="name()"/>
        <xsl:with-param name="parameters" select="$parameters"/>
      </xsl:call-template>
    </xsl:template>
  
  
    <!-- PRIVATE -->
    <xsl:template name="xscript-builtin">
      <xsl:param name="builtin"/>
      <xsl:param name="parameters"/>
      <xsl:param name="name" select="@name"/>
  
      <xsl:variable name="scope">
        <xsl:call-template name="xscript-get-scope">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:variable name="context">
        <xsl:call-template name="xscript-get-context">
          <xsl:with-param name="scope" select="@scope"/>
        </xsl:call-template>
      </xsl:variable>
  
      <xsl:call-template name="xscript-transform">
        <xsl:with-param name="parameters" select="$parameters"/>
        <xsl:with-param name="name" select="$name"/>
        <xsl:with-param name="scope" select="$scope"/>
        <xsl:with-param name="context" select="$context"/>
        <xsl:with-param name="stylesheet" select="$builtin"/>
        <xsl:with-param name="stylesheet-scope">
          <xsl:call-template name="xscript-get-scope">
            <xsl:with-param name="scope" select="'global'"/>
          </xsl:call-template>
        </xsl:with-param>
        <xsl:with-param name="stylesheet-context">
          <xsl:call-template name="xscript-get-context">
            <xsl:with-param name="scope" select="'global'"/>
          </xsl:call-template>
        </xsl:with-param>
      </xsl:call-template>
  
    </xsl:template>
  
    <xsl:template match="@*|*|text()|processing-instruction()">
      <!-- Catch all template. Just pass along unmodified everything we
           don't handle. -->
      <xsl:copy>
        <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
      </xsl:copy>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.17      +20 -16    xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java
  
  Index: URLSource.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- URLSource.java	2001/10/08 20:03:15	1.16
  +++ URLSource.java	2001/10/10 20:53:56	1.17
  @@ -8,30 +8,34 @@
   
   package org.apache.cocoon.components.source;
   
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.ResourceNotFoundException;
  -import org.apache.cocoon.components.parser.Parser;
  -import org.apache.cocoon.environment.ModifiableSource;
  -import org.apache.cocoon.xml.XMLConsumer;
  -import org.xml.sax.ContentHandler;
  -import org.xml.sax.InputSource;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.ext.LexicalHandler;
  -
  -import java.io.*;
  -import java.lang.reflect.Method;
  -import java.net.URL;
  +import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.cocoon.ProcessingException;
  +import org.apache.cocoon.ResourceNotFoundException;
  +import org.apache.cocoon.components.parser.Parser;
  +import org.apache.cocoon.environment.ModifiableSource;
  +import org.apache.cocoon.xml.XMLConsumer;
  +import org.xml.sax.ContentHandler;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +import org.xml.sax.ext.LexicalHandler;
  +
  +import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.FileNotFoundException;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.lang.reflect.Method;
  +import java.net.URL;
   import java.net.URLConnection;
   
   /**
    * Description of a source which is described by an URL.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.16 $ $Date: 2001/10/08 20:03:15 $
  + * @version CVS $Revision: 1.17 $ $Date: 2001/10/10 20:53:56 $
    */
   
  -public final class URLSource implements ModifiableSource {
  +public class URLSource implements ModifiableSource {
   
       /** Identifier for file urls */
       private final String FILE = "file:";
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/StringBufferContentHandler.java
  
  Index: StringBufferContentHandler.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xscript;
  
  import java.util.Stack;
  import java.io.StringReader;
  import java.io.StringBufferInputStream;
  import java.io.IOException;
  
  import org.xml.sax.InputSource;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.Attributes;
  import org.xml.sax.helpers.DefaultHandler;
  
  
  /**
   * A <code>ContentHandler</code> that accumulates the SAX stream into
   * a <code>StringBuffer</code> object.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since August 30, 2001
   */
  public class StringBufferContentHandler extends DefaultHandler
  {
    private Stack namespaces = new Stack();
    ContentHandler contentHandler;
    StringBuffer stringBuffer;
    static Marker marker = new Marker();
  
    public StringBufferContentHandler(StringBuffer stringBuffer)
    {
      this.stringBuffer = stringBuffer;
    }
  
    public void setNextContentHandler(ContentHandler handler)
    {
      this.contentHandler = handler;
    }
  
    public void startPrefixMapping(String prefix, String uri)
      throws SAXException
    {
      namespaces.push(new NPU(prefix, uri));
    }
  
    public void endPrefixMapping(String prefix)
      throws SAXException
    {
      namespaces.pop();
    }
  
    public void startElement(String uri, String loc, String qName, Attributes a)
      throws SAXException
    {
      int lastNamespaceIndex = 0;
  
      lastNamespaceIndex = namespaces.size() - 1;
      while(lastNamespaceIndex >= 0
            && namespaces.elementAt(lastNamespaceIndex) != marker)
        lastNamespaceIndex--;
  
      if (lastNamespaceIndex < 0)
        lastNamespaceIndex = 0;
      else if (namespaces.elementAt(lastNamespaceIndex) == marker)
        lastNamespaceIndex++;
  
      namespaces.push(marker);
  
      stringBuffer.append("<" + qName);
  
      for (int i = 0, len = a.getLength(); i < len; i++) {
        // Check if the attribute is a namespace declaration. Some
        // parsers (Xerces) sometimes pass the namespace declaration
        // as an attribute. We need to catch this case so that we
        // don't end up generating the namespace declaration twice.
        String attrName = a.getQName(i);
  
        if (attrName.startsWith("xmlns:")) {
          // We have a namespace declaration
          String name = a.getLocalName(i);
  
          // Check whether this namespace has been already declared
          boolean found = false;
          for (int j = namespaces.size() - 1;
               j >= lastNamespaceIndex;
               j--) {
            Object obj = namespaces.elementAt(j);
            if (obj == marker)
              continue;
            NPU npu = (NPU)obj;
            
            if (name.equals(npu.prefix)) {
              found = true;
              break;
            }
          }
  
          if (!found) {
            namespaces.push(new NPU(name, a.getValue(i)));
          }
        }
        else {
          // Normal attribute
          stringBuffer.append(" " + a.getQName(i)
                              + "=\"" + a.getValue(i) + "\"");
        }
      }
  
      if (namespaces.size() != 0) {
        for (int i = namespaces.size() - 1; i >= lastNamespaceIndex; i--) {
          Object obj = namespaces.elementAt(i);
          if (obj == marker)
            continue;
          NPU npu = (NPU)obj;
          stringBuffer.append(" xmlns:" + npu.prefix + "=\"" + npu.uri + "\"");
        }
      }
      stringBuffer.append(">");
    }
  
    public void endElement(String uri, String loc, String qName)
      throws SAXException 
    {
      stringBuffer.append("</" + qName + ">");
  
      Object obj;
      do {
        obj = namespaces.pop();
      } while (obj != marker);
    }
      
    public void characters(char ch[], int start, int len)
      throws SAXException 
    {
      stringBuffer.append(ch, start, len);
    }
  }
  
  class NPU
  {
    public String prefix;
    public String uri;
  
    NPU(String prefix, String uri)
    {
      this.prefix = prefix;
      this.uri = uri;
    }
  
    public String toString()
    {
      return this.prefix + "=" + this.uri;
    }
  }
  
  class Marker
  {
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptManager.java
  
  Index: XScriptManager.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xscript;
  
  import org.apache.avalon.framework.component.ComponentManager;
  
  /**
   * <code>XScriptManager</code> is the public interface used to
   * interact with the XScript component, which implements the
   * supporting code for the XScript language.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since August  4, 2001
   */
  public interface XScriptManager
  {
    public final String ROLE = "org.apache.cocoon.components.xscript.XScriptManager";
  
    public final String XSCRIPT_NS = "http://apache.org/xsp/xscript/1.0";
  
    /**
     * The variable's global scope. Each Cocoon instance has exactly one
     * global scope for variables.
     */
    public final int GLOBAL_SCOPE = 1;
    /**
     * The session scope. This scope is specific to a particular
     * activation of an XSP page, which is usually identified by the
     * session id of the user that sent the HTTP request. From XScript's
     * point of view however, the session identifier is not interpreted
     * in any way, so a client can define its own notion of "session".
     */
    public final int SESSION_SCOPE = 2;
    
    /**
     * The page scope. This is scope very specific to an XSP page, and
     * defines variables visible only within the context of that
     * page. No other XSP page can access these variables, unless it
     * knows the identifier used by that page to store its
     * variables. This identifier is not necessarily the URL or full
     * path of that page; it is up to the page to define it.
     */
    public final int PAGE_SCOPE = 3;
  
    /**
     * Search for a variable in all the accessible scopes. The variable
     * is first searched in the current session scope. If no variable is
     * found here, the current page scope is searched next. If nothing
     * is found either, the global scope is searched.
     */
    public final int ALL_SCOPES = 4;
  
    /**
     * Obtains the object value of the
     * <code>name</code> variable in <code>scope</code>. The
     * <code>context</code> parameter is interpreted differently
     * depending on the value of <code>scope</code>, as follows:
     *
     * <ul>
     *
     *  <li>if <code>scope</code> is <code>{@link #GLOBAL_SCOPE}</code>, the
     *  value of <code>context is ignored.
     *
     *  <li>if <code>scope</code> is <code>{@link
     *  #SESSION_SCOPE}</code>, the value of <code>context</code> is
     *  interpreted as the session identifier.
     *
     *  <li>if <code>scope</code> is <code>{@link #PAGE_SCOPE}</code>, the value
     *  of <code>context</code> is interpreted as an identifier of the
     *  page. This could be the URL of the page or the path of the file
     *  name in the file system.
     *
     * </ul>
     *
     * @param name a <code>String</code> value
     * @param scope an <code>int</code> value
     * @param context a <code>String</code> value whose interpretation
     * depends on <code>scope</code>
     * @return a <code>{@link XScriptObject}</code> value
     */
    public XScriptObject get(String name, int scope, String context)
      throws IllegalArgumentException;
  
    /**
     * Search for the first occurence of the variable
     * <code>name</code>.
     *
     * <p>The search happens first in the session scope
     * identified by <code>sessionContext</code>. If no variable is
     * found here, the search continues in the page scope identified by
     * <code>pageContext</code>. If no variable is found here, it's
     * finally searched in the global scope.
     *
     * <p>The <code>XScriptObject</code> value of the variable is
     * returned if a variable is found in one of the scopes, otherwise
     * an exception is thrown.
     *
     * @param name a <code>String</code> value
     * @param sessionContext a <code>String</code> value
     * @param pageContext a <code>String</code> value
     * @return a <code>XScriptObject</code> value
     * @exception IllegalArgumentException if an error occurs
     */
    public XScriptObject getFirst(String name,
                                  String sessionContext,
                                  String pageContext)
      throws IllegalArgumentException;
    
    /**
     * Defines or overwrites the value of variable
     * <code>name</code> in <code>scope</code>. The <code>context</code>
     * argument is interpreted as described in {@link #get(String, int,
     * String)}.
     *
     * @param name a <code>String</code> value
     * @param value a <code>XScriptObject</code> value
     * @param scope an <code>int</code> value
     * @param context a <code>String</code> value whose interpretation
     * depends on <code>scope</code>
     */
    public void put(String name, XScriptObject value, int scope, String context)
      throws IllegalArgumentException;
  
    /**
     * Removes a variable previously declared in <code>scope</code>
     * within <code>context</code>. Such a variable could be declared
     * using the {@link #put(String, XScriptObject, int, String)}
     * method.
     *
     * @param name a <code>String</code> value
     * @param scope an <code>int</code> value
     * @param context a <code>String</code> value
     */
    public void remove(String name, int scope, String context);
    
    /**
     * Remove the first appearance of <code>name</code> in the all the
     * currently accessible scopes. The search happens as described in
     * {@link #getFirst(String,String,String)}.
     *
     * @param name a <code>String</code> value
     * @param sessionContext a <code>String</code> value
     * @param pageContext a <code>String</code> value
     * @exception IllegalArgumentException if an error occurs
     */
    public void removeFirst(String name, String sessionContext, String pageContext)
      throws IllegalArgumentException;
    
    /**
     * Return the <code>ComponentManager</code> managing this instance.
     *
     * @return a <code>ComponentManager</code> value
     */
    public ComponentManager getComponentManager();
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptManagerImpl.java
  
  Index: XScriptManagerImpl.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xscript;
  
  import java.util.HashMap;
  
  import java.io.InputStream;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.parameters.ParameterException;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.avalon.excalibur.pool.Poolable;
  
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.cocoon.components.xslt.XSLTProcessor;
  import org.apache.cocoon.components.xscript.XScriptObjectFromURL;
  
  /**
   * The actual implementation of the <code>XScriptManager</code> interface.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since August  4, 2001
   */
  public class XScriptManagerImpl
    extends AbstractLoggable
    implements XScriptManager, Composable, Component, Configurable, Poolable
  {
    /**
     * The global scope. All the global variables are indexed in this
     * space by their name.
     */
    XScriptVariableScope globalScope = new XScriptVariableScope();
  
    /**
     * The session scope. The key in this hash table is the session
     * identifier, which should be a <code>String</code> object. The
     * value is an {@link XScriptVariableScope} instance which holds the
     * variables in a session scope.
     */
    HashMap sessionScope = new HashMap();
  
    /**
     * Page specific variables. The key in the hash map is an identifier
     * for the page, usually the full path name to the page. The value
     * is an {@link XScriptVariableScope} instance which holds the
     * variables in a page scope.
     */
    HashMap pageScope = new HashMap();
  
    /**
     * The <code>ComponentManager</code> instance.
     */
    protected ComponentManager manager = null;
  
    public void compose(ComponentManager manager)
      throws ComponentException
    {
      this.manager = manager;
      getLogger().debug("XScriptManager component initialized.");
    }
  
    public void configure(Configuration conf)
      throws ConfigurationException
    {
      try {
        Parameters params = Parameters.fromConfiguration(conf);
        String[] names = params.getNames();
        for (int i = 0; i < names.length; i++) {
          String resourceString = params.getParameter(names[i]);
          XScriptObject resource = new XScriptObjectFromURL(this, resourceString);
          globalScope.put(names[i], resource);
        }
      }
      catch (ParameterException ex) {
        throw new ConfigurationException("Error configuring XScriptManager: ",
                                         ex);
      }
    }
  
    private IllegalArgumentException
      createAccessException(String msg, String name, int scope, String context)
    {
      String message = "Cannot " + msg + " variable named '"
        + name + "' in ";
  
      if (scope == XScriptManager.GLOBAL_SCOPE)
        message += "global scope";
      else if (scope == XScriptManager.SESSION_SCOPE)
        message += "session scope";
      else if (scope == XScriptManager.PAGE_SCOPE)
        message += "page scope";
      else
        message += "unknown scope (" + scope + ")";
  
      message += " with context '" + context + "'";
      return new IllegalArgumentException(message);
    }
    
    public XScriptObject get(String name, int scope, String context)
      throws IllegalArgumentException
    {
      if (scope == XScriptManager.GLOBAL_SCOPE)
        return globalScope.get(name);
      else if (scope == XScriptManager.SESSION_SCOPE) {
        XScriptVariableScope s = (XScriptVariableScope)sessionScope.get(context);
        if (s != null)
          return s.get(name);
      }
      else if (scope == XScriptManager.PAGE_SCOPE) {
        XScriptVariableScope s = (XScriptVariableScope)pageScope.get(context);
        if (s != null)
          return s.get(name);
      }
  
      throw createAccessException("find", name, scope, context);
    }
    
    public XScriptObject getFirst(String name,
                                  String sessionContext,
                                  String pageContext)
      throws IllegalArgumentException
    {
      XScriptVariableScope scope;
  
      // Lookup in the session scope first.
      scope = (XScriptVariableScope)sessionScope.get(sessionContext);
      if (scope != null) {
        synchronized(scope) {
          if (scope.defines(name))
            return scope.get(name);
        }
      }
  
      // No luck finding `name' in session scope, try in page scope.
      scope = (XScriptVariableScope)pageScope.get(pageContext);
      if (scope != null) {
        synchronized(scope) {
          if (scope.defines(name))
            return scope.get(name);
        }
      }
  
      // No luck finding `name' in the page scope, try the global scope.
      synchronized(globalScope) {
        if (globalScope.defines(name))
          return globalScope.get(name);
      }
  
      // No variable `name' found, throw an exception.
      throw new IllegalArgumentException("getFirst: no variable '" + name
                                         + "' accessible from this scope!");
    }
    
    public void put(String name, XScriptObject value, int scope, String context)
    {
      if (scope == XScriptManager.GLOBAL_SCOPE) {
        globalScope.put(name, value);
      }
      else if (scope == XScriptManager.SESSION_SCOPE) {
        XScriptVariableScope s = (XScriptVariableScope)sessionScope.get(context);
        if (s == null) {
          s = new XScriptVariableScope();
          sessionScope.put(context, s);
        }
        s.put(name, value);
      }
      else if (scope == XScriptManager.PAGE_SCOPE) {
        XScriptVariableScope s = (XScriptVariableScope)pageScope.get(context);
        if (s == null) {
          s = new XScriptVariableScope();
          pageScope.put(context, s);
        }
        s.put(name, value);
      }
      else
        throw createAccessException("create", name, scope, context);
    }
  
    public void remove(String name, int scope, String context)
      throws IllegalArgumentException
    {
      if (scope == XScriptManager.GLOBAL_SCOPE) {
        globalScope.remove(name);
      }
      else if (scope == XScriptManager.SESSION_SCOPE) {
        XScriptVariableScope s = (XScriptVariableScope)sessionScope.get(context);
        if (s != null)
          s.remove(name);
      }
      else if (scope == XScriptManager.PAGE_SCOPE) {
        XScriptVariableScope s = (XScriptVariableScope)pageScope.get(context);
        if (s != null)
          s.remove(name);
      }
      else
        throw createAccessException("remove", name, scope, context);
    }
  
    public void removeFirst(String name,
                            String sessionContext,
                            String pageContext)
      throws IllegalArgumentException
    {
      XScriptVariableScope scope;
  
      // Lookup in the session scope first.
      scope = (XScriptVariableScope)sessionScope.get(sessionContext);
      if (scope != null) {
        synchronized(scope) {
          if (scope.defines(name)) {
            scope.remove(name);
            return;
          }
        }
      }
  
      // No luck finding `name' in session scope, try in page scope.
      scope = (XScriptVariableScope)pageScope.get(pageContext);
      if (scope != null) {
        synchronized(scope) {
          if (scope.defines(name)) {
            scope.remove(name);
            return;
          }
        }
      }
  
      // No luck finding `name' in the page scope, try the global scope.
      synchronized(globalScope) {
        if (globalScope.defines(name)) {
          globalScope.remove(name);
          return;
        }
      }
  
      // No variable `name' found, throw an exception.
      throw new IllegalArgumentException("removeFirst: no variable '" + name
                                         + "' accessible from this scope!");
    }
    
    public ComponentManager getComponentManager()
    {
      return manager;
    }
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptObject.java
  
  Index: XScriptObject.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xscript;
  
  import javax.xml.transform.stream.StreamResult;
  import java.util.Date;
  import java.io.IOException;
  import java.io.CharArrayWriter;
  
  import org.xml.sax.SAXException;
  import org.xml.sax.InputSource;
  import org.xml.sax.ContentHandler;
  import org.apache.cocoon.xml.EmbeddedXMLPipe;
  import org.apache.cocoon.environment.Source;
  import org.apache.cocoon.components.xslt.XSLTProcessor;
  import org.apache.cocoon.components.parser.Parser;
  import org.apache.cocoon.ProcessingException;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.Component;
  
  /**
   * <code>XScriptObject</code> is the root class implemented by all the
   * object types in XScript. Every XScriptObject is essentially a
   * Source object.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since August  4, 2001
   */
  public abstract class XScriptObject implements Source
  {
    /**
     * The creation date of this <code>XScriptObject</code>.
     */
    Date lastModifiedDate = new Date();
  
    /**
     * The <code>XScriptManager</code> object that's managing this
     * <code>XScriptObject</code> value.
     */
    XScriptManager xscriptManager;
    
    /**
     * Creates a new <code>XScriptObject</code> instance.
     *
     * @param manager a <code>XScriptManager</code> value
     */
    public XScriptObject(XScriptManager manager)
    {
      this.xscriptManager = manager;
    }
    
    /**
     * Apply the XSLT stylesheet defined by the <code>stylesheet</code>
     * variable to this instance. Return the result of the
     * transformation as an <code>XScriptObject</code>.
     *
     * @param source a <code>XScriptObject</code> value
     * @param stylesheet a <code>XScriptObject</code> value
     * @param params a <code>Parameters</code> value containing optional
     * arguments to be passed to the XSLT processor.
     * @param result a <code>Result</code> value. This is where the
     * result of the XSLT processing will be placed.
     * @exception IllegalArgumentException if an error occurs
     * @exception ProcessingException if an error occurs
     */
    public XScriptObject transform(XScriptObject stylesheet, Parameters params)
      throws IllegalArgumentException, ProcessingException
    {
      try {
        CharArrayWriter writer = new CharArrayWriter();
        StreamResult result = new StreamResult(writer);
        
        ComponentManager manager = xscriptManager.getComponentManager();
        XSLTProcessor transformer
          = (XSLTProcessor)manager.lookup(XSLTProcessor.ROLE);
        
        transformer.transform(this, stylesheet, params, result);
  
        manager.release((Component)transformer);
  
        return new XScriptObjectResult(xscriptManager, writer.toString());
      }
      catch (ComponentException ex) {
        throw new ProcessingException(ex);
      }
    }
  
    public void toSAX(ContentHandler handler)
      throws SAXException
    {
      try {
        EmbeddedXMLPipe newHandler = new EmbeddedXMLPipe(handler);
  
        ComponentManager manager = xscriptManager.getComponentManager();
        Parser parser = (Parser)manager.lookup(Parser.ROLE);
        
        parser.setContentHandler(newHandler);
        InputSource source = getInputSource();
        parser.parse(source);
  
        manager.release(parser);
      }
      catch (Exception ex) {
        throw new SAXException(ex);
      }
    }
  
    /* The Source interface methods. */
  
    public long getLastModified()
    {
      return lastModifiedDate.getTime();
    }
  
    public abstract long getContentLength();
  
    public InputSource getInputSource()
      throws ProcessingException, IOException
    {
      return new InputSource(getInputStream());
    }
  
    public void recycle()
    {
    }
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptObjectFromURL.java
  
  Index: XScriptObjectFromURL.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xscript;
  
  import java.net.URLConnection;
  import java.net.URL;
  import java.io.InputStream;
  import java.io.IOException;
  
  import org.apache.cocoon.components.url.URLFactory;
  import org.apache.cocoon.ProcessingException;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.Component;
  
  /**
   * An <code>XScriptObject</code> created from the contents of a URL.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since August 30, 2001
   */
  public class XScriptObjectFromURL extends XScriptObject
  {
    /**
     * The URL containing to obtain the source from.
     */
    String systemId;
  
    /**
     * The content length.
     */
    int contentLength;
  
    /**
     * When the content of the URL was last modified.
     */
    long lastModified;
    
    public XScriptObjectFromURL(XScriptManager manager, String systemId)
    {
      super(manager);
      this.systemId = systemId;
    }
  
    public InputStream getInputStream()
      throws ProcessingException, IOException
    {
      try {
        ComponentManager manager = xscriptManager.getComponentManager();
        URLFactory urlFactory = (URLFactory)manager.lookup(URLFactory.ROLE);
        URL url = urlFactory.getURL(systemId);
        URLConnection conn = url.openConnection();
        InputStream is = conn.getInputStream();
        contentLength = conn.getContentLength();
        manager.release((Component)urlFactory);
  
        return is;
      }
      catch (ComponentException ex) {
        throw new ProcessingException(ex);
      }
    }
  
    public long getContentLength()
    {
      return contentLength;
    }
  
    public long getLastModified()
    {
      return lastModified;
    }
  
    public String getSystemId()
    {
      // FIXME: generate a real system id to represent this object
      return "file:/";
    }
  
    public void recycle()
    {
    }
  
    public String toString()
    {
      return "XScriptObjectFromURL(systemId = " + systemId + ")";
    }
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptObjectInlineXML.java
  
  Index: XScriptObjectInlineXML.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xscript;
  
  import java.util.Stack;
  import java.io.StringReader;
  import java.io.StringBufferInputStream;
  import java.io.InputStream;
  import java.io.IOException;
  
  import org.xml.sax.helpers.DefaultHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.InputSource;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.Attributes;
  
  import org.apache.cocoon.ProcessingException;
  
  /**
   * An <code>XScriptObject</code> created from an inline XML fragment.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since July 7, 2001
   */
  public class XScriptObjectInlineXML extends XScriptObject
  {
    StringBuffer stringBuffer;
    StringBufferContentHandler streamHandler;
  
    public XScriptObjectInlineXML(XScriptManager manager)
    {
      super(manager);
      stringBuffer = new StringBuffer();
      stringBuffer.append("<?xml version=\"1.0\"?>\n\n");
      streamHandler = new StringBufferContentHandler(stringBuffer);
    }
    
    public XScriptObjectInlineXML(XScriptManager manager,
                                  StringBuffer stringBuffer)
    {
      super(manager);
      this.stringBuffer = stringBuffer;
      streamHandler = new StringBufferContentHandler(stringBuffer);
    }
  
    public InputStream getInputStream()
      throws ProcessingException, IOException
    {
      return new StringBufferInputStream(stringBuffer.toString());
    }
    
    public ContentHandler getContentHandler()
    {
      return streamHandler;
    }
  
    public void setNextContentHandler(ContentHandler handler)
    {
      streamHandler.setNextContentHandler(handler);
    }
  
    public String toString()
    {
      return stringBuffer.toString();
    }
  
    public long getContentLength()
    {
      return stringBuffer.length();
    }
  
    public String getSystemId()
    {
      // FIXME: Implement a URI scheme to be able to refer to XScript
      // variables by URI
      return "file:/";
    }
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptObjectResult.java
  
  Index: XScriptObjectResult.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xscript;
  
  import java.io.ByteArrayInputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import javax.xml.transform.Result;
  import javax.xml.transform.sax.SAXResult;
  import javax.xml.transform.stream.StreamResult;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.url.URLFactory;
  
  /**
   * An <code>XScriptObject</code> created from a JAXP
   * <code>Result</code> object.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since   August 30, 2001
   */
  public class XScriptObjectResult extends XScriptObject
  {
    /**
     * The XML content of this object.
     */
    String content;
    
    public XScriptObjectResult(XScriptManager manager, String content)
    {
      super(manager);
      this.content = content;
    }
  
    public InputStream getInputStream()
      throws ProcessingException, IOException
    {
      return new ByteArrayInputStream(content.getBytes());
    }
  
    public long getContentLength()
    {
      return content.length();
    }
  
    public String getSystemId()
    {
      // FIXME: Return a real URL that identifies this object
      return "file:/";
    }
  
    public String toString()
    {
      return "XScriptObjectResult: " + content;
    }
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/XScriptVariableScope.java
  
  Index: XScriptVariableScope.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.cocoon.components.xscript;
  
  import java.util.HashMap;
  
  /**
   * <code>XScriptVariableScope</code> maintains variables in a given
   * scope. A variable has a unique name within a scope, but multiple
   * variables with the same name can exist within different scopes.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @since August 4, 2001
   */
  public class XScriptVariableScope
  {
    /**
     * The variables store; each entry is <code>String</code>
     * representing the name of the variable, with the corresponding
     * value an {@link XScriptObject}.
     */
    HashMap variables = new HashMap();
  
    /**
     * Define a new variable or overwrite the value of an existing
     * variable in this scope.
     *
     * @param name a <code>String</code> value
     * @param value a <code>{@link XScriptObject}</code> value
     */
    public synchronized void put(String name, XScriptObject value)
    {
      variables.put(name, value);
    }
  
    /**
     * Obtains the value of the XScript <code>name</code> variable.
     *
     * @param name a <code>String</code> value
     * @return a <code>{@link XScriptObject}</code> value
     */
    public synchronized XScriptObject get(String name)
      throws IllegalArgumentException
    {
      if (!variables.containsKey(name))
        throw new IllegalArgumentException("Cannot find variable '"
                                           + name + "'!");
      return (XScriptObject)variables.get(name);
    }
  
    /**
     * Removes the XScript variable that's accessible via
     * <code>name</code>.
     *
     * @param name a <code>String</code> value
     */
    public synchronized void remove(String name)
    {
      variables.remove(name);
    }
  
    public synchronized boolean defines(String name)
    {
      return variables.containsKey(name);
    }
  }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/xslt/copy-of.xsl
  
  Index: copy-of.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <!-- Author: Ovidiu Predescu "ovidiu@cup.hp.com" -->
  <!-- Date: July 27, 2001 -->
  <!-- Implement the xscript:copy-of support -->
  
  <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xalan="http://xml.apache.org/xalan"
    xmlns:saxon="http://icl.com/saxon"
    exclude-result-prefixes="xalan"
    >
  
    <xsl:param name="xpath"/>
  
    <xsl:template match="/">
      <xsl:choose>
        <xsl:when test="contains(system-property('xsl:vendor-url'), 'xalan')">
          <xsl:copy-of select="xalan:evaluate($xpath)"/>
        </xsl:when>
        <xsl:when test="contains(system-property('xsl:vendor-url'), 'saxon')">
          <xsl:copy-of select="saxon:evaluate($xpath)"/>
        </xsl:when>
      </xsl:choose>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/components/xscript/xslt/value-of.xsl
  
  Index: value-of.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <!-- Author: Ovidiu Predescu "ovidiu@cup.hp.com" -->
  <!-- Date: July 27, 2001 -->
  <!-- Implement the xscript:value-of support -->
  
  <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xalan="http://xml.apache.org/xalan"
    xmlns:saxon="http://icl.com/saxon"
    exclude-result-prefixes="xalan">
  
    <xsl:param name="xpath"/>
  
    <xsl:template match="/">
      <xsl:choose>
        <xsl:when test="contains(system-property('xsl:vendor-url'), 'xalan')">
          <xsl:value-of select="xalan:evaluate($xpath)"/>
        </xsl:when>
        <xsl:when test="contains(system-property('xsl:vendor-url'), 'saxon')">
          <xsl:value-of select="saxon:evaluate($xpath)"/>
        </xsl:when>
      </xsl:choose>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.37      +17 -0     xml-cocoon2/webapp/cocoon.xconf
  
  Index: cocoon.xconf
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/cocoon.xconf,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- cocoon.xconf	2001/10/05 12:29:23	1.36
  +++ cocoon.xconf	2001/10/10 20:53:57	1.37
  @@ -150,6 +150,11 @@
       <parameter name="servlet-name" value="*.jsp"/>
     </jsp-engine>
   
  +  <xscript>
  +    <parameter name="xscript:copy-of" value="resource://org/apache/cocoon/components/xscript/xslt/copy-of.xsl"/>
  +    <parameter name="xscript:value-of" value="resource://org/apache/cocoon/components/xscript/xslt/value-of.xsl"/>
  +  </xscript>
  +
     <programming-languages>
       <java-language name="java">
         <!-- compiler parameter specifies which class to use to compile Java.
  @@ -262,6 +267,18 @@
             <parameter name="prefix" value="capture"/>
             <parameter name="uri" value="http://apache.org/cocoon/capture/1.0"/>
             <parameter name="href" value="resource://org/apache/cocoon/components/language/markup/xsp/java/capture.xsl"/>
  +        </builtin-logicsheet>
  +
  +        <builtin-logicsheet>
  +          <parameter name="prefix" value="xscript"/>
  +          <parameter name="uri" value="http://apache.org/xsp/xscript/1.0"/>
  +          <parameter name="href" value="resource://org/apache/cocoon/components/language/markup/xsp/java/xscript.xsl"/>
  +        </builtin-logicsheet>
  +
  +        <builtin-logicsheet>
  +          <parameter name="prefix" value="soap"/>
  +          <parameter name="uri" value="http://apache.org/xsp/soap/3.0"/>
  +          <parameter name="href" value="resource://org/apache/cocoon/components/language/markup/xsp/java/soap.xsl"/>
           </builtin-logicsheet>
   
         </target-language>
  
  
  
  1.55      +9 -0      xml-cocoon2/webapp/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/sitemap.xmap,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- sitemap.xmap	2001/10/05 07:15:20	1.54
  +++ sitemap.xmap	2001/10/10 20:53:57	1.55
  @@ -613,6 +613,15 @@
       <map:serialize type="xml"/>
      </map:match>
   
  +   <!-- ======================== XScript Samples ========================= -->
  +   <map:match pattern="xscript/*">
  +     <map:generate type="serverpages" src="docs/samples/xscript/{1}.xsp"/>
  +     <map:transform src="stylesheets/dynamic-page2html.xsl">
  +       <map:parameter name="view-source" value="docs/samples/xscript/{1}.xsp"/>
  +     </map:transform>
  +     <map:serialize/>
  +   </map:match>
  +
      <!-- ========================== Tidy Samples ============================== -->
      
      <map:match pattern="yahoo">
  
  
  
  1.15      +21 -0     xml-cocoon2/webapp/docs/samples/samples.xml
  
  Index: samples.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/webapp/docs/samples/samples.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- samples.xml	2001/09/07 23:00:28	1.14
  +++ samples.xml	2001/10/10 20:53:57	1.15
  @@ -149,6 +149,27 @@
      </sample>
     </group>
   
  +  <group name="XScript and SOAP">
  +   <sample name="Simple Sample" href="xscript/simple">
  +       An simple sample for XScript.
  +   </sample>
  +   <sample name="SOAP Stock Quote Example 1" href="xscript/soap-getquote1">
  +       This page demonstrates the SOAP logicsheet for
  +       Cocoon2. It accesses a SOAP service that provides stock quotes
  +       and displays the result.
  +   </sample>
  +   <sample name="SOAP Sample 2" href="xscript/soap-getquote2">
  +       This example uses an inline XSLT stylesheet and an
  +       XScript transform instruction to extract the stock
  +       price.
  +   </sample>
  +   <sample name="SOAP Sample 3" href="xscript/soap-getquote3">
  +       This is yet another example of the XScript and SOAP
  +       logicsheets. This sample is very similar with
  +       SOAP Sample 2, except that the stylesheet is defined in an external file.
  +   </sample>
  +  </group>
  +
     <group name="Web Applications">
      <sample name="Protected Area" href="protected/login">
             An example web-application built around db-authenticator,
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/xscript/simple.xsp
  
  Index: simple.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    Date: September 18, 2001
   -->
  
  <xsp:page language="java"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
    xmlns:xscript="http://apache.org/xsp/xscript/1.0"
  >
  
    <page>
  
      <title>Inline XScript variable</title>
  
      <content>
  
        <para>
          This is a simple XSP page demonstrating how to work with
          inline XScript variables. This example show how one can create
          and later refer to an XScript variable.
        </para>
  
        <xscript:variable name="my-var">
          <b>123</b>
        </xscript:variable>
  
        <para>
          The content of the XScript variable is: <xscript:get name="my-var"/>.
        </para>
  
        <para>
          We now remove the Xscript variable "my-var", and try to access
          it again. You should see an error message indicating it's no
          longer available.
        </para>
  
        <xscript:remove name="my-var"/>
  
        <xscript:get name="my-var"/>
  
      </content>
  
    </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/xscript/soap-getquote1.xsl
  
  Index: soap-getquote1.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    Date: October 9, 2001
   -->
  
  <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:n="urn:xmethods-delayed-quotes"
    exclude-result-prefixes="soap n"
    >
  
    <xsl:template match="soap:Envelope">
      <b><xsl:value-of select="soap:Body/n:getQuoteResponse/Result"/></b>
    </xsl:template>
  
    <xsl:template match="@*|*|text()|processing-instruction()">
      <!-- Catch all template. Just pass along unmodified everything we
           don't handle. -->
      <xsl:copy>
        <xsl:apply-templates select="@*|*|text()|processing-instruction()"/>
      </xsl:copy>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/xscript/soap-getquote1.xsp
  
  Index: soap-getquote1.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    Date: October 9, 2001
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
    xmlns:xscript="http://apache.org/xsp/xscript/1.0"
    xmlns:soap="http://apache.org/xsp/soap/3.0"
    >
    
    <page>
  
     <title>SOAP Stock Quote Example 1</title>
  
     <content>
  
     <xsp:logic>
      String symbol = request.getParameter("symbol");
  
      if (symbol == null || symbol.equals("")) {
  
         <para>This page demonstrates the SOAP logicsheet for
         Cocoon2. It accesses a SOAP service that provides stock quotes
         and displays the result.</para>
  
         <para>The SOAP result is placed in the generated page, and the
         stock price is extracted from it using an external XSLT
         stylesheet. Compare this approach with the one used in
         <code>soap-getquote2.xsp</code>, which uses an internal XScript
         stylesheet to extract the stock price.</para>
  
         <para>Please enter the stock ticker: </para>
         <form href="soap-getquote">
           <input name="symbol" type="text" value="HWP"/>
           <input value="Do it!" type="submit"/>
         </form>
      }
      else {
        <para>The stock price for <xsp:expr>symbol</xsp:expr> is 
  
        <soap:call url="http://services.xmethods.net:80/soap">
          <ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes">
            <soap:enc/>
            <symbol xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><xsp-request:get-parameter name="symbol"/></symbol>
          </ns1:getQuote>
        </soap:call>
  
        </para>
  
        <form href="soap-getquote">
          <input value="Back" type="submit"/>
        </form>
      }
    </xsp:logic>
  
    </content>
  
    </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/xscript/soap-getquote2.xsp
  
  Index: soap-getquote2.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    Date: October 9, 2001
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
    xmlns:xscript="http://apache.org/xsp/xscript/1.0"
    xmlns:soap="http://apache.org/xsp/soap/3.0"
    >
    
    <page>
  
     <title>SOAP Stock Quote Example 2</title>
  
     <content>
  
     <xsp:logic>
      String symbol = request.getParameter("symbol");
  
      if (symbol == null || symbol.equals("")) {
  
         <para>This page demonstrates the SOAP logicsheet for
         Cocoon2. It accesses a SOAP service that provides stock quotes
         and displays the result.</para>
  
         <para>This example uses an inline XSLT stylesheet and an
         XScript <code>transform</code> instruction to extract the stock
         price. Compare this with the approach used in
         <code>soap-getquote1.xsp</code>, which uses a sitemap XSLT
         transformer to achieve the same thing.</para>
  
         <para>Please enter the stock ticker: </para>
         <form href="soap-getquote">
           <input name="symbol" type="text" value="HWP"/>
           <input value="Do it!" type="submit"/>
         </form>
      }
      else {
        <para>The stock price for <xsp:expr>symbol</xsp:expr> is 
  
      <xscript:variable name="soap-result">
        <soap:call url="http://services.xmethods.net:80/soap">
          <ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes">
            <soap:enc/>
            <symbol xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><xsp-request:get-parameter name="symbol"/></symbol>
          </ns1:getQuote>
        </soap:call>
      </xscript:variable>
  
      <xscript:variable name="stylesheet">
        <xsl:stylesheet
          version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
          xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
          xmlns:n="urn:xmethods-delayed-quotes"
          exclude-result-prefixes="soap n"
        >
  
          <xsl:template match="/">
            <b><xsl:value-of select="/soap:Envelope/soap:Body/n:getQuoteResponse/Result"/></b>
          </xsl:template>
        </xsl:stylesheet>
      </xscript:variable>
  
      <xscript:transform name="soap-result" stylesheet="stylesheet"/>
  
        </para>
  
        <form href="soap-getquote">
          <input value="Back" type="submit"/>
        </form>
      }
    </xsp:logic>
  
    </content>
  
    </page>
  </xsp:page>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/xscript/soap-getquote3.xsl
  
  Index: soap-getquote3.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    Date: October 9, 2001
   -->
  
  <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:n="urn:xmethods-delayed-quotes"
    exclude-result-prefixes="soap n"
    >
  
    <xsl:template match="/">
      <b><xsl:value-of select="/soap:Envelope/soap:Body/n:getQuoteResponse/Result"/></b>
    </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-cocoon2/webapp/docs/samples/xscript/soap-getquote3.xsp
  
  Index: soap-getquote3.xsp
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <!--
    Author: Ovidiu Predescu "ovidiu@cup.hp.com"
  
    Date: October 9, 2001
   -->
  
  <xsp:page
    language="java"
    xmlns:xsp="http://apache.org/xsp"
    xmlns:xsp-request="http://apache.org/xsp/request/2.0"
    xmlns:xscript="http://apache.org/xsp/xscript/1.0"
    xmlns:soap="http://apache.org/xsp/soap/3.0"
    >
    
    <page>
  
     <title>SOAP Stock Quote Example 3</title>
  
     <content>
  
     <xsp:logic>
      String symbol = request.getParameter("symbol");
  
      if (symbol == null || symbol.equals("")) {
  
         <para>This page demonstrates the SOAP logicsheet for
         Cocoon2. It accesses a SOAP service that provides stock quotes
         and displays the result.</para>
  
         <para>This is yet another example of the XScript and SOAP
         logicsheets. This sample is very similar with
         <code>soap-getquote2.xsp</code>, except that the stylesheet is
         defined in an external file.
         </para>
  
         <para>Please enter the stock ticker: </para>
         <form href="soap-getquote">
           <input name="symbol" type="text" value="HWP"/>
           <input value="Do it!" type="submit"/>
         </form>
      }
      else {
        <para>The stock price for <xsp:expr>symbol</xsp:expr> is 
  
      <xscript:variable name="soap-result">
        <soap:call url="http://services.xmethods.net:80/soap">
          <ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes">
            <soap:enc/>
            <symbol xsi:type="xsd:string" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><xsp-request:get-parameter name="symbol"/></symbol>
          </ns1:getQuote>
        </soap:call>
      </xscript:variable>
  
      <xscript:variable name="stylesheet"
                        href="docs/samples/xscript/soap-getquote3.xsl"/>
  
      <xscript:transform name="soap-result" stylesheet="stylesheet"/>
  
        </para>
  
        <form href="soap-getquote">
          <input value="Back" type="submit"/>
        </form>
      }
    </xsp:logic>
  
    </content>
  
    </page>
  </xsp:page>
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message