Quite a lot more improvement on robustness and formatting

This commit is contained in:
sb 2008-05-09 16:12:12 +00:00
parent 0e392e6bb3
commit 7642f0bf02
4 changed files with 995 additions and 949 deletions

View file

@ -20,8 +20,8 @@
explicitly state the permission, even if it is 'none'.
$Author: sb $
$Revision: 1.8 $
$Date: 2008-02-28 14:52:08 $
$Revision: 1.9 $
$Date: 2008-05-09 16:12:12 $
-->
<xsl:stylesheet version="1.0"
@ -64,7 +64,7 @@
* THIS FILE IS AUTOMATICALLY GENERATED AND SHOULD NOT
* BE MANUALLY EDITED.
*
* Generated using adl2canonical.xslt <xsl:value-of select="substring('$Revision: 1.8 $', 12)"/>
* Generated using adl2canonical.xslt <xsl:value-of select="substring('$Revision: 1.9 $', 12)"/>
*
***************************************************************************
</xsl:comment>
@ -407,14 +407,15 @@
NOTE that n-to-n properties cannot currently be user-distinct and are
therefore not inspected -->
<xsl:template name="unroll-user-distinct">
<xsl:for-each select="ancestor::adl:entity/descendant::adl:property[@distinct='user']">
<xsl:for-each select="ancestor::adl:entity/descendant::adl:property[@distinct='user' or @distinct='all']">
<field>
<xsl:attribute name="property">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:apply-templates select="adl:prompt"/>
<xsl:apply-templates select="adl:help"/>
</field>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

View file

