cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@cocoon.apache.org
Subject [Cocoon Wiki] Updated: SimpleContentModel
Date Fri, 14 Jan 2005 21:03:33 GMT
   Date: 2005-01-14T13:03:33
   Editor: MarkLundquist
   Wiki: Cocoon Wiki
   Page: SimpleContentModel
   URL: http://wiki.apache.org/cocoon/SimpleContentModel

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -1,3 +1,5 @@
+''Author:'' MarkLundquist
+----
 = A simple content model for pages generated from static XML sources =
 
 In a standard Web server (such as [http://httpd.apache.org Apache httpd]), the default interpretation
of the URL path component is as a filesystem pathname relative to the Document``Root directory.
 In Cocoon, there's no default; if a request doesn't match in the sitemap, you get the "No
pipeline matched" error.
@@ -8,10 +10,15 @@
  * Co-location of additional page-specific resources
  * External redirects to a "trailing slash" form of the URL (yes, you '''do''' want this...)
 
+'''Assumptions:'''
+ * You understand the basics of Cocoon and the ([http:http://cocoon.apache.org/2.1/userdocs/concepts/sitemap.html
Cocoon sitemap]
+ * You know the basic pattern for publishing in Cocoon using XLST (SimpleTransformations).
+
 I'll explain the content model by way of examples, and discuss these additional aspects in
context of the examples.    A sitemap fragment implementing all of this is given at the end
of the article.  
 
 You can use this model as a starting point, and modify it according to your needs/tastes/etc.
 
+
 = The Content Model =
 
 OK, then... we start with this directory structure within the webapp directory:
@@ -35,7 +42,7 @@
 
 {{{static/}}} does '''not''' contain any page-specific resources (see below!)
 
-In production, I run Cocoon applications behind an Apache front-end using mod_proxy.  Apache
is configured to serve directly URIs starting with {{{static/}}}, because it can serve static
content so much faster than a servlet container could ever hope to do.  But for development
on my laptop, I don't want to have to run Apache, so the sitemap includes matchers for serving
these static resource with the correct MIME types, and then I can just point my browser at
Cocoon instances running on localhost.
+In production, I run Cocoon applications behind an Apache front-end using mod_proxy.  Apache
is configured to serve directly URIs starting with {{{static/}}}, because it can serve static
content so much faster than a servlet container could ever hope to do.  But for development
on my laptop, I don't want to have to run Apache, so the sitemap includes matchers for serving
these static resources, so that I can just point my browser at Cocoon instances running on
localhost.
 
 == The simplest case ==
 
@@ -100,7 +107,7 @@
 <img src="/static/content/path/to/dogs/Bowser/bad_dog.jpg" />
 }}}
 
-It would be quite undesirable to hard-code the site structure into our XML source document,
so we'll add a template to our stylesheet that lets us just write that as {{{<img src="static/bad_dog.jpg">}}};
the template will rewrite that to the necessary URI in the generated HTML.  See the implementation
notes at the end of this article for the XSLT template.
+It would be quite undesirable to hard-code the site structure into our XML source document
like that, so we'll add a template to our stylesheet that lets us just write that as {{{<img
src="static/bad_dog.jpg">}}}; the template will rewrite that to the necessary URI in the
generated HTML.  See the implementation notes at the end of this article for the XSLT template.
 
 The sitemap looks for {{{Bowser.page/source.xml}}} in {{{content/path/to/dogs}}} if the resource
{{{Bowser.xml}}} (see "The simplest case" above) does not exist there.  So this is really
a "drop-in" content model; the sitemap doesn't have to be told on a page-by-page basis which
resources use the "site-specific assets" model and which have just the source document as
their only asset.
 
@@ -115,12 +122,18 @@
     ''etc...''
 }}}
 
-The tool will create the soft link in {{{static/content}}}, and you
+The tool will create the soft link in {{{static/content}}}, and you can
 reference it in the document like this, e.g.:
 {{{
 <img src="/static/content/path/to/dogs/some-common-image.jpg">
 }}}
 
+If you don't like hard-coding so much site structure into the URI, you can use a relative
link beginning with "static/".  For example, to reference that image from the Bowser.page
example above:
+{{{
+<img src="static/../some-common-image.jpg" />
+}}}
+
+...and the link rewriting template in your stylesheet will do the right thing.  Try it! :-)
 
 == "Trailing slash" resources ==
 
@@ -170,8 +183,6 @@
 
 == The Sitemap ==
 
-Sorry, I use a default namespace in my sitemaps, so you'll have to add "map:" to everything
unless you do the same...
-
 This example assumes that you have a template called "to-html.xslt" that does your page layout/styling.
 
 {{{
@@ -205,35 +216,35 @@
       ++  HTML pages generated from source documents
       -->
 
-    <match pattern="content//**/">
-      <redirect-to uri="content//{1}/main" />
+    <map:match pattern="content//**/">
+      <map:redirect-to uri="content//{1}/main" />
     </match>
 
-    <match pattern="content//**">
-      <select type="resource-exists">
-          <when test="content/{1}.xml">
-            <generate src="content/{1}.xml" />
-          </when>
-          <when test="content/{1}.page">
-            <generate src="content/{1}.page/source.xml" />
-          </when>
-          <when test="content/{1}">
-            <redirect-to uri="/{1}/" global="true" />
-          </when>
-          <otherwise>
+    <map:match pattern="content//**">
+      <map:select type="resource-exists">
+          <map:when test="content/{1}.xml">
+            <map:generate src="content/{1}.xml" />
+          </map:when>
+          <map:when test="content/{1}.page">
+            <map:generate src="content/{1}.page/source.xml" />
+          </map:when>
+          <map:when test="content/{1}">
+            <map:redirect-to uri="/{1}/" global="true" />
+          </map:when>
+          <map:otherwise>
             <!-- we want an error message, so... -->
-            <generate src="content/{1}" /> <!-- (non-existent) -->
-          </otherwise>
-      </select>
-      <serialize type="xml"/>
-    </match>
+            <map:generate src="content/{1}" /> <!-- (non-existent) -->
+          </map:otherwise>
+      </map:select>
+      <map:serialize type="xml"/>
+    </map:match>
 
-    <match pattern="**">
-      <generate src="cocoon:/content//{0}" />
-      <transform src="to-html.xslt">
-         <parameter name="path" value="{0} />
-      </transform>
-    </match>
+    <map:match pattern="**">
+      <map:generate src="cocoon:/content//{0}" />
+      <map:transform src="to-html.xslt">
+         <map:parameter name="path" value="{0} />
+      </map:transform>
+    </map:match>
 }}}
 
 == XSLT template to rewrite URIs for local resources ==
@@ -285,8 +296,15 @@
 }}}
 
 ----
-That's all there is to it!
+
+That's all there is to it! :-)
 
 ----
-''Author:'' MarkLundquist
+= Reader Comments =
+Feedback welcome... add it here, or email me --[wiki:MarkLundquist ML].
+----
+See also:
+[[FullSearch()]]
+----
+
 

Mime
View raw message