You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2006/08/25 17:20:52 UTC

svn commit: r436827 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples: java/zipping.xsp samples.xml sitemap.xmap

Author: anathaniel
Date: Fri Aug 25 08:20:50 2006
New Revision: 436827

URL: http://svn.apache.org/viewvc?rev=436827&view=rev
Log:
XSP block: Add example for on-the-fly generation of ZIP file.

Added:
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/zipping.xsp   (with props)
Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/sitemap.xmap

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/zipping.xsp
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/zipping.xsp?rev=436827&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/zipping.xsp (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/zipping.xsp Fri Aug 25 08:20:50 2006
@@ -0,0 +1,78 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<!-- CVS $Id$ -->
+
+<!--
+  This XSP produces markup for the ZipArchiveSerializer to zip all java/*.xsp files.
+  
+  Note that this simple example could as well be implemented using the
+  DirectoryGenerator and transformed by a stylesheet to zip: markup.
+-->
+ 
+<xsp:page language="java"
+          xmlns:zip="http://apache.org/cocoon/zip-archive/1.0"
+          xmlns:xsp="http://apache.org/xsp">
+
+  <xsp:structure>
+    <xsp:include>org.apache.excalibur.source.impl.FileSource</xsp:include>
+    <xsp:include>java.io.File</xsp:include>
+  </xsp:structure>
+  
+  <zip:archive>
+    <xsp:logic>
+    
+      // Get the samples/java directory.
+      // File URIs are resolved relative to the location of the sitemap.xmap.
+      
+      FileSource source = null;
+      File dir = null;
+      try {
+        source = (FileSource) resolver.resolveURI("java");
+        dir = source.getFile();
+      }
+      finally {
+        resolver.release(source);
+      }
+        
+      // Scan directory for *.xsp files.
+      
+      File[] files = dir.listFiles();
+
+      boolean found = false;
+      for ( int i = 0, n = files.length; i &lt; n; i++ ) {
+        File file = files[i];
+        String filename = file.getName();
+        if ( !filename.endsWith(".xsp") ) continue;
+        found = true;
+      
+        <zip:entry>
+          <xsp:attribute name="name"><xsp:expr>filename</xsp:expr></xsp:attribute>
+          <xsp:attribute name="src"><xsp:expr>file.getPath()</xsp:expr></xsp:attribute>
+        </zip:entry>
+      } // for files
+
+      // ZIP files cannot be completely empty.      
+      if ( !found ) {
+        <zip:entry name="README.txt" serializer="text">
+          No match for *.xsp in <xsp:expr>dir.getPath()</xsp:expr>.
+        </zip:entry>
+      } // if !found
+    </xsp:logic>
+  </zip:archive>
+</xsp:page>

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/zipping.xsp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/java/zipping.xsp
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml?rev=436827&r1=436826&r2=436827&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/samples.xml Fri Aug 25 08:20:50 2006
@@ -74,6 +74,9 @@
    <sample name="Escaping" href="java/escaping" xlink:role="dynamic">
     Escaping of non-ASCII characters.
    </sample>
+   <sample name="Zipping" href="java/zipping.zip" xlink:role="dynamic">
+    On-the-fly zipping of filtered files.
+   </sample>
   </group>
 
   <group name="eXtensible Server Pages in Javascript">

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/sitemap.xmap
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/sitemap.xmap?rev=436827&r1=436826&r2=436827&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/sitemap.xmap (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/xsp/samples/sitemap.xmap Fri Aug 25 08:20:50 2006
@@ -57,6 +57,11 @@
         <map:serialize/>
       </map:match>
 
+      <map:match pattern="java/*.zip">
+        <map:generate src="java/{1}.xsp" type="serverpages" label="content"/>
+        <map:serialize type="zip"/>
+      </map:match>
+
       <map:match pattern="java/*">
         <map:generate src="java/{1}.xsp" type="serverpages"/>
         <map:transform src="context://samples/stylesheets/dynamic-page2html.xsl">