cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "neil" <nba...@aisoftware.com.au>
Subject Example use of writeDOMsession / readDOMsession
Date Mon, 11 Feb 2002 22:47:27 GMT
Here's a sitemap example (for cocoon-2.0) using writeDOMsession /
readDOMsession (as suggested in the docs) to avoid repetitive queries of
reference tables. It works fine, but I haven't done any benchmarking to find
out if it was worth the trouble (and it was quite a bit of trouble)!

Questions:

1. Is there some way this global data could be saved globally rather than
per session?
I guess a new set of global data matchers, selectors and read/writeDOMGlobal
would be required
(more trouble that its worth to me).

2. Has anybody found this approach to be worthwhile or otherwise?

3. Has anybody got a better way of doing it?

Cheers,
	Neil.


			<!--
			Get reference table data.
			e.g. Lookup.Staff returns data from the Staff table (query defined in
Staff.xml file)
			TO DO: make this a 'resource' so its not available externally.

			If session attribute org.apache.cocoon.SessionState does not contain the
string ",Staff,"
			then this string is appended to the attribute, the query is executed and
the result is saved
			to the session attribute pinnacle.Staff.
			Otherwise the query is not executed and result is fetched from the
session attribute pinnacle.Staff.

			SessionState is used because I can match its value against various string
values, but I don't know how to
			test for the existence of a non-string valued session attribute like
pinnacle.Staff.
			-->
			<map:match pattern="Lookup.*">
				<!-- If session attribute org.apache.cocoon.SessionState does contain
the string ",Staff," -->
				<map:match type="sessionState" pattern="*,{1},*">
					<!-- for debugging - In browser's URL field you see
"LookupStaff.wasNotSetIsNow" -->
					<!-- <map:redirect-to uri="Lookup{../1}.wasAlreadySet"/> -->
					<map:generate type="file" src="BlankPage.xml"/>
					<!-- only contains a <page/> -->
					<!--
					Append content from session attribute pinnacle.Staff after <page/>
element.
					We end up with: <page/><page>... stuff we want...</page>.
					-->
					<map:transform type="readDOMsession">
						<map:parameter name="dom-name" value="pinnacle.{../1}"/>
						<map:parameter name="trigger-element" value="page"/>
						<map:parameter name="position" value="in"/>
					</map:transform>
					<map:serialize type="xml"/>
				</map:match>
				<!-- Else session attribute org.apache.cocoon.SessionState does not
contain the string ",Staff," -->
				<map:match type="sessionState" pattern="**">
					<map:act type="sessionState">
						<map:parameter name="new-state" value="{1},{../1},"/>
						<!-- append ",Staff," -->
						<!-- for debugging - In browser's URL field you see
"LookupStaff.wasNotSetIsNow" -->
						<!-- <map:redirect-to uri="Lookup{../../1}.wasNotSetIsNow"/> -->
						<!-- execute query defined in Staff.xml. -->
						<map:generate type="file" src="{../../1}.xml"/>
						<map:transform type="sql">
							<map:parameter name="use-connection" value="poracle"/>
						</map:transform>
						<!--
						Shouldn't really need an XSLT transform here, but without it I get
						org.xml.sax.SAXException: URI not declared
						at
org.apache.cocoon.transformation.WriteDOMSessionTransformer.startElement()
						in cocoon\WEB-INF\logs\cocoon.log.000001
						Some problem with the sql: namespace not being declared.
						-->
						<map:transform type="xslt" src="LookupTables.xsl"/>
						<!-- save <page> element (and its descendents) to session attribute
pinnacle.Staff -->
						<map:transform type="writeDOMsession">
							<map:parameter name="dom-name" value="pinnacle.{../../1}"/>
							<map:parameter name="dom-root-element" value="page"/>
						</map:transform>
						<map:serialize type="xml"/>
					</map:act>
				</map:match>
				<map:redirect-to uri="Lookup{1}.noMatchOnSessionState"/>
			</map:match>

			<!--
			Test Lookup.*
			Initialises the session to allow testing from the URLReader.java test
programme.
			-->
			<map:match pattern="TestLookup.*">
				<!-- start a session -->
				<map:redirect-to session="true" uri="TestLookup2.{1}"/>
			</map:match>

			<map:match pattern="TestLookup2.*">
				<!-- init session attribute that holds current state -->
				<map:act type="sessionState">
					<map:parameter name="new-state" value="init"/>
					<!-- do the lookup -->
					<map:redirect-to session="true" uri="Lookup.{../1}"/>
				</map:act>
			</map:match>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

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


Mime
View raw message