You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by do...@cocoon.apache.org on 2004/07/10 04:09:00 UTC

[Cocoon Wiki] Updated: UnderstandingCocoonMounts

   Date: 2004-07-09T19:09:00
   Editor: JoergHeinicke <jo...@gmx.de>
   Wiki: Cocoon Wiki
   Page: UnderstandingCocoonMounts
   URL: http://wiki.apache.org/cocoon/UnderstandingCocoonMounts

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -12,14 +12,14 @@
 
 This means that if the Cocoon web application is installed in 
 
-{{{
-$TOMCAT_HOME/cocoon
+{{{
+$TOMCAT_HOME/cocoon
 }}}
 
 Then all requests with the base URL of:
 
-{{{
-http://localhost:8080/cocoon/...
+{{{
+http://localhost:8080/cocoon/...
 }}}
 
 will be serviced by asking this sitemap for a suitable pipeline.
@@ -29,14 +29,14 @@
 
 So for example a pipeline with:
 
-{{{
-<map:match pattern="my/long/url/path/*.html"/>
+{{{
+<map:match pattern="my/long/url/path/*.html"/>
 }}}
 
 Will match:
 
-{{{
-http://localhost:8080/cocoon/my/long/url/path/doc.html
+{{{
+http://localhost:8080/cocoon/my/long/url/path/doc.html
 }}}
 
 So while the Cocoon web application is mounted at {{{/cocoon}}}
@@ -60,10 +60,10 @@
 and includes the location of that sitemap.
 
 E.g. 
-{{{
-<map:match pattern="my/long/url/path/*.html">
- <map:mount src="my/long/dir/structure/sitemap.xmap"/>
-</map:match>
+{{{
+<map:match pattern="my/long/url/path/*.html">
+ <map:mount src="my/long/dir/structure/sitemap.xmap"/>
+</map:match>
 }}}
 
 Will cause the sitemap in {{{$CATALINA_HOME/cocoon/my/long/dir/structure/}}} 
@@ -73,44 +73,44 @@
 
 ''Note : in the compiled sitemap engine (used up to version 2.0.3), default components are not inherited, and you may want to declare empty container elements to specify these defaults (e.g. {{{<map:generators default="file"/>"}}}). This is not needed with the newer interpreted engine.''
 
-However, any [:Matchers] in this sitemap would still have to 
+However, any [:Matcher]s in this sitemap would still have to 
 use the full request path for their match to work as expected
 
 I couldn't do:
 
-{{{
-<map:match pattern="*.html"/>
+{{{
+<map:match pattern="*.html"/>
 }}}
 
 As this actually matches
 
-{{{
-http://localhost:8080/cocoon/*.html.
+{{{
+http://localhost:8080/cocoon/*.html.
 }}}
 
 To enable additional unwanted path information to be ignored, 
 we need to add an additional uri-prefix attribute to the {{{<map:mount>}}}
 element, as follows:
 
-{{{
-<map:match pattern="my/long/url/path/*.html">
- <map:mount src="my/long/dir/structure/sitemap.xmap"
-                   uri-prefix="my/long/url/path/"/>
-</map:match>
+{{{
+<map:match pattern="my/long/url/path/*.html">
+ <map:mount src="my/long/dir/structure/sitemap.xmap"
+                   uri-prefix="my/long/url/path/"/>
+</map:match>
 }}}
 
 Which means that a matcher with the pattern *.html in 
 {{{$CATALINA_HOME/cocoon/my/long/dir/structure/sitemap.xmap}}} will 
 match:
 
-{{{
-http://localhost:8080/cocoon/my/long/url/path/doc.html
+{{{
+http://localhost:8080/cocoon/my/long/url/path/doc.html
 }}}
 
 but not
 
-{{{
-http://localhost:8080/cocoon/*.html
+{{{
+http://localhost:8080/cocoon/*.html
 }}}
 
 The other additional parameter to the mount element is {{{check-reload}}} 
@@ -151,31 +151,31 @@
 
 We can achieve this with the following:
 
-{{{
-<map:match pattern="auto/*/**">
-   <map:mount uri-prefix="auto/{1}/" src="auto/{1}"/>
-</map:match>
+{{{
+<map:match pattern="auto/*/**">
+   <map:mount uri-prefix="auto/{1}/" src="auto/{1}"/>
+</map:match>
 }}}
 
 This uses wildcard, and sitemap parameters to automatically match 
 a base request url, in this case:
 
-{{{
-http://localhost:8080/cocoon/auto/...
+{{{
+http://localhost:8080/cocoon/auto/...
 }}}
 
 The first path element is matched and stored in {1}. This is 
 then used as the name of the directory from which to load 
 the sitemap. In this case a request for
 
-{{{
-http://localhost:8080/cocoon/auto/foo/bar.html
+{{{
+http://localhost:8080/cocoon/auto/foo/bar.html
 }}}
 
 Will cause the sitemap in:
 
-{{{
-$CATALINA_HOME/cocoon/auto/foo
+{{{
+$CATALINA_HOME/cocoon/auto/foo
 }}}
 
 to be loaded and the prefix {{{/auto/foo/}}} automatically 
@@ -212,54 +212,54 @@
 
 An interesting feature to ask to a root sitemap is service of static resources. Example :
 
-{{{<map:match pattern="**.ai">
-  <map:read src="{1}.ai" mime-type="application/postscript"/>
-</map:match>
-<map:match pattern="**.aif">
-  <map:read src="{1}.aif" mime-type="audio/x-aiff"/>
-</map:match>
+{{{<map:match pattern="**.ai">
+  <map:read src="{1}.ai" mime-type="application/postscript"/>
+</map:match>
+<map:match pattern="**.aif">
+  <map:read src="{1}.aif" mime-type="audio/x-aiff"/>
+</map:match>
 <!-- ... -->}}}
 
 There are lot of mime/type, and they are very useful in case of downloading on some browsers. Not funny to copy/paste the list everywhere. First, put it as [:Resources]. It will be easier to manipulate.
 
-{{{<map:resources>
-  <map:resource name="static">
-    <!-- all the pipeline fragments matching static resources -->
-  </map:resource>
-<!-- ... -->
-</map:resources>
-
-<!-- call it like that where you want in a pipeline process -->
+{{{<map:resources>
+  <map:resource name="static">
+    <!-- all the pipeline fragments matching static resources -->
+  </map:resource>
+<!-- ... -->
+</map:resources>
+
+<!-- call it like that where you want in a pipeline process -->
 <map:call resource="static"/>}}}
 
 '''Now, where to put this call relatively to a mount?'''
 
 If you put it like that
-{{{<map:call resource="static"/>
-<map:match pattern="*/**">
-  <map:mount uri-prefix="{1}" src="{1}/" check-reload="yes"/>
+{{{<map:call resource="static"/>
+<map:match pattern="*/**">
+  <map:mount uri-prefix="{1}" src="{1}/" check-reload="yes"/>
 </map:match>}}}
 All urls like **.js, or **.css will be handled before sub-sitemap matches. Nice, no more need to declare them in each sub-sitemaps.
 But sadly, now your clients will not be allowed to use the virtual matching of cocoon on common file extensions (example: producing images on request with a **.png url). '''Bad solution'''
 
 If you put it like that
-{{{<map:match pattern="*/**">
-  <map:mount uri-prefix="{1}" src="{1}/" check-reload="yes"/>
-  <map:call resource="static"/>
+{{{<map:match pattern="*/**">
+  <map:mount uri-prefix="{1}" src="{1}/" check-reload="yes"/>
+  <map:call resource="static"/>
 </map:match>}}}
 FixMe, but sub-sitemap seems to throw the "Resource not found" error, before the call in the root sitemap.
 
 An idea was to copy the pipeline in all sub-sitemaps (heavy). FixMe, but it seems impossible to use resource from root sitemap in sub-sitemaps. 
 
 ''Forget the idea?'' There's an elegant solution with ResourceExistsAction. The contract of the root sitemap will become, ''"Serves static resource if exists, if not, give hand to sub-sitemaps"''. This is expressed, like that
-{{{<map:match pattern="**">
-    <map:act type="resource-exists">
-      <map:parameter name="url" value="context://{1}"/>
-      <map:call resource="static"/>
-    </map:act>
-</map:match>
-<map:match pattern="*/**">
-  <map:mount uri-prefix="{1}" src="{1}/" check-reload="yes"/>
+{{{<map:match pattern="**">
+    <map:act type="resource-exists">
+      <map:parameter name="url" value="context://{1}"/>
+      <map:call resource="static"/>
+    </map:act>
+</map:match>
+<map:match pattern="*/**">
+  <map:mount uri-prefix="{1}" src="{1}/" check-reload="yes"/>
 </map:match>}}}
 
 It works for us, in hope this helps, FredericGlorieux
@@ -270,11 +270,11 @@
 
 As I understood it, a big disadvantage of a using a cocoon auto-mount is that you couldn't use databases, as you can't define the database connection without modifying global property pages (which defeats the point of using a mount?). However, I discovered that you can define a database connection directly, as and when you use it, in your mounted sitemap, e.g:
 
-{{{<map:transform type="sql">
-  <map:parameter name="dburl" value="jdbc:hsqldb:hsql://localhost:9003"/>
-  <map:parameter name="username" value="sa"/>
-  <map:parameter name="password" value=""/>
-  <map:parameter name="show-nr-of-rows" value="true"/> 
+{{{<map:transform type="sql">
+  <map:parameter name="dburl" value="jdbc:hsqldb:hsql://localhost:9003"/>
+  <map:parameter name="username" value="sa"/>
+  <map:parameter name="password" value=""/>
+  <map:parameter name="show-nr-of-rows" value="true"/> 
 </map:transform>}}}
 
 I haven't seen this documented anywhere else, but I think its a useful feature. If you use this in conjunction with HSQLDB's in-memory database, you can build and use a database on the fly with no more set up than this. -nicola