new stuff for the xform part
What already works:
-on the first view the XSP page passes the SAX events
to a new DOMObject. This holds the instance data of
the XForm.
-the XForm instances are saved inside the session
-the XForm instance data are inserted into the XSP page via XMLFragment interface
-getValue( String XPath )
-setValue( String XPath )
-DOMObject is now an interface AbstractDOMObject is the implementation
(might become DOMObjectImpl)
-now we have a DOMObjectOutputWrapper that opens
the door for backend mapping like beans or whatever.
Here is sitemap snipped for first tests:
<map:match pattern="xform.xhtml">
<map:generate type="serverpages" src="docs/samples/xform/xform.xml">
<!-- select which subpage to view -->
<map:parameter name="page" value="fillin1"/>
</map:generate>
<map:transform src="stylesheets/xform2html.xsl"/>
<map:serialize type="xml"/>
</map:match>
The stylesheet is not much more then a test. Probably Peter will
already have a real one :)
I again attached all necessary files.
regards
--
Torsten
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page
language="java"
xmlns:xsp="http://apache.org/xsp"
xmlns:xform="http://www.w3.org/2001/06/xforms"
xmlns:sel="http://apache.org/xsp/sel/1.0"
>
<root>
<xform:xform id="orderForm">
<xform:instance>
<order>
<firstname/>
<lastname/>
<email>[EMAIL PROTECTED]</email>
<city/>
<country/>
<newsletter/>
</order>
</xform:instance>
</xform:xform>
<sel:selector type="sitemap" parameter="page">
<sel:case name="fillin1">
<p>Please enter your name and email address</p>
<xform:xform id="orderForm">
<xform:textbox ref="order/firstname">
<caption>Firstname</caption>
</xform:textbox>
<xform:textbox ref="order/lastname">
<caption>Lastname</caption>
</xform:textbox>
<xform:textbox ref="order/email">
<caption>Email</caption>
</xform:textbox>
</xform:xform>
</sel:case>
<sel:case name="fillin2">
<p>Please enter where you are located</p>
<xform:textbox ref="order/city" xform="orderForm">
<caption>City</caption>
</xform:textbox>
<xform:selectOne ref="order/country" xform="orderForm">
<caption>Country</caption>
<hint>Please select the country you are from</hint>
<choices>
<item value="none">Please select</item>
<item value="DE">Germany</item>
<item value="US">USA</item>
<item value="UK">United Kingdom</item>
</choices>
</xform:selectOne>
<xform:selectBoolean ref="order/newsletter" xform="orderForm">
<caption>Newsletter</caption>
<choices>
<item value="true">Yes</item>
<item value="false">No</item>
</choices>
</xform:selectBoolean>
</sel:case>
<sel:case name="overview">
<xform:xform id="orderForm">
<p>Is everything correct?</p>
<xform:output ref="order/firstname"/>
<xform:output ref="order/lastname"/>
<xform:output ref="order/email"/>
<xform:output ref="order/city"/>
<xform:output ref="order/country"/>
<xform:output ref="order/newsletter"/>
</xform:xform>
<xform:submitInfo target="" method="POST"/>
</sel:case>
<sel:case name="thanks">
<p>Thank you!</p>
</sel:case>
<sel:otherwise>
<p>Hm.. how did you get here?</p>
</sel:otherwise>
</sel:selector>
</root>
</xsp:page>
AbstractDOMObject.java
DOMObject.java
DOMObjectOutputWrapper.java
<?xml version="1.0"?>
<!--
============================================================================
The Apache Software License, Version 1.2
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-->
<!--
* @author <a href="mailto:[EMAIL PROTECTED]">Torsten Curdt</a>
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsp="http://apache.org/xsp"
xmlns:xform="http://www.w3.org/2001/06/xforms"
>
<xsl:template match="xsp:page">
<xsp:page>
<xsl:copy-of select="@*"/>
<xsp:structure>
<xsp:include>org.apache.cocoon.environment.Request</xsp:include>
<xsp:include>org.apache.cocoon.environment.Session</xsp:include>
<xsp:include>org.apache.cocoon.xml.DOMObject</xsp:include>
<xsp:include>org.apache.cocoon.xml.AbstractDOMObject</xsp:include>
<xsp:include>org.xml.sax.ContentHandler</xsp:include>
<xsl:for-each select=".//*[@class]">
<xsp:include><xsl:value-of select="@class"/></xsp:include>
</xsl:for-each>
</xsp:structure>
<xsl:call-template name="defineForms"/>
<xsp:logic>
public boolean hasContentChanged( org.apache.cocoon.environment.Request request ){
return(true);
}
</xsp:logic>
<xsl:apply-templates/>
</xsp:page>
</xsl:template>
<!--##################################################################################-->
<xsl:template match="xsp:page/*[not(self::xsp:*)]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsp:logic>
/* START <xsl:value-of select="name()"/> */
</xsp:logic>
<xsp:logic>
Session _xform_session = request.getSession(true);
</xsp:logic>
<xsl:call-template name="getForms"/>
<xsl:apply-templates/>
<xsl:call-template name="setForms"/>
<xsp:logic>
/* STOP <xsl:value-of select="name()"/> */
</xsp:logic>
</xsl:copy>
</xsl:template>
<!--##################################################################################-->
<xsl:template match="xform:instance">
<xsl:variable name="formname" select="parent::xform:xform/@id"/>
<xsp:logic>
/* START <xsl:value-of select="name()"/> */
</xsp:logic>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsp:logic>
/* pass the XML into the DOMObject */
if (!_xform_<xsl:value-of select="$formname"/>.isFinished()){
ContentHandler oldHandler = this.contentHandler;
try {
this.contentHandler = _xform_<xsl:value-of select="$formname"/>.getContentHandler();
<xsl:apply-templates/>
_xform_<xsl:value-of select="$formname"/>.markFinished();
}
finally {
this.contentHandler = oldHandler;
}
}
/* insert the DOMObject XML representation / current instance data */
_xform_<xsl:value-of select="$formname"/>.toSAX(this.contentHandler);
</xsp:logic>
</xsl:copy>
<xsp:logic>
/* STOP <xsl:value-of select="name()"/> */
</xsp:logic>
</xsl:template>
<!--##################################################################################-->
<xsl:template name="defineForm">
<xsl:variable name="formname" select="."/>
<xsp:logic>
/* XForm <xsl:value-of select="$formname"/> */
</xsp:logic>
<xsl:variable name="class">
<xsl:choose>
<xsl:when test="../@class"><xsl:value-of select="../@class"/></xsl:when>
<xsl:otherwise>AbstractDOMObject</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsp:logic>
<xsl:value-of select="$class"/> _xform_<xsl:value-of select="$formname"/> = null;
</xsp:logic>
</xsl:template>
<!--##################################################################################-->
<xsl:template name="defineForms">
<xsp:logic>
/* START defineForms */
</xsp:logic>
<xsl:variable name="requiredforms" select=".//xform:*/@xform|.//xform:xform/@id"/>
<xsl:for-each select="$requiredforms">
<xsl:variable name="formname" select="."/>
<xsl:if test="generate-id(.) = generate-id($requiredforms[.=$formname][1])">
<xsl:call-template name="defineForm"/>
</xsl:if>
</xsl:for-each>
<xsp:logic>
/* STOP defineForms */
</xsp:logic>
</xsl:template>
<!--##################################################################################-->
<xsl:template name="getForm">
<xsl:variable name="formname" select="."/>
<xsp:logic>
/* XForm <xsl:value-of select="$formname"/> */
</xsp:logic>
<xsl:variable name="class">
<xsl:choose>
<xsl:when test="../@class"><xsl:value-of select="../@class"/></xsl:when>
<xsl:otherwise>AbstractDOMObject</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsp:logic>
_xform_<xsl:value-of select="$formname"/> = (<xsl:value-of select="$class"/>) _xform_session.getAttribute("<xsl:value-of select="$formname"/>");
if(_xform_<xsl:value-of select="$formname"/> == null){
_xform_<xsl:value-of select="$formname"/> = new <xsl:value-of select="$class"/>();
getLogger().debug("xform taglib created the <xsl:value-of select="$class"/> [<xsl:value-of select="$formname"/>]");
}
</xsp:logic>
</xsl:template>
<!--##################################################################################-->
<xsl:template name="getForms">
<xsp:logic>
/* START getForms */
</xsp:logic>
<xsl:variable name="requiredforms" select=".//xform:*/@xform|.//xform:xform/@id"/>
<xsl:for-each select="$requiredforms">
<xsl:variable name="formname" select="."/>
<xsl:if test="generate-id(.) = generate-id($requiredforms[.=$formname][1])">
<xsl:call-template name="getForm"/>
</xsl:if>
</xsl:for-each>
<xsp:logic>
/* STOP getForms */
</xsp:logic>
</xsl:template>
<!--##################################################################################-->
<xsl:template name="setForm">
<xsl:variable name="formname" select="."/>
<xsp:logic>
/* XForm <xsl:value-of select="$formname"/> */
</xsp:logic>
<xsl:variable name="class">
<xsl:choose>
<xsl:when test="../@class"><xsl:value-of select="../@class"/></xsl:when>
<xsl:otherwise>DOMObject</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsp:logic>
_xform_session.setAttribute("<xsl:value-of select="$formname"/>",_xform_<xsl:value-of select="$formname"/>);
</xsp:logic>
</xsl:template>
<!--##################################################################################-->
<xsl:template name="setForms">
<xsp:logic>
/* START setForms */
</xsp:logic>
<xsl:variable name="requiredforms" select=".//xform:*/@xform|.//xform:xform/@id"/>
<xsl:for-each select="$requiredforms">
<xsl:variable name="formname" select="."/>
<xsl:if test="generate-id(.) = generate-id($requiredforms[.=$formname][1])">
<xsl:call-template name="setForm"/>
</xsl:if>
</xsl:for-each>
<xsp:logic>
/* STOP setForms */
</xsp:logic>
</xsl:template>
<!--##################################################################################-->
<xsl:template match="@*|node()" priority="-2"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy></xsl:template>
<xsl:template match="text()" priority="-1"><xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<!--
============================================================================
The Apache Software License, Version 1.2
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Cocoon" and "Apache Software Foundation" must not be used to
endorse or promote products derived from this software without prior
written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
-->
<!--
* @author <a href="mailto:[EMAIL PROTECTED]">Torsten Curdt</a>
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsp="http://apache.org/xsp"
xmlns:sel="http://apache.org/xsp/sel/1.0"
exclude-result-prefixes="sel"
>
<xsl:template match="xsp:page">
<xsp:page>
<xsl:copy-of select="@*"/>
<xsl:for-each select=".//sel:case|.//sel:otherwise">
<xsp:logic>
private void _<xsl:value-of select="parent::sel:selector/@parameter"/>_<xsl:value-of select="@name"/>_case() throws SAXException {
AttributesImpl xspAttr = new AttributesImpl();
<xsl:apply-templates/>
}
</xsp:logic>
</xsl:for-each>
<xsl:apply-templates select="*[not(name()='sel:case' or name()='sel:otherwise')]"/>
</xsp:page>
</xsl:template>
<xsl:template match="sel:selector">
<xsp:logic>
String selection = parameters.getParameter("<xsl:value-of select="@parameter"/>", null);
</xsp:logic>
<xsl:for-each select="sel:case">
<xsp:logic>
<xsl:if test="position() != 1"> else </xsl:if>
if ("<xsl:value-of select="@name"/>".equals(selection)){
_<xsl:value-of select="parent::sel:selector/@parameter"/>_<xsl:value-of select="@name"/>_case();
}
</xsp:logic>
</xsl:for-each>
<xsl:for-each select="sel:otherwise">
<xsp:logic>
else {
_<xsl:value-of select="parent::sel:selector/@parameter"/>_<xsl:value-of select="@name"/>_case();
}
</xsp:logic>
</xsl:for-each>
</xsl:template>
<!--##################################################################################-->
<xsl:template match="@*|node()" priority="-2"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy></xsl:template>
<xsl:template match="text()" priority="-1"><xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xform="http://www.w3.org/2001/06/xforms"
xmlns:xalan="http://xml.apache.org/xalan"
>
<xsl:template match="xform:instance"/>
<xsl:template match="xform:xform">
<xsl:apply-templates/>
</xsl:template>
exclude-result-prefixes="xform xalan"
<xsl:template match="xform:textbox">
<xsl:variable name="instance" select="/root/xform:xform/xform:instance"/>
<xsl:variable name="prefix">
<xsl:choose>
<xsl:when test="@xform">
<xsl:value-of select="@xform"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="ancestor::xform:xform/@id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="caption"/>
<input type="text" name="{$prefix}/{@ref}" value="{xalan:evaluate(concat('$instance/',@ref))}"/>
</xsl:template>
<xsl:template match="@*|node()" priority="-2"><xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy></xsl:template>
<xsl:template match="text()" priority="-1"><xsl:value-of select="."/></xsl:template>
</xsl:stylesheet>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]