![]() | ![]() | Sitemap GuideThe sitemap is the key part of running a site based on either Cocoon and Paloose. It defines all the components to be used and the pipelines to be run in response to a particular browser request. It is definitely worth reading the Apache documentation about the Cocoon sitemap. Note Remember that everything that goes through Paloose takes time. Rather
than use Paloose to serve files see if Apache can do this for you. In general resources
such as style sheets and images are static files and do not need transforming. This is the
same situation in Cocoon: if Apache can serve it —
don't process it. The StructureThe Paloose site has a similar structure to the Cocoon one, just less of it. <?xml version="1.0"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
<map:components>
<map:generators/>
<map:transformers/>
<map:serializers/>
<map:selectors/>
<map:readers/>
<map:matchers/>
</map:components>
<map:views/>
<map:resources/>
<map:pipelines/>
</map:sitemap> Sitemap NamespaceThe namespace is identical to that used by Cocoon (http://apache.org/cocoon/sitemap/1.0), though there is no real reason why it should not be one specific to Paloose. This could be changed in future. If you wish to do this yourself note that the namespace is changed in the main Paloose configuration file in the user's site. Common Attributes of ComponentsLike Cocoon all components have some common attributes.
Component ParametersSome component declaration use parameters to allow user-settable values to be incorporated in the definition, for example see the PageHitTransformer. Subsitemap Component DefinitionsWarning Versions before 0.14.1: Component definitions in subsitemaps are
handled differently to Cocoon. In the latter it is possible to
redefine or declare a new component. In Paloose all declarations should be placed in the
root sitemap, with just the default changed in the subsitemap. Components can be defined with a subsitemap overriding a declaration made in a higher sitemap. The new definition is available to all sitemaps called by the one where the declaration is made. GeneratorsA Generator generates XML content as DOM objects and initializes the pipeline processing. Using DOM instead of SAX is a change from Cocoon (see this FAQ). For example defining the FileGenerator generator: <map:generators default="file">
<map:generator name="file" src="resource://lib/generation/FileGenerator"/>
</map:generators> The default attribute specifies the type of generator to use if none is specified in a pipeline. Further discussion on the types of generator are on the Generators Page. TransformersTransformers change a DOM into a another DOM using either an XSLT file or a custom translator. For example this defines TRAXTransformer which performs standard XSLT transformations, similar to Cocoon. <map:transformers default="xslt">
<map:transformer name="xslt" src="resource://lib/transforming/TRAXTransformer"/>
</map:transformers> The default attribute specifies the type of transformer to use if none is specified in a pipeline. Further discussion on the types of generator are on the Transformers page. SerializersSerializers change a DOM into a stream of characters that the client can use. There are several serializers that work in a similar fashion to Cocoon, although not so extensive: only encoding and doctype in the XHTML/HTML serializers is currently supported. For example <map:serializers default="xml">
<map:serializer name="xhtml" src="resource://lib/serialization/XHTMLSerializer">
<doctype-public>-//W3C//DTD XHTML 1.0 Strict//EN</doctype-public>
<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</doctype-system>
<encoding>iso-8859-1</encoding>
</map:serializer>
</map:serializers> See the Serializers page for more information. ReadersReaders are used to deliver resources directly from the server to the client, usually without modification. As such they are generator, transformer and serializer all in one. In Paloose there is currently only one type of matcher: ReasourceReader, which is equivalent to the Cocoon reader of the same name. <map:readers default="resource">
<map:reader name="resource" src="resource://lib/reading/ResourceReader"/>
</map:readers> The default attribute specifies the type of reader to use if none is specified in a pipeline. SelectorsSelectors allow conditional processing within the pipeline. Currently the only selector supported by Paloose if the BrowserSelector which allows different routes through a pipeline to be taken dependent on the client's browser. See the Selectors page for more information. AggregatorsAggregators takes several XML documents and combine them into a single DOM, with appropriate enclosing tags for each part. They are equivalent to generators and thus must be placed first in a pipeline. See Aggregators page for more information. MatchersMatchers are used to match the request into a particular pipeline. In Paloose (version 0.7.0 or later) there are two types of matcher: WildcardURIMatcher and RegexpURIMatcher. WildcardURIMatcher is equivalent to the Cocoon matcher of the same name. However RegexpURIMatcher is slightly different to its Cocoon equivalent: it uses a PHP-modified Perl regular expression syntax. For details of this see the PHP5 manual pages) <map:matchers default="wildcard">
<map:matcher name="wildcard" src="resource://lib/matching/WildcardURIMatcher"/>
<map:matcher name="regexp" src="resource://lib/matching/RegexpURIMatcher"/>
</map:matchers> The default attribute specifies the type of matcher to use if none is specified in a pipeline. ViewsViews are means of interrupting the normal pipeline flow under the control of the user via the quesry string. It is similar to that of Cocoon but not quite so extensive. It is a useful debugging aid. See the Views documentation page for more information. PipelinesLike Cocoon the heart of Paloose is the sitemap pipeline. Documents are entered one end of the pipeline (via a generator), progress through pipeline via zero or more transformations (transformers) and end up being processed to the client (via a serializer). Paloose also support aggregation to build up a document from a variety of other documents (or pipelines). Paloose also supports a similar error handling procedure to Cocoon, although there are some slight differences withn the handlers. Defining a PipelinePipelines are defined within the map:pipelines element within individual map:pipeline elements. <map:pipelines>
<map:pipeline>
<!-- pipeline elements -->
</map:pipeline>
<map:handle-errors>
...
</map:handle-errors>
</map:pipelines> An individual pipeline can be marked as " internal only" so that itis impossible to activate it from an external URL request. This is generally done on aggregation to hide the intermediate parts from direct access. It is declared <map:pipelines>
<map:pipeline internal-only="true">
<!-- pipeline elements -->
</map:pipeline>
</map:pipelines> Pipeline ElementsPaloose supports a subset of the Cocoon sitemap pipeline elements:
Internal PipelinesSometimes it is desirable to mark a pipeline to be only accessable from the sitemap itself. This is of particular use when aggregation is used (and authorisation). It prevents scraps of documents which are used in assembling a complete document from being accessed. See the documentation on aggregation for an example of how this is used. The general structure is: <map:pipelines>
<map:pipeline>
<!-- matchers appearing here are available externally and internally -->
</map:pipeline>
<map:pipeline internal-only="true">
<!-- matchers appearing here are available internally -->
</map:pipeline>
</map:pipelines> Sitemap Variables and Matching PatternsIt is possible to define variables in the Cocoon sitemap. Paloose uses this principle, but, at present, uses a very restricted set. Like Cocoon variables are defined by enclosing them in brackets "{...}". The primary area where this is used is in the pattern matching. Wildcard Pattern MatchingFor example take the wildcard matcher <map:match pattern="*/*.html">
...
</map:match> The wildcards in the match pattern are assigned to internal pattern variables "{1}", "{2}" etc, in a similar fashion to Perl regular expressions. So in the above case if the pattern to be matched is "documentation/index.html" then there would be a match. The internal variables would be set {1} = "documentation" and {2} = "index". These variables are used within the various pipeline components to resolve string expressions. For example <map:match pattern="*/*.html">
<map:generate src="context://{1}/{2}.xml"/>
...
</map:match> In this case the generator would fetch the file documentation/index.xml from the current application context (see pseudo protocols below). Note that the constructions "**" and "*" are different and are identical to their Cocoon counterparts.
Note that since Version 1.3.4 the sitemap variables formed from the matcher "{0},{1},{2},..." have been included in the global variables. The can be accessed by using "{global:__0},{global:__1},{global:__2},..." respectively. The values for the pattern variables are taken from the current matcher. If you want to access a higher matcher (wherever it is) then you would have to use the string {../1}, which means access the pattern variable {1} in the previous matcher. These can be extended as necessary, for example {../../1} to access a matcher two levels above the current one. Regular Expression Pattern MatchingSince version 0.7.0 it has been possible to carry out matching using regular expressions. Paloose regular expressions are not the same as Cocoon regular expressions. The PHP5 version based on Perl is used and a full description of the regexp can be found on the PHP5 manual page. The pattern variables work in similar fashion as the wildcard matcher. For example: <map:match type="regexp" pattern="/.*\.(html)|(tex)|(xml)/">
...
</map:match> would match all requests that end in "html", "tex" and "xml". In the following all requests for documents between "nb1996" and "nb1999" would read the html file directly: <map:match type="regexp" pattern="/nb199([6789]).html/">
<map:read src="context://nb/199{1}/nb199{1}.html"/>
</map:match> and the following would take all others in 2000 or later and process them from an XML file. <map:match type="regexp" pattern="/nb20(.+).html/">
<map:generate src="cocoon:/20{1}/nb20{1}.xml" label="xml-content"/>
<map:transform src="context://resources/transforms/notebooks-html.xsl" label="page-transform">
<map:parameter name="page" value="nb20{1}"/>
</map:transform>
<map:serialize/>
</map:match> VariablesThere are other variables that can be used within the sitemap. The RequestParameterModule allows access to the query string variables. For example if the URI request is index.html?locale=en the RequestParameterModule gives the sitemap access to the query string. Using this is very simple <map:match pattern="**.html">
<map:generate src="context://{1}.xml"/>
<map:transform src="context://resources/transforms/page2html.xsl">
<map:parameter name="locale" value="{request-param:locale}"/>
</map:transform>
...
</map:match> This would pass the parameter locale into the XSLT script where it could be accessed using the following typical code: <xsl:param name="locale"/>
...
<xsl:value-of select="$locale" /> Note the format of the variable, it is formed of a pair "{module name:variable name}". As other predefined modules are added the module name will be used to access the variables defined by the module. Global VariablesGlobal variables can be declared within each sitemamp and are available to each subsitemap. They are also overwritten by subsitemap declarations. They are declared within the sitemap pipelines declaration as a component configuration element, for example <map:pipelines>
<map:component-configurations>
<global-variables>
<composer>Bach</composer>
</global-variables>
</map:component-configurations>
... which would set the global variable "composer" to the string "Bach". It could then be accessed like other variables within the sitemap as: <map:transform type="mysql" label="sql-transform">
<map:parameter name="show-nr-of-rows" value="true"/>
<map:parameter name="composer" value="{global:composer}"/>
</map:transform> Since Version 1.3.4 the sitemap variables formed from the matcher "{0},{1},{2},..." have been included in the global variables. The can be accessed by using "{global:__0},{global:__1},{global:__2},..." respectively. Handling Pipeline ErrorsWhen an error is detacted in a sitemap (page does not exist because a matcher has not fired, for example) a specialised error pipeline is run. More details can be found in the Handle Error documentation page. ProtocolsAs in a Cocoon sitemap, you can use all protocols nearly everywhere in a Paloose sitemap. The following are a list of the Paloose protocols and what they mean. Note that there are subtle differences to Cocoon.
| ![]() |


