cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Schmidt <Daniel.Schm...@tomtom.com>
Subject RE: Trigger Cocoon http response code from within XSL code
Date Fri, 13 Dec 2013 17:12:19 GMT
Hi David,

That is great. I got it working with the following code:

<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
	<map:components>
		...
		<map:selectors>
			<map:selector name="exception" src="org.apache.cocoon.selection.ExceptionSelector">
				<exception name="FileNotFound" class="org.apache.cocoon.ResourceNotFoundException"/>
				<exception name="ContentNotAvailableInCountry" class="org.apache.cocoon.ProcessingException"/>
			</map:selector>
		</map:selectors>
	</map:components>
	<map:resources>
		<map:resource name="404">
			<map:generate src="404.xml"/>
			<map:serialize status-code="404"/>
		</map:resource>
		<map:resource name="404-notavailableinyourcountry">
			<map:generate src="404-notavailableinyourcountry.xml"/>
			<map:serialize status-code="404"/>
		</map:resource>
		...
	</map:resources>
	<map:pipelines>
		<map:pipeline>
			<map:handle-errors>
				<map:select type="exception">
					<map:when test="ContentNotAvailableInCountry">
						<map:call resource="404-notavailableinyourcountry"/>
					</map:when>
					<map:when test="FileNotFound">
						<map:call resource="404"/>
					</map:when>
					<map:otherwise>
						<!-- something else -->
					</map:otherwise>
				</map:select>
			</map:handle-errors>
			...
		</map:pipeline>
	</map:pipelines>
</map:sitemap>


So I always get a "ContentNotAvailableInCountry" exception if I do a <xsl:message terminate="yes"/>
in XSLT. Otherwise I'm serving a "generic" error page or a FileNotFound error page.


However, it would be great if I could throw different exceptions from within XSLT with the
following approach:
<xsl:message terminate="yes">ContentNotAvailableInCountry</xsl:message>

I tried using an XPathExceptionSelector instead of the ExceptionSelector (the numbers 1/2
in the code below are only there to point out a line; they are not part of the code):

<map:selector name="exception" src="org.apache.cocoon.selection.XPathExceptionSelector">
	<exception name="Transform" class="org.apache.cocoon.ProcessingException">
(1)		<xpath name="ContentNotAvailableInCountry" test="rawMessage='Failed to process pipeline'"/>
(2)		<xpath name="ContentNotAvailableInCountry" test="message='ContentNotAvailableInCountry'"/>
	</exception>
</map:selector>

While (1) works fine (it's equal to the ExceptionSelector approach since I can't say what's
the content of <xsl:message/>), I can't get (2) working.

How can I test if the content of <xsl:message terminate="yes"/> is a certain string
with the help of XPathExceptionSelector?


Thank you!




-----Original Message-----
From: David Crossley [mailto:crossley@apache.org] 
Sent: Freitag, 13. Dezember 2013 00:49
To: users@cocoon.apache.org
Subject: Re: Trigger Cocoon http response code from within XSL code

Daniel Schmidt wrote:
> Hi Thorsten,
> 
> Thanks for pointing out actions. I will have a closer look at them.
> 
> Setting the status code is no problem, we already do that. The problem is that we only
know within the XSLT code if a page is available in a certain country, because this is defined
in XML.

Could use "stylesheet-directed termination" (xsl:message terminate="yes") Then in the relevant
sitemap use "map:handle-errors" to set the status-code on the serializer.
http://forrest.apache.org/faq.html#handle-errors

-David

> Thanks.
> 
> 
> 
> From: Thorsten Scherler [mailto:scherler@gmail.com]
> Sent: Donnerstag, 12. Dezember 2013 14:33
> To: users@cocoon.apache.org
> Subject: Re: Trigger Cocoon http response code from within XSL code
> 
> On 12/12/2013 02:21 PM, Daniel Schmidt wrote:
> Hi,
> 
> In our project we have multiple languages and some pages are not available in a certain
country. If that is the case, we just output a message. For Search engines it would be good
to respond with a different status code then 200.
> 
> The question is: Is it possible to trigger a different http status code from within the
XSL-code to the sitemap? Is there a way of doing something like that?
> 
> Thank you!
> Daniel
> 
> 
> Daniel Schmidt | Jr Web Developer | TomTom Business Solutions | 
> daniel.schmidt@tomtom.com<mailto:daniel.schmidt@tomtom.com> | 
> +49(0)341 24495-920 office | +49(0)341 24495-888 fax | 
> www.tomtom.com/business<http://www.tomtom.com/business>
> 
> 
> Depending which version I would suggest an action to do that. There are examples how
to set the status code, the question which one would you want to set? From within xslt I think
it is a bit more complicated.
> 
> salu2
> 
> 
> --
> 
> Thorsten Scherler <scherler.at.gmail.com>
> 
> codeBusters S.L. - web based systems
> 
> <consulting, training and solutions>
> 
> 
> 
> http://www.codebusters.es/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message