This action is being slowly phased out in favor of the ResourceExistsSelector

(See ResourceExistsSelector)

This action allows you to process different pipelines based on whether a resource exists. This is useful when you have this sort of a pipeline:

<map:match pattern="foo/*/">
  <map:generate src="docs/{1}.xml"/>
  <map:transform src="xslt/foo2html.xsl"/>
  <map:serialize type="xhtml"/>
</map:match>

Althought the wildcards in the sitemap are extremely powerful, you will run into problems when someone requests a URL which will substitute to a file that does not exist:

GET /foo/nowhere/ HTTP/1.1

Obviously, the sitemap will look for docs/nowhere.xml, it won't be found, and you'll end up with an ugly ResourceNotFoundException.

If you only care about reporting that a resource does not exist, you have this option:

<map:pipeline>
<map:handle-errors type="404">
    <map:transform src="xslt/error2html.xsl"/>
    <map:serialize type="html"/>
</map:handle-errors>
</map:pipeline>

However, if you wish to "fall-back" to a different pipeline if a file doesn't exist, you may use the ResourceExistsAction. This action will run through it's embedded pipeline only when the resource given as 'url' parameter exists. Otherwise it won't do anything and the execution will continue below the action.

(inspired from the mailing list)

<map:match pattern="foo/*/">

  <!-- check to see if the requested resource is actually a valid source document -->

  <map:act type="resource-exists">
    <map:parameter name="url" value="context://documents/{1}.xml"/>
    <map:generate src="context://documents/{../1}.xml" type="file"/>
    <map:transform src="xslt/doc2html.xsl"/>
    <map:serialize type="xhtml"/>
  </map:act>

  <!-- otherwise, we can do this stuff -->

  <map:generate src="docs/system/notfound.xml"/>
  <map:transform src="xslt/notfound2html.xsl/>
  <map:serialize type="xhtml"/>

</map:match>

note: Notice the following line:

<map:generate src="documents/'''{../1}'''.xml" type="file"/>

In the src attribute, since we're already inside an action, we need to use the notation {../1} to denote that we want the wildcard match from the map:match tag, because the ResourceExistsAction always returns an empty map. The side effect of this is that if you accidentally use {1} in your src attribute, NULL will get substituted instead of the desired wildcard that you matched above in your map:match, think scope.

ResourceExistsAction (last edited 2009-09-20 23:41:48 by localhost)