(Giacomo, Colin, sorry if you received this multiple times. It looks
like somebody decided that posting messages with attachments on
cocoon-dev is a bad thing, so they disabled it. I got confused reading
the error message, and kept re-sending it without realizing the true
nature of the fault.)
Hi,
The following patch fixes two things and adds some things for some
future planned functionality.
fix 1:
Fix compatibility issue with Saxon. The namespace used to identify
XSLTFactoryLoader was Xalan specific. I changed this to use the
recommended way to do such things. Giacomo, please take a look at
this one.
fix 2:
I removed some duplicate code used to pass sitemap parameters.
future improvement:
This is based on a discussion I had with Colin Britton at ApacheCon
2001, in Santa Clara, earlier this year.
I've added support for generating the file name and line number in
the generated sitemap_xmap.java. This information identifies the XML
source code that was used to generate the code. I plan to use this
to better identify sitemap problems. Hopefully the mechanism
described below can also be used for XSPs.
The general idea is that there are two kinds of errors that can
happen. The first one is a compilation problem, where the generated
Java code is invalid. The second type of errors happens at runtime,
when a stack trace is generated. Somewhere in the stack trace there
is information about where in the sitemap or the XSP generated Java
code the error happened.
We can use the file name and line number reported in the above two
errors to go back in the generated Java code, identify the file and
line in the XML document just before that, which is the location in
the XML source document from which that code was generated. We can
report then this exact location in the XML document that caused the
error.
To support this improvement we need to have the ability of generating
the file and line information in XSLT. Saxon supports this. For Xalan
I've created a patch and submitted it to xalan-dev. It looks however
that I need to rework it, because they are going to drop the today's
so-called STREE model of representing the source document. The
replacement DTM model is not compatible with STREE, so my patch is
useless and needs rework. I hope I can finish this sometime this week
or later next week.
As for the Cocoon functionality described above, I plan to implement
the support code in the ProgramGenerator. Any comments on this
functionality are more than welcome.
Regards,
--
Ovidiu Predescu <[EMAIL PROTECTED]>
http://orion.nsr.hp.com/ (inside HP's firewall only)
http://www.geocities.com/SiliconValley/Monitor/7464/ (GNU, Emacs, other stuff)
[Patch inserted inline in the message]
---
xml-cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java/sitemap.xsl
Wed Jun 6 11:25:01 2001
+++ Cocoon2/src/org/apache/cocoon/components/language/markup/sitemap/java/sitemap.xsl
+ Wed Jun 6 14:37:04 2001
@@ -13,7 +13,7 @@
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:map="http://apache.org/cocoon/sitemap/1.0"
-
xmlns:java="http://xml.apache.org/xslt/java/org.apache.cocoon.sitemap.XSLTFactoryLoader"
exclude-result-prefixes="java"
+ xmlns:XSLTFactoryLoader="org.apache.cocoon.sitemap.XSLTFactoryLoader"
version="1.0">
<xsl:output method="text"/>
@@ -26,12 +26,40 @@
<xsl:variable name="nsprefix">map</xsl:variable>
- <!-- this variable holds the factory loader used to get at the code
matcher/selector factories
- are producing
- FIXME(GP): This approach seem Xalan dependant and not (yet) portable
+ <!--
+ this variable holds the factory loader used to get at the code
+ matcher/selector factories are producing
+
+ ovidiu: use the class name as the namespace to identify the
+ class. This is supposedly portable across XSLT implementations.
-->
- <xsl:variable name="factory-loader" select="java:new()"/>
+ <xsl:variable
+ name="factory-loader"
+ select="XSLTFactoryLoader:new()"
+ xmlns:XSLTFactoryLoader="org.apache.cocoon.sitemap.XSLTFactoryLoader"/>
+
+ <!-- Define the XSLT processor. Currently only Saxon and Xalan are
+ recognized. -->
+ <xsl:variable name="xslt-processor">
+ <xsl:choose>
+ <xsl:when test="contains(system-property('xsl:vendor-url'),
+'xalan')">xalan</xsl:when>
+ <xsl:when test="contains(system-property('xsl:vendor-url'),
+'saxon')">saxon</xsl:when>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:template name="line-number">
+ <xsl:choose>
+ <xsl:when test="$xslt-processor = 'saxon'"
+ xmlns:saxon="http://icl.com/saxon">
+//file <xsl:value-of select="saxon:system-id()"/>
+//line <xsl:value-of select="saxon:line-number()"/>
+</xsl:when>
+ <xsl:otherwise>
+//line numbers not supported with <xsl:value-of select="$xslt-processor"/>
+</xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
<!-- this template wraps the hole content within a single <code> element which
the xsp core logicsheet uses to build the java source code out of it
@@ -115,18 +143,20 @@
<!-- Generate matchers which implements CodeFactory -->
<xsl:for-each select="/map:sitemap/map:components/map:matchers/map:matcher">
+<xsl:call-template name="line-number"/>
<xsl:variable name="src">
<xsl:value-of select="@src"/>
</xsl:variable>
- <xsl:if test="java:isFactory($factory-loader, string($src))">
+ <xsl:if test="XSLTFactoryLoader:isFactory($factory-loader, string($src))">
<xsl:variable name="type" select="translate(@name, '- ', '__')"/>
<xsl:variable name="default" select="$type = ../@default"/>
<xsl:variable name="config"><xsl:copy-of select="."/></xsl:variable>
- private Map <xsl:value-of select="$type"/>Match (<xsl:value-of
select="java:getParameterSource($factory-loader, string($src),$config)"/> pattern, Map
objectModel, Parameters parameters) {
- <xsl:value-of select="java:getMethodSource($factory-loader,
string($src),$config)"/>
+ private Map <xsl:value-of select="$type"/>Match (<xsl:value-of
+select="XSLTFactoryLoader:getParameterSource($factory-loader,
+string($src),$config)"/> pattern, Map objectModel, Parameters parameters) {
+ <xsl:value-of select="XSLTFactoryLoader:getMethodSource($factory-loader,
+string($src),$config)"/>
}
<!-- process all map:match elements with a type attribute refering to the
current matcher factory iteration -->
<xsl:for-each
select="/map:sitemap/map:pipelines/map:pipeline/descendant-or-self::map:match[@type=$type
or (not(@type) and $default)]">
+<xsl:call-template name="line-number"/>
<xsl:variable name="matcher-name">
<xsl:call-template name="generate-name">
<xsl:with-param name="prefix">matcher_</xsl:with-param>
@@ -134,7 +164,7 @@
</xsl:call-template>
</xsl:variable>
// The generated matcher for a pattern of "<xsl:value-of
select="@pattern"/>"
- <xsl:value-of
select="java:getClassSource($factory-loader,string($src),string($matcher-name),string(@pattern),$config)"/>
+ <xsl:value-of
+select="XSLTFactoryLoader:getClassSource($factory-loader,string($src),string($matcher-name),string(@pattern),$config)"/>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
@@ -142,18 +172,20 @@
<!-- Generate selectors which implements CodeFactory -->
<xsl:for-each select="/map:sitemap/map:components/map:selectors/map:selector">
+<xsl:call-template name="line-number"/>
<xsl:variable name="src">
<xsl:value-of select="@src"/>
</xsl:variable>
- <xsl:if test="java:isFactory($factory-loader, string($src))">
+ <xsl:if test="XSLTFactoryLoader:isFactory($factory-loader, string($src))">
<xsl:variable name="name" select="@name"/>
<xsl:variable name="type" select="translate(@name, '- ', '__')"/>
<xsl:variable name="default" select="@name = ../@default"/>
<xsl:variable name="config" select="descendant-or-self::*"/>
- private boolean <xsl:value-of select="$name"/>Select (<xsl:value-of
select="java:getParameterSource($factory-loader, string($src),$config)"/> pattern, Map
objectModel, Parameters param) {
- <xsl:value-of select="java:getMethodSource($factory-loader,
string($src),$config)"/>
+ private boolean <xsl:value-of select="$name"/>Select (<xsl:value-of
+select="XSLTFactoryLoader:getParameterSource($factory-loader,
+string($src),$config)"/> pattern, Map objectModel, Parameters param) {
+ <xsl:value-of select="XSLTFactoryLoader:getMethodSource($factory-loader,
+string($src),$config)"/>
}
<xsl:for-each
select="/map:sitemap/map:pipelines/map:pipeline/descendant::map:select[@type=$name or
(not(@type) and $default)]/map:when">
+<xsl:call-template name="line-number"/>
<xsl:variable name="selector-name">
<xsl:call-template name="generate-name">
<xsl:with-param name="prefix">selector_</xsl:with-param>
@@ -161,7 +193,7 @@
</xsl:call-template>
</xsl:variable>
<!-- produce a definition for this test string -->
- <xsl:value-of
select="java:getClassSource($factory-loader,string($src),string($selector-name),string(@test),$config)"/>
+ <xsl:value-of
+select="XSLTFactoryLoader:getClassSource($factory-loader,string($src),string($selector-name),string(@test),$config)"/>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
@@ -298,6 +330,7 @@
<!-- generate methods for every map:view element -->
<xsl:for-each select="/map:sitemap/map:views/map:view">
+<xsl:call-template name="line-number"/>
/**
* This is the method to produce the "<xsl:value-of select="@name"/>" view of
the requested resource
* @param pipeline A <code>StreamPipeline</code> holding the
sitemap component collected so far
@@ -319,6 +352,7 @@
<!-- generate methods for every map:action-set element -->
<xsl:for-each select="/map:sitemap/map:action-sets/map:action-set">
+<xsl:call-template name="line-number"/>
/**
* This is the method to process the "<xsl:value-of select="@name"/>"
action-set of the requested resource
* @param cocoon_action A <code>String</code> holding the
requested action
@@ -334,6 +368,7 @@
Map allMap = null;
Parameters nparam = null;
<xsl:for-each select="map:act">
+<xsl:call-template name="line-number"/>
map = null;
<xsl:choose>
<xsl:when test="@action">
@@ -415,6 +450,7 @@
<!-- process the pipelines -->
<!-- for each pipeline element generate a try/catch block -->
<xsl:for-each select="/map:sitemap/map:pipelines/map:pipeline">
+<xsl:call-template name="line-number"/>
<xsl:variable name="pipeline-position" select="position()"/>
<xsl:if test="@internal-only = 'yes' or @internal-only='true'">
if (internalRequest) {
@@ -451,6 +487,7 @@
<!-- generate methods for every map:handle-errors elements in all map:pipeline
elements -->
<xsl:for-each select="/map:sitemap/map:pipelines/map:pipeline">
+<xsl:call-template name="line-number"/>
<xsl:variable name="pipeline-position" select="position()"/>
<xsl:if test="(./map:handle-errors)">
private boolean error_process_<xsl:value-of select="$pipeline-position"/>
(Environment environment, Map objectModel, Exception e, boolean internalRequest)
@@ -483,6 +520,7 @@
<!-- a match element calls a match method on a matcher component (or a inlined
matcher method produced by a CodeFactory -->
<xsl:template match="map:match">
+<xsl:call-template name="line-number"/>
<!-- get the type of matcher used -->
<xsl:variable name="matcher-type">
@@ -511,7 +549,7 @@
<!-- check if this matcher is a factory ? -->
<xsl:variable name="is-factory">
- <xsl:value-of select="java:isFactory($factory-loader,
string(/map:sitemap/map:components/map:matchers/map:matcher[@name=$matcher-type]/@src))"/>
+ <xsl:value-of select="XSLTFactoryLoader:isFactory($factory-loader,
+string(/map:sitemap/map:components/map:matchers/map:matcher[@name=$matcher-type]/@src))"/>
</xsl:variable>
<!-- break on error when old parameter syntax exists -->
@@ -569,6 +607,7 @@
<!-- a select element introduces a multi branch case by calls to a select method on
a selector component (or a inlined
selector method produced by a CodeFactory -->
<xsl:template match="map:select">
+<xsl:call-template name="line-number"/>
<!-- get the type of selector used -->
<xsl:variable name="selector-type">
@@ -609,42 +648,8 @@
<xsl:with-param name="param">param</xsl:with-param>
</xsl:apply-templates>
- <!-- modification end -->
-
- <!-- Modified 20010510 L.Sutic Changed to pass sitemap parameters. -->
-
- <!-- break on error when old parameter syntax exists -->
- <xsl:if test="parameter">
- <xsl:call-template name="error">
- <xsl:with-param name="message">Sitemap parameters should now be in the
sitemap namespace (map:parameter).</xsl:with-param>
- </xsl:call-template>
- </xsl:if>
-
- <!-- test if we have to define parameters for this action -->
- <xsl:if test="count(map:parameter)>0">
- param = new Parameters ();
- </xsl:if>
-
- <!-- generate the value used for the parameter argument in the invocation of the
act method of this action -->
- <xsl:variable name="component-param">
- <xsl:choose>
- <xsl:when test="count(map:parameter)>0">
- param
- </xsl:when>
- <xsl:otherwise>
- emptyParam
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <!-- collect the parameters -->
- <xsl:apply-templates select="map:parameter">
- <xsl:with-param name="param">param</xsl:with-param>
- </xsl:apply-templates>
+ <!-- modification end -->
- <!-- modification end -->
-
-
<!-- loop through all the when cases -->
<xsl:for-each select="./map:when">
@@ -667,7 +672,7 @@
<!-- check if this selector is a factory ? -->
<xsl:variable name="is-factory">
- <xsl:value-of select="java:isFactory($factory-loader,
string(/map:sitemap/map:components/map:selectors/map:selector[@name=$selector-type]/@src))"/>
+ <xsl:value-of select="XSLTFactoryLoader:isFactory($factory-loader,
+string(/map:sitemap/map:components/map:selectors/map:selector[@name=$selector-type]/@src))"/>
</xsl:variable>
<!-- Modified 20010509 L.Sutic Changed to pass sitemap parameters. -->
@@ -774,6 +779,7 @@
<!-- processing of an act element having a type attribute -->
<xsl:template match="map:act[@type]" mode="set">
+<xsl:call-template name="line-number"/>
<!-- get the type of action used -->
<xsl:variable name="action-type">
@@ -827,6 +833,7 @@
<!-- processing of an act element having a set attribute -->
<xsl:template match="map:act[@set]">
+<xsl:call-template name="line-number"/>
<!-- get the type of action used -->
<xsl:variable name="action-set">
@@ -896,6 +903,7 @@
<!-- generate the code to invoke a generator -->
<xsl:template match="map:generate">
+<xsl:call-template name="line-number"/>
<xsl:call-template name="setup-component">
<xsl:with-param name="default-component"
select="/map:sitemap/map:components/map:generators/@default"/>
<xsl:with-param name="method">eventPipeline.setGenerator</xsl:with-param>
@@ -905,6 +913,7 @@
<!-- generate the code to invoke a transformer -->
<xsl:template match="map:transform">
+<xsl:call-template name="line-number"/>
<xsl:call-template name="setup-component">
<xsl:with-param name="default-component"
select="/map:sitemap/map:components/map:transformers/@default"/>
<xsl:with-param name="method">eventPipeline.addTransformer</xsl:with-param>
@@ -914,6 +923,7 @@
<!-- generate the code to invoke a serializer -->
<xsl:template match="map:serialize">
+<!-- <xsl:call-template name="line-number"/> -->
<xsl:call-template name="setup-component">
<xsl:with-param name="default-component"
select="/map:sitemap/map:components/map:serializers/@default"/>
<xsl:with-param name="method">pipeline.setSerializer</xsl:with-param>
@@ -947,6 +957,7 @@
<!-- generate the code to invoke a reader -->
<xsl:template match="map:read">
+<xsl:call-template name="line-number"/>
<xsl:call-template name="setup-component">
<xsl:with-param name="default-component"
select="/map:sitemap/map:components/map:readers/@default"/>
<xsl:with-param name="method">pipeline.setReader</xsl:with-param>
@@ -974,6 +985,7 @@
<!-- generate the code to invoke a sub sitemap -->
<xsl:template match="map:mount">
+<xsl:call-template name="line-number"/>
<xsl:variable name="src" select="@src"/>
<xsl:variable name="check-reload">
@@ -1017,6 +1029,7 @@
<!-- generate the code to redirect a request -->
<xsl:template match="map:redirect-to">
+<xsl:call-template name="line-number"/>
<xsl:choose>
<!-- redirect to a internal resource definition -->
@@ -1054,6 +1067,7 @@
<!-- generate the code to match a label definition -->
<xsl:template match="map:label">
+<xsl:call-template name="line-number"/>
<xsl:apply-templates/>
if ("<xsl:value-of select="@name"/>".equals(cocoon_view))
return view_<xsl:value-of select="translate(@name, '- ', '__')"/> (pipeline,
eventPipeline, listOfMaps, environment, internalRequest);
@@ -1061,6 +1075,7 @@
<!-- generate the code to match a aggregate definition -->
<xsl:template match="map:aggregate">
+<xsl:call-template name="line-number"/>
<xsl:call-template name="setup-component">
<xsl:with-param name="default-component">!content-aggregator!</xsl:with-param>
<xsl:with-param name="method">eventPipeline.setGenerator</xsl:with-param>
@@ -1085,6 +1100,7 @@
<!-- generate the code to match a aggregates part definition -->
<xsl:template match="map:part">
+<xsl:call-template name="line-number"/>
<xsl:param name="ca"/>
<xsl:if test="not (@src)">
<xsl:call-template name="error">
@@ -1098,6 +1114,7 @@
<!-- collect parameter definitions -->
<xsl:template match="map:pipeline//map:parameter | map:action-set//map:parameter |
map:resource//map:parameter">
+<xsl:call-template name="line-number"/>
<xsl:param name="param"/>
<xsl:if test="not($param='')">
<xsl:value-of select="$param"/>.setParameter ("<xsl:value-of select="@name"/>",
substitute(listOfMaps, "<xsl:value-of select="@value"/>"));
@@ -1106,6 +1123,7 @@
<!-- FIXME:(GP) is this still valid? -->
<xsl:template match="map:param">
+<xsl:call-template name="line-number"/>
param.setParameter ("<xsl:value-of select="@name"/>", substitute(listOfMaps,
"<xsl:value-of select="@map:value"/>"));
</xsl:template>
@@ -1113,6 +1131,7 @@
<!-- this template generates the code to configure a specific sitemap component -->
<xsl:template name="config-components">
+<xsl:call-template name="line-number"/>
<xsl:param name="name"/>
<xsl:param name="components"/>
@@ -1127,7 +1146,7 @@
<xsl:variable name="ns" select="namespace-uri(.)"/>
<xsl:for-each select="$components">
<xsl:variable name="is-factory-component"
- select="@src and ($name = 'matcher' or $name = 'selector') and
java:isFactory($factory-loader, string(@src))"/>
+ select="@src and ($name = 'matcher' or $name = 'selector') and
+XSLTFactoryLoader:isFactory($factory-loader, string(@src))"/>
<xsl:if test="$is-factory-component=false()">
{
DefaultConfiguration cconf1 = new DefaultConfiguration("<xsl:value-of
select="translate(@name, '- ', '__')"/>", LOCATION);
@@ -1161,6 +1180,7 @@
<!-- this template generates the code to collect configurations for a specific
sitemap component -->
<xsl:template name="nested-config-components">
+<xsl:call-template name="line-number"/>
<xsl:param name="name"/>
<xsl:param name="config-name"/>
<xsl:param name="components"/>
@@ -1217,6 +1237,7 @@
<!-- this template is used to setup a individual sitemap component before putting
it into a pipeline -->
<xsl:template name="setup-component">
+<xsl:call-template name="line-number"/>
<xsl:param name="default-component"/>
<xsl:param name="method"/>
<xsl:param name="prefix"/>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]