@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes
$Author: sb $
$Revision: 1.23 $
$Date: 2008-05-08 17:26:44 $
$Revision: 1.24 $
$Date: 2008-05-09 16:12:12 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -71,7 +71,7 @@
//
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.24 $', 10)"/>
//
// This file is automatically generated; DO NOT EDIT IT.
//
@ -128,7 +128,7 @@ namespace <xsl:value-of select="$controllerns"/> {
//
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.23 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.24 $', 10)"/>
//
// This file is automatically generated; DO NOT EDIT IT.
//
@ -164,8 +164,10 @@ namespace <xsl:value-of select="$controllerns"/> {
///
/// DO NOT EDIT THIS FILE!
/// &lt;/summary&gt;
[ Layout("<xsl:value-of select="$layout-name"/>"), Rescue("<xsl:value-of select="$rescue-name"/>"),
ControllerDetails("<xsl:value-of select="@name"/>", Area = "<xsl:value-of select="$area-name"/>")]
[ Layout("<xsl:value-of select="$layout-name"/>"),
Rescue("<xsl:value-of select="$rescue-name"/>"),
ControllerDetails("<xsl:value-of select="@name"/>",
Area = "<xsl:value-of select="$area-name"/>")]
public partial class <xsl:value-of select="@name"/>Controller : <xsl:value-of select="concat( 'Abstract', /adl:application/@name, 'Controller')"/> {
<xsl:if test="adl:form">
@ -182,27 +184,27 @@ namespace <xsl:value-of select="$controllerns"/> {
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
List&lt;string&gt; messages = new List&lt;string&gt;();
// A 'newborn' instance can be updated even if the current user doesn't have
// update permissions, seeing that we use an update operation to set the
// field values and save the entity.
/* A 'newborn' instance can be updated even if the current user doesn't have
* update permissions, seeing that we use an update operation to set the
* field values and save the entity. */
Boolean isnewborn = false;
<xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="."/>
<xsl:with-param name="initialise-locals" select="'true'"/>
</xsl:call-template>
/* the instance (record) of type <xsl:value-of select="@name"/> we're dealing with */
<xsl:value-of select="concat($entityns, '.', @name)"/> record = null;
try {
<xsl:if test="adl:property[@distinct='system' or @distinct='all']">
/* declare a list of <xsl:value-of select="@name"/> to use in
* distinctness checks */
IList&lt;<xsl:value-of select="@name"/>&gt; matches = null;
/* a criteria object to use in distinctness checks */
ICriteria matchCriteria = null;
</xsl:if>
record = FetchRecord( hibernator);
<xsl:apply-templates select="descendant::adl:property"/>
if ( HasNoErrors()) {
if ( record == null) {
/* it seems to be new, create persistent object */
/* it seems to be new, create persistent object - if the user is permitted to */
AssertUserCanCreate();
try {
@ -239,7 +241,7 @@ namespace <xsl:value-of select="$controllerns"/> {
}
catch ( FormatException) {
/* failed to parse a number - not wholly unexpected, since it's most likely
that an empty string was passed in */
* that an empty string was passed in */
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>();
}
catch ( NullReferenceException) {
@ -255,12 +257,15 @@ namespace <xsl:value-of select="$controllerns"/> {
ITransaction tx = null;
if ( ! isnewborn) {
// isnewborn cannot be true unless we've already checked user can create
// so no need to do it again here
/* isnewborn cannot be true unless we've already checked user can create
* so no need to do it again here */
AssertUserCanUpdate();
}
try {
/* begin our atomic transaction */
tx = hibernator.BeginTransaction();
/* actually update the record */
BindObjectInstance( record, ParamStore.Form, "instance");
@ -272,7 +277,7 @@ namespace <xsl:value-of select="$controllerns"/> {
if ( ! String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'i18n.instance.', @name)"/>"])){
/* there's an uninitialised message for this slot */
Message mess = record.<xsl:value-of select="@name"/>;
if ( mess == null){
if ( mess == null) {
mess = new Message();
}
hibernator.Save( mess);
@ -287,7 +292,6 @@ namespace <xsl:value-of select="$controllerns"/> {
}
</xsl:for-each>
</xsl:if>
<xsl:for-each select="descendant::adl:property[@type='entity']">
/* for properties of type 'entity', it should not be necessary to do anything
* special - BindObjectInstance /should/ do it all. Unfortunately it sometimes
@ -299,7 +303,7 @@ namespace <xsl:value-of select="$controllerns"/> {
{
record.<xsl:value-of select="@name"/> = <xsl:call-template name="fetch-property-instance">
<xsl:with-param name="property" select="."/>
<xsl:with-param name="valuename" select="concat( 'instance.', @name)"/>
<xsl:with-param name="valuename" select="@name"/>
</xsl:call-template>;
}
</xsl:when>
@ -356,19 +360,18 @@ namespace <xsl:value-of select="$controllerns"/> {
foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>)
{
<!-- TODO: this could definitely be made more efficient -->
if ( index.Equals( itemId))
{
found = true;
break;
}
}
} /* foreach ( string index... */
if ( ! found)
{
record.<xsl:value-of select="@name"/>.Remove( item);
}
} /* foreach ( string index... */
} /* foreach ( <xsl:value-of select="@entity"/> item ... */
/* then add any on the included list which are not already members */
foreach ( string index in <xsl:value-of select="concat(@name, 'Values')"/>)
@ -403,6 +406,7 @@ namespace <xsl:value-of select="$controllerns"/> {
else {
throw new ApplicationException( String.Format( "No record of type <xsl:value-of select="@name"/> with the key values supplied was found"));
}
} /* if ( HasNoErrors()) */
} /* try */
catch ( DataSuitabilityException dse)
{
@ -419,21 +423,16 @@ namespace <xsl:value-of select="$controllerns"/> {
PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN];
</xsl:if>
if ( HasNoErrors())
if ( ! HasNoErrors())
{
/* the session may be polluted; create a new session */
NHibernateHelper.CloseSession();
hibernator = NHibernateHelper.GetCurrentSession(<xsl:if test="$authentication-layer = 'Database'">
Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]
</xsl:if>);
Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
<xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="."/>
<xsl:with-param name="initialise-locals" select="'false'"/>
</xsl:call-template>
}
record = FetchRecord( hibernator);
} /* if ( ! HasNoErrors()) */
<xsl:call-template name="formmenus">
<xsl:with-param name="form" select="adl:form[position()=1]"/>
</xsl:call-template>
@ -455,19 +454,13 @@ namespace <xsl:value-of select="$controllerns"/> {
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
string reallydelete = Params["reallydelete"];
if ( "true".Equals( reallydelete))
if ( "true".Equals( Params["reallydelete"]))
{
<xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="."/>
<xsl:with-param name="initialise-locals" select="'true'"/>
</xsl:call-template>
<xsl:value-of select="concat($entityns, '.', @name)"/> record = FetchRecord( hibernator);
if ( record != null)
{
hibernator.Delete( record);
hibernator.Flush();
}
else
@ -524,52 +517,96 @@ namespace <xsl:value-of select="$controllerns"/> {
RenderViewWithFailover(view + ".vm", view + ".auto.vm");
}
</xsl:if>
/// &lt;summary&gt;
/// Fetch the record represented by the values in the current Form
/// &lt;/summary&gt;
protected <xsl:value-of select="concat($entityns, '.', @name)"/> FetchRecord(ISession hibernator) {
/* the instance (record) of type <xsl:value-of select="@name"/> we're dealing with */
<xsl:value-of select="concat($entityns, '.', @name)"/> record = null;
/* whether we have valid values for all the key fields */
bool allkeys = true;
/* check whether values for all key slots have been passed in; if so, we're probably dealing with an
* existing record */
<xsl:for-each select="adl:key/adl:property">
if ( String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
allkeys = false;
} else if ( "<xsl:value-of select="concat('$instance.', @name)"/>".Equals( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
/* nasty artefact of NVelocity forms - default 'null value' is dollar followed by fieldname */
allkeys = false;
}
</xsl:for-each>
if ( allkeys){
/* it's (probably) existing, retrieve it */
record = hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @name)"/>))
<xsl:for-each select="adl:key/adl:property">
<xsl:variable name="basetype">
<xsl:call-template name="base-type">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:variable>
.Add( Expression.Eq( "<xsl:value-of select="@name"/>", <xsl:choose>
<xsl:when test="$basetype='integer'">
Int32.Parse( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"])
</xsl:when>
<xsl:when test="$basetype='entity'">
<!-- Maybe TODO: this doesn't work recursively - if an entity has a key which is an entity
and the key of that entity is an entity, you're on your own, mate! -->
<xsl:variable name="keyentity" select="@entity"/>
<xsl:variable name="keyenttype">
<xsl:call-template name="primary-key-csharp-type">
<xsl:with-param name="entity" select="//adl:entity[@name=$keyentity]"/>
</xsl:call-template>
</xsl:variable>
hibernator.CreateCriteria( typeof( <xsl:value-of select="$keyenttype"/>))
.Add(Expression.Eq( "<xsl:value-of select="//adl:entity[@name=$keyentity]/adl:key/adl:property[position()=1]/@name"/>",<xsl:choose>
<xsl:when test="$keyenttype = 'int'">
Int32.Parse( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"])
</xsl:when>
<xsl:otherwise>
Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"]
</xsl:otherwise>
</xsl:choose>))
.UniqueResult&lt;<xsl:value-of select="$keyenttype"/>&gt;()
</xsl:when>
<xsl:otherwise>
Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"]
</xsl:otherwise>
</xsl:choose>))
</xsl:for-each>
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', @name)"/>&gt;();
}
return record;
}
}
}
/* ---- [ cut here: next file 'junk'] ------------------------- */
</xsl:template>
<xsl:template match="adl:property[@required='true']">
if ( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>" ] == null)
<xsl:template match="adl:property">
<xsl:if test="@required='true'">
if ( String.IsNullOrEmpty( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>" ]))
{
AddError( <xsl:choose>
<xsl:when test="adl:ifmissing[@locale=$locale]">
<xsl:apply-templates select="adl:ifmissing[@locale=$locale]"/>
</xsl:when>
<xsl:otherwise>"You must supply a value for <xsl:value-of select="@name"/>"</xsl:otherwise>
<xsl:otherwise>
"You must supply a value for <xsl:value-of select="@name"/>"
</xsl:otherwise>
</xsl:choose>);
}
<xsl:choose>
<xsl:when test="adl:property[@distinct='system']">
</xsl:if>
<xsl:if test="@distinct='system' or @distinct='all'">
<xsl:call-template name="check-property-value-distinct">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:when test="adl:property[@distinct='all']">
<xsl:call-template name="check-property-value-distinct">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="adl:property[@distinct='system']">
<xsl:call-template name="check-property-value-distinct">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template match="adl:property[@distinct='all']">
<xsl:call-template name="check-property-value-distinct">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:template>
<!-- suppress properties otherwise -->
<xsl:template match="adl:property"/>
<xsl:template match="adl:ifmissing">
"<xsl:value-of select="normalize-space(.)"/>"
</xsl:template>
@ -600,7 +637,7 @@ namespace <xsl:value-of select="$controllerns"/> {
if ( command.Equals( "<xsl:value-of select="@verb"/>"))
{
/* NOTE: You must write an implementation of this verb in a
manually maintained partial class file for this class */
* manually maintained partial class file for this class */
<xsl:value-of select="@verb"/>();
}
else
@ -611,10 +648,7 @@ namespace <xsl:value-of select="$controllerns"/> {
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
<xsl:call-template name="fetch-instance">
<xsl:with-param name="entity" select="ancestor::adl:entity"/>
<xsl:with-param name="initialise-locals" select="'true'"/>
</xsl:call-template>
<xsl:value-of select="concat($entityns, '.', ancestor::adl:entity/@name)"/> record = FetchRecord( hibernator);
<xsl:if test="$authentication-layer = 'Database'">
PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN];
@ -783,21 +817,17 @@ namespace <xsl:value-of select="$controllerns"/> {
</xsl:when>
<xsl:when test="$property/@distinct = 'system' or $property/@distinct='all'">
/* <xsl:value-of select="$property/@name"/> should be distinct: check that it is */
matches =
hibernator.CreateCriteria(typeof(<xsl:value-of select="$property/ancestor::adl:entity/@name"/>))
<xsl:choose>
<xsl:when test="$basetype='string'">
.Add(Expression.Eq("<xsl:value-of select="$property/@name"/>", Form["<xsl:value-of select="concat('instance.', $property/@name)"/>"]))
</xsl:when>
<xsl:when test="$basetype='integer'">
.Add(Expression.Eq("<xsl:value-of select="$property/@name"/>", Int32.Parse( Form["<xsl:value-of select="concat('instance.', $property/@name)"/>"])))
</xsl:when>
matchCriteria =
hibernator.CreateCriteria(typeof(<xsl:value-of select="$property/ancestor::adl:entity/@name"/>));
matchCriteria.Add(Expression.Eq("<xsl:value-of select="$property/@name"/>", <xsl:choose>
<xsl:when test="$basetype='string'">Form["<xsl:value-of select="concat('instance.', $property/@name)"/>"]</xsl:when>
<xsl:when test="$basetype='integer'">Int32.Parse( Form["<xsl:value-of select="concat('instance.', $property/@name)"/>"])</xsl:when>
<xsl:when test="$basetype='entity'">
.Add(Expression.Eq("<xsl:value-of select="$property/@name"/>",
<xsl:call-template name="fetch-property-instance">
<xsl:with-param name="property" select="."/>
<xsl:with-param name="valuename" select="adl:property[position()=1]/@name"/>
</xsl:call-template>))
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
@ -805,30 +835,33 @@ namespace <xsl:value-of select="$controllerns"/> {
with base type <xsl:value-of select="$basetype"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="$property/ancestor::adl:entity/adl:key">
.Add(Expression.Not(Expression.Eq("<xsl:value-of select="adl:property[position()=1]/@name"/>",<xsl:choose>
<xsl:when test="@type='entity'">
</xsl:choose>));
if ( record != null) {
/* i.e. we do have values for each of our key fields... */
<xsl:for-each select="$property/ancestor::adl:entity/adl:key/adl:property[position()=1]">
<xsl:variable name="keybasetype">
<xsl:call-template name="base-type">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:variable>
matchCriteria.Add(Expression.Not(Expression.Eq("<xsl:value-of select="@name"/>",<xsl:choose>
<xsl:when test="$keybasetype='entity'">
<xsl:call-template name="fetch-property-instance">
<!-- recurse -->
<xsl:with-param name="property" select="."/>
<xsl:with-param name="valuename" select="adl:property[position()=1]/@name"/>
<xsl:with-param name="valuename" select="@name"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="@type='integer'">
Int32.Parse( Form["<xsl:value-of select="adl:property[position()=1]/@name"/>"])
</xsl:when>
<xsl:otherwise>
Form["<xsl:value-of select="adl:property[position()=1]/@name"/>"]
</xsl:otherwise>
</xsl:choose>)))
<xsl:when test="$keybasetype='integer'">Int32.Parse( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])</xsl:when>
<xsl:otherwise>Form["<xsl:value-of select="concat( 'instance.', @name)"/>"]</xsl:otherwise>
</xsl:choose>)));
</xsl:for-each>
.List&lt;<xsl:value-of select="$property/ancestor::adl:entity/@name"/>&gt;();
}
if ( matches.Count > 0)
if ( matchCriteria.List&lt;<xsl:value-of select="$property/ancestor::adl:entity/@name"/>&gt;().Count > 0)
{
throw new
DataNotDistinctException(
AddError(
String.Format("There is already a {0} with the {1} '{2}'",
"<xsl:value-of select="$property/ancestor::adl:entity/@name"/>", "<xsl:value-of select="$property/@name"/>", Form["<xsl:value-of select="concat('instance.', $property/@name)"/>"]));
}
@ -979,71 +1012,18 @@ namespace <xsl:value-of select="$controllerns"/> {
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', $property/@entity)"/>))
<xsl:for-each select="//adl:entity[@name=$property/@entity]/adl:key/adl:property">
.Add(Expression.Eq("<xsl:value-of select="@name"/>",<xsl:choose>
<xsl:when test="@type='entity'"><xsl:call-template name="fetch-property-instance">
<xsl:when test="@type='entity'">
<xsl:call-template name="fetch-property-instance">
<!-- recurse -->
<xsl:with-param name="property" select="."/>
<xsl:with-param name="valuename" select="$valuename"/>
</xsl:call-template></xsl:when>
<xsl:when test="@type='integer'">Int32.Parse( Form["<xsl:value-of select="$valuename"/>"])</xsl:when>
<xsl:otherwise>Form["<xsl:value-of select="$valuename"/>"]</xsl:otherwise>
</xsl:call-template>
</xsl:when>
<xsl:when test="@type='integer'">Int32.Parse( Form["<xsl:value-of select="concat( 'instance.', $valuename)"/>"])</xsl:when>
<xsl:otherwise>Form["<xsl:value-of select="concat( 'instance.', $valuename)"/>"]</xsl:otherwise>
</xsl:choose>))
</xsl:for-each>
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', @entity)"/>&gt;()
</xsl:template>
<!-- this is essentially just a macro and doesn't really do anything clever.
It finds the current instance of the entity for which this is the controller,
and returns it as the value of a variable (which must have been previously
declared) called 'record' -->
<xsl:template name="fetch-instance">
<xsl:param name="entity"/>
<xsl:param name="initialise-locals" select="'false'"/>
/* check whether values for all key slots have been passed in; if so, we're probably dealing with an
* existing record */
<xsl:if test="$initialise-locals = 'true'">
/* the instance (record) of type <xsl:value-of select="$entity/@name"/> we're dealing with */
<xsl:value-of select="concat($entityns, '.', $entity/@name)"/> record = null;
/* whether we have valid values for all the key fields */
bool allkeys = true;
</xsl:if>
<xsl:for-each select="$entity/adl:key/adl:property">
if ( String.IsNullOrEmpty( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
allkeys = false;
}
else if ( "<xsl:value-of select="concat('$instance.', @name)"/>".Equals( Form["<xsl:value-of select="concat( 'instance.', @name)"/>"])) {
/* nasty artefact of NVelocity forms - default 'null value' is dollar followed by fieldname */
allkeys = false;
}
</xsl:for-each>
if ( allkeys){
/* it's (probably) existing, retrieve it */
record = hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', $entity/@name)"/>))
<xsl:for-each select="$entity/adl:key/adl:property">
<xsl:variable name="basetype">
<xsl:call-template name="base-type">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:variable>
.Add( Expression.Eq( "<xsl:value-of select="@name"/>", <xsl:choose>
<xsl:when test="$basetype='integer'">Int32.Parse( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"])</xsl:when>
<xsl:when test="$basetype='entity'">
<!-- Maybe TODO: this doesn't work recursively - if an entity has a key which is an entity
and the key of that entity is an entity, you're on your own, mate! -->
<xsl:variable name="keyentity" select="@entity"/>
<xsl:variable name="keyenttype">
<xsl:call-template name="primary-key-csharp-type">
<xsl:with-param name="entity" select="//adl:entity[@name=$keyentity]"/>
</xsl:call-template>
</xsl:variable>
hibernator.CreateCriteria( typeof( <xsl:value-of select="$keyenttype"/>))
.Add(Expression.Eq( "<xsl:value-of select="//adl:entity[@name=$keyentity]/adl:key/adl:property[position()=1]/@name"/>",<xsl:choose>
<xsl:when test="$keyenttype = 'int'">Int32.Parse( Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"])</xsl:when>
<xsl:otherwise>Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"]</xsl:otherwise></xsl:choose>))
.UniqueResult&lt;<xsl:value-of select="$keyenttype"/>&gt;()</xsl:when>
<xsl:otherwise>Form[ "<xsl:value-of select="concat( 'instance.', @name)"/>"]</xsl:otherwise></xsl:choose>))
</xsl:for-each>
.UniqueResult&lt;<xsl:value-of select="concat( $entityns, '.', $entity/@name)"/>&gt;();
}
</xsl:template>
</xsl:stylesheet>
</xsl:stylesheet>

View file

@ -8,8 +8,8 @@
Transform ADL into entity classes
$Author: sb $
$Revision: 1.12 $
$Date: 2008-03-12 13:46:10 $
$Revision: 1.13 $
$Date: 2008-05-09 16:12:12 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -61,7 +61,7 @@
stored to CVS -->
<xsl:variable name="transform-rev1"
select="substring( '$Revision: 1.12 $', 11)"/>
select="substring( '$Revision: 1.13 $', 11)"/>
<xsl:variable name="transform-revision"
select="substring( $transform-rev1, 0, string-length( $transform-rev1) - 1)"/>
@ -220,8 +220,8 @@
get {
StringBuilder result = new StringBuilder();
<xsl:choose>
<xsl:when test="descendant::adl:property[@distinct='user']">
<xsl:for-each select="descendant::adl:property[@distinct='user']">
<xsl:when test="descendant::adl:property[@distinct='user' or @distinct='all']">
<xsl:for-each select="descendant::adl:property[@distinct='user' or @distinct='all']">
<xsl:choose>
<xsl:when test="@type='message'">
if ( <xsl:value-of select="@name"/> != null)

View file

@ -12,8 +12,8 @@
Transform ADL into velocity view templates
$Author: sb $
$Revision: 1.15 $
$Date: 2008-04-18 10:06:47 $
$Revision: 1.16 $
$Date: 2008-05-09 16:12:12 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
Whitespace (or lack of it) is significant! -->
@ -29,7 +29,13 @@
<xsl:param name="locale" select="en-UK"/>
<!-- whether or not to auto-generate site navigation - by default, don't -->
<xsl:param name="generate-site-navigation"/>
<xsl:param name="generate-site-navigation" select="'false'"/>
<!-- whether or not to layout errors - they may be in the default layout -->
<xsl:param name="show-errors" select="'false'"/>
<!-- whether or not to layout messages - they may be in the default layout -->
<xsl:param name="show-messages" select="'false'"/>
<!-- the current state of play is that we can only generate views with permissions for one group.
TODO: this isn't how it's supposed to be. It's supposed to be that at service time the system
@ -46,9 +52,14 @@
for making sure it loads all the scripts, etc, that an ADL controller
expects. -->
<xsl:param name="layout-name" select="adl-default-layout"/>
<!-- bug 1800 : the name of the area (i.e. URL path part) to use -->
<xsl:param name="area-name" select="auto"/>
<xsl:template match="adl:application">
<output>
<!-- 'output' is a dummy wrapper root tag to make the entire output work as
an XML document; the actual output later gets cut into chunks and the
wrapper tag is discarded. -->
<xsl:apply-templates select="adl:entity"/>
<!-- make sure extraneous junk doesn't get into the last file generated,
by putting it into a separate file -->
@ -71,7 +82,7 @@
</xsl:template>
<!-- generate views for an entity, assuming a non-empty layout - i.e.
I'm not responsible for head, or for the body tag -->
I'm not responsible for the html, the head, or for the body tag -->
<xsl:template match="adl:entity" mode="non-empty-layout">
<xsl:variable name="keyfield">
<xsl:choose>
@ -93,14 +104,15 @@
Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>,
generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.15 $', 10)"/>
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.16 $', 10)"/>
</xsl:comment>
<xsl:call-template name="maybe-delete">
<xsl:with-param name="entity" select="."/>
</xsl:call-template>
</xsl:template>
<!-- generate views for an entity, assuming a non-empty layout -->
<!-- generate views for an entity, assuming an empty layout
(i.e. I'm responsible for html, head and body tags) -->
<xsl:template match="adl:entity" mode="empty-layout">
<xsl:variable name="keyfield">
<xsl:choose>
@ -115,7 +127,9 @@
<xsl:apply-templates select="adl:list" mode="empty-layout"/>
<xsl:text>
</xsl:text>
<xsl:comment> [ cut here: next file '<xsl:value-of select="concat( @name, '/maybedelete.auto.vm')"/>' ] </xsl:comment>
<xsl:comment>
[ cut here: next file '<xsl:value-of select="concat( @name, '/maybedelete.auto.vm')"/>' ]
</xsl:comment>
<xsl:text>
</xsl:text>
<html>
@ -127,7 +141,7 @@
Auto generated Velocity maybe-delete form for <xsl:value-of select="@name"/>,
generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.15 $', 10)"/>
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.16 $', 10)"/>
</xsl:comment>
<xsl:call-template name="install-scripts"/>
</head>
@ -213,7 +227,7 @@
Auto generated Velocity <xsl:value-of select="@name"/> form for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL.
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.15 $', 10)"/>
Generated using adl2views.xslt <xsl:value-of select="substring( '$Revision: 1.16 $', 10)"/>
</xsl:comment>
#capturefor( title)
#if ( $instance)
@ -223,6 +237,7 @@
#end
#end
#capturefor( headextras)
<xsl:call-template name="head"/>
<script type='text/javascript' language='JavaScript1.2'>
var panes = new Array( <xsl:for-each select='adl:fieldgroup'>
"<xsl:value-of select='@name'/>"<xsl:choose>
@ -294,9 +309,11 @@
#capturefor(bodyattributes)
onload="performInitialisation()"
#end
<xsl:call-template name="top"/>
<xsl:call-template name="form-content">
<xsl:with-param name="form" select="."/>
</xsl:call-template>
<xsl:call-template name="foot"/>
</xsl:template>
<xsl:template match="adl:form" mode="empty-layout">
@ -334,7 +351,7 @@
Auto generated Velocity form for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL.
Generated using adl2views.xsl <xsl:value-of select="substring( '$Revision: 1.15 $', 10)"/>
Generated using adl2views.xsl <xsl:value-of select="substring( '$Revision: 1.16 $', 10)"/>
</xsl:comment>
<xsl:call-template name="install-scripts"/>
<script type='text/javascript' language='JavaScript1.2'>
@ -421,26 +438,32 @@
<xsl:param name="form"/>
<xsl:variable name="formname" select="$form/@name"/>
<div class="content">
<xsl:if test="$show-errors = 'true'">
#if ( $errors)
#if ( $errors.Count != 0)
<ul class="errors">
#foreach( $e in $errors)
#foreach($e in $errors)
#if($e.Message)
<li>$t.Error($e)</li>
#else
<li>$t.Enc($e)</li>
#end
#end
</ul>
#end
#end
</xsl:if>
<xsl:if test="$show-messages = 'true'">
#if( $messages)
#if ( $messages.Count != 0)
<div class="information">
<ul class="information">
#foreach ( $message in $messages)
<p>
$message
</p>
<li>$message</li>
#end
</div>
</ul>
#end
#end
</xsl:if>
<form method="post" onsubmit="invokeSubmitHandlers( this)">
<xsl:attribute name="action">
<xsl:value-of select="concat( $formname, 'SubmitHandler.rails')"/>
@ -478,6 +501,7 @@
switchtab( '<xsl:value-of select="@name"/>'); return false;
</xsl:attribute>
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@name"/>
</xsl:call-template>
</a>
@ -548,6 +572,7 @@
</xsl:attribute>
<h3>
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@name"/>
</xsl:call-template>
</h3>
@ -650,6 +675,7 @@
<xsl:for-each select="//adl:entity[@name=$farent]//adl:property[@name=$fieldprop]/adl:option">
#if ( $item.<xsl:value-of select="$fieldprop"/> == '<xsl:value-of select="@value"/>')
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@value"/>
</xsl:call-template>
#end
@ -676,16 +702,12 @@
<xsl:otherwise>
<!-- properties not listed, so therefore presumably all. -->
<tr>
<xsl:for-each select="//adl:entity[@name=$farent]//adl:property[@distinct='user']">
<xsl:for-each select="//adl:entity[@name=$farent]//adl:property[@distinct='user' or @distinct='all']">
<th>
<xsl:choose>
<xsl:when test="adl:prompt[@locale=$locale]">
<xsl:value-of select="adl:prompt[@locale=$locale]/@prompt"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@name"/>
</xsl:call-template>
</th>
</xsl:for-each>
<th>-</th>
@ -698,7 +720,7 @@
#set( $oddity = "odd")
#end
<tr class="$oddity">
<xsl:for-each select="//adl:entity[@name=$farent]//adl:property[@distinct='user']">
<xsl:for-each select="//adl:entity[@name=$farent]//adl:property[@distinct='user' or @distinct='all']">
<td>
<xsl:variable name="fieldprop" select="@name"/>
<xsl:choose>
@ -713,6 +735,7 @@
<xsl:for-each select="adl:option">
#if ( $item.<xsl:value-of select="$fieldprop"/> == '<xsl:value-of select="@value"/>')
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@value"/>
</xsl:call-template>
#end
@ -763,6 +786,7 @@
<xsl:value-of select="@verb"/>
</xsl:attribute>
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@verb"/>
</xsl:call-template>
</button>
@ -802,6 +826,7 @@
</xsl:attribute>
<td class="label">
${FormHelper.LabelFor( "instance.<xsl:value-of select="@name"/>", "<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@name"/>
</xsl:call-template>")}
</td>
@ -840,6 +865,7 @@
</xsl:attribute>
<td class="label" rowspan="2">
${FormHelper.LabelFor( "instance.<xsl:value-of select="@name"/>", "<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@name"/>
</xsl:call-template>")}
</td>
@ -906,14 +932,10 @@
<xsl:value-of select="$oddness"/>
</xsl:attribute>
<td class="label" rowspan="2">
${FormHelper.LabelFor( "instance.<xsl:value-of select="@name"/>", "<xsl:choose>
<xsl:when test="adl:prompt[@locale = $locale]">
<xsl:apply-templates select="adl:prompt[@locale = $locale]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>")}
${FormHelper.LabelFor( "instance.<xsl:value-of select="@name"/>", "<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@name"/>
</xsl:call-template>")}
</td>
<td class="widget" colspan="2">
${FormHelper.TextArea( "instance.<xsl:value-of select="@name"/>", "%{rows='8', cols='60', title='<xsl:value-of select="$if-missing"/>'}")}
@ -1249,14 +1271,10 @@
<xsl:attribute name="value">
<xsl:value-of select="@value"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="adl:prompt[@locale=$locale]">
<xsl:value-of select="adl:prompt[@locale=$locale]/@prompt"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@value"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@value"/>
</xsl:call-template>
</option>
</xsl:template>
@ -1286,9 +1304,14 @@
#capturefor( title)
<xsl:value-of select="normalize-space( concat( 'List ', $withpluralsuffix))"/>
#end
#capturefor( headextras)
<xsl:call-template name="head"/>
#end
<xsl:call-template name="top"/>
<xsl:call-template name="list">
<xsl:with-param name="list" select="."/>
</xsl:call-template>
<xsl:call-template name="foot"/>
</xsl:template>
<!-- layout of a list assuming an empty layout -->
@ -1300,7 +1323,8 @@
<xsl:text>
</xsl:text>
<xsl:variable name="withpluralsuffix">
<!-- English-laguage syntactic sugar of entity name -->
<!-- English-laguage syntactic sugar of entity name. TODO (bug 1896): This really /must/ not be here.
some means of doing i18n syntactic sugar needs to be spliced in. -->
<xsl:choose>
<xsl:when test="../@name='Person'">People</xsl:when>
<xsl:when test="starts-with( substring(../@name, string-length(../@name) ), 's')">
@ -1323,7 +1347,7 @@
Auto generated Velocity list for <xsl:value-of select="ancestor::adl:entity/@name"/>,
generated from ADL.
Generated using adl2listview.xsl <xsl:value-of select="substring( '$Revision: 1.15 $', 10)"/>
Generated using adl2listview.xsl <xsl:value-of select="substring( '$Revision: 1.16 $', 10)"/>
</xsl:comment>
<xsl:call-template name="install-scripts"/>
</head>
@ -1393,14 +1417,10 @@
<th>
<xsl:variable name="pname" select="@property"/>
<xsl:variable name="property" select="$list/ancestor::adl:entity//adl:property[@name=$pname]"/>
<xsl:choose>
<xsl:when test="$property/adl:prompt[@locale=$locale]">
<xsl:value-of select="$property/adl:prompt[@locale=$locale]/@prompt"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@property"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="$property"/>
<xsl:with-param name="fallback" select="@property"/>
</xsl:call-template>
</th>
</xsl:for-each>
<xsl:for-each select="$list/ancestor::adl:entity/adl:form">
@ -1478,16 +1498,12 @@
<xsl:otherwise>
<!-- properties are not 'listed' -->
<tr>
<xsl:for-each select="$list/ancestor::adl:entity//adl:property[@distinct='user' and not( @type='link' or @type='list')]">
<xsl:for-each select="$list/ancestor::adl:entity//adl:property[(@distinct='user' or @distinct='all') and not( @type='link' or @type='list')]">
<th>
<xsl:choose>
<xsl:when test="adl:prompt[@locale=$locale]">
<xsl:value-of select="adl:prompt[@locale=$locale]/@prompt"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="showprompt">
<xsl:with-param name="node" select="."/>
<xsl:with-param name="fallback" select="@name"/>
</xsl:call-template>
</th>
</xsl:for-each>
<xsl:for-each select="$list/ancestor::adl:entity/adl:form">
@ -1501,7 +1517,7 @@
#set( $oddity = "odd")
#end
<tr class="$oddity">
<xsl:for-each select="$list/ancestor::adl:entity//adl:property[@distinct='user']">
<xsl:for-each select="$list/ancestor::adl:entity//adl:property[@distinct='user' or @distinct='all']">
<td>
<xsl:choose>
<xsl:when test="@type = 'date'">
@ -1586,17 +1602,65 @@
${ScriptsHelper.InstallScript( "Panes")}
</xsl:template>
<xsl:template match="navigation">
foobar!
</xsl:template>
<xsl:template match="adl:navigation">
<xsl:variable name="pagename" select="@name"/>
<ul class="generatednav">
<xsl:choose>
<xsl:when test="@include='list'">
<xsl:for-each select="//adl:entity[adl:list[@name=$pagename]]">
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat( '$siteRoot', '/', $area-name, '/', @name, '/', adl:list[position()=1]/@name, '.rails')"/>
</xsl:attribute>
<xsl:value-of select="@name"/>
</a>
</li>
</xsl:for-each>
</xsl:when>
<xsl:when test="@include='form'">
<xsl:for-each select="//adl:entity[adl:form[@name=$pagename]]">
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat( '$siteRoot', '/', $area-name, '/', @name, '/', adl:list[position()=1]/@name, '.rails')"/>
</xsl:attribute>
<xsl:value-of select="@name"/>
</a>
</li>
</xsl:for-each>
</xsl:when>
<xsl:when test="@include='page'">
<xsl:for-each select="//adl:entity[adl:page[@name=$pagename]]">
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat( '$siteRoot', '/', $area-name, '/', @name, '/', adl:list[position()=1]/@name, '.rails')"/>
</xsl:attribute>
<xsl:value-of select="@name"/>
</a>
</li>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</ul>
</xsl:template>
<xsl:template name="head">
<xsl:choose>
<xsl:when test="adl:head">
<xsl:for-each select="adl:head/*">
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="//adl:content/adl:head/*">
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
@ -1606,22 +1670,22 @@
<xsl:choose>
<xsl:when test="adl:top">
<xsl:for-each select="adl:top/*">
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="//adl:content/adl:top/*">
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$generate-site-navigation">
<xsl:if test="$generate-site-navigation = 'true'">
<ul class="generatednav">
<xsl:for-each select="//adl:entity[adl:list[@name='list']]">
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat( '$siteRoot', '/auto/', @name, '/', adl:list[position()=1]/@name, '.rails')"/>
<xsl:value-of select="concat( '$siteRoot', '/', $area-name, '/', @name, '/', adl:list[position()=1]/@name, '.rails')"/>
</xsl:attribute>
<xsl:value-of select="@name"/>
</a>
@ -1635,12 +1699,12 @@
<xsl:choose>
<xsl:when test="adl:foot">
<xsl:for-each select="adl:foot/*">
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="//adl:content/adl:foot/*">
<xsl:copy-of select="."/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
@ -1652,6 +1716,7 @@
<xsl:template name="showprompt">
<xsl:param name="fallback" select="Unknown"/>
<xsl:param name="node" select="."/>
<xsl:param name="locale" select="'en-GB'"/>
<xsl:choose>
<xsl:when test="$node/adl:prompt[@locale=$locale]">
<xsl:value-of select="$node/adl:prompt[@locale=$locale][1]/@prompt"/>