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: XfolioOpenOfficeGeneration
Date Sun, 17 Oct 2004 07:30:28 GMT
   Date: 2004-10-17T00:30:27
   Editor: FredericGlorieux <frederic.glorieux@xfolio.org>
   Wiki: Cocoon Wiki
   Page: XfolioOpenOfficeGeneration
   URL: http://wiki.apache.org/cocoon/XfolioOpenOfficeGeneration

   SXWGenerator, implemented and tested

Change Log:

------------------------------------------------------------------------------
@@ -2,45 +2,73 @@
 
 = WHAT =
 
-Open Office Writer generation, one more time.
-The issue is discussed in more than one place (sometimes by me)
-this is my last cocoon solution to have a flat oo xml file,
-with __caching__ !
+http://cvs.berlios.de/cgi-bin/viewcvs.cgi/xfolio/webapp/WEB-INF/classes/org/apache/cocoon/generation/SXWGenerator.java
 
+Here is a regular Cocoon Generator for SXW OpenOffice Writer documents.
+OO becomes more and more a real world production text tool.
+The original format is quite xml, except it is zipped, and could embed other resources
+(images and other media). This generator provides text informations,
+metadatas, and enough styles to resolve some tagging from XSL.
 
-= WHO =
+= STATUS =
 
- *[[Anchor(FG)]] FredericGlorieux [[MailTo(frederic DOT glorieux AT xfolio DOT org)]]
+Tested on thousands of OO docs in production context, 
+proposed as a Cocoon commit if someone wants it. All licence
+mentions could be let to Apache, except author name and company.
 
-= STATUS =
+= WHO =
+
+ [FG] FredericGlorieux http://www.ajlsm.com
 
-It works for me, in hope this helps others.
-For Cocoon 2.1.5
-After more tests, could be proposed as a java generator in default cocoon ?
 
 = CHANGES =
 
-* 2004-06-30:[#FG]  Creation
+ * 2004-10-17:[FG]  Implemented as generator
+ * 2004-06-30:[FG]  Creation as a accheable XSP
 
 = HOW =
 
 {{{
-  <map:match pattern="**.oo">
-    <map:generate type="xsp" src="actions/oo.xsp">
-      <map:parameter name="sxw" value="{myfolder}{1}.sxw"/>
-    </map:generate>
-    <map:serialize type="xml"/>
-  </map:match>
+<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+  <map:components>
+    <map:generators>
+      <map:generator name="sxw" label="content" logger="sitemap.generator.sxw" src="org.apache.cocoon.generation.SXWGenerator"/>
+    </map:generators>
+  </map:components>
+  <map:pipelines>
+    <map:pipeline>
+      <map:match pattern="**.html">
+        <map:select type="exists">
+          <!-- OpenOfficeWriter -->
+          <map:when test="{context-attr:xfolio.efolder}{1}.sxw">
+            <map:generate type="sxw" src="{context-attr:xfolio.efolder}{1}.sxw"/>
+            <map:transform src="transform/oo/oo2html.xsl"/>
+            <map:serialize/>
+          </map:when>
+        </map:select>
+      </map:match>
+    </map:pipeline>
+  </map:pipelines>
+</map:sitemap>
 }}}
 
 = WHY =
 
-I need an OpenOffice generator, not only to provide an HTML view or some other transformation,
-but also to extract metadata on vast amount of documents. So, performances is an issue. I
read all I can about OpenOffice generation and search for the best solution which should be
- * easy
- * fast
- * cacheable
-This one is still implemented as an XSP, because it's easier for testing, and for people
to integrate in their cocoon apps. But in fact, best could be a Cocoon generator.
+OpenOffice Writer documents could be used like other XML documents as sources.
+To provide an HTML view or some other transformation,
+but also to extract metadata on vast amount of documents. 
+So, performances is an issue, a generator should be cacheable.
+
+This was first implemented as an XSP, easy for testing, 
+and for people to integrate in their cocoon apps,
+it's now a Cocoon generator, ready to be commited in cocoon.
+
+Fast performances test (thanks to profiler)
+ * direct pipe cost ~10 ms
+ * xinclude cost ~160ms
+ * cinclude ~320ms
+ * SXWGenerator cost ~200ms on first call, but is _cached_ (~40 ms on second call)
+
 
   == Forget ==
 
@@ -48,7 +76,7 @@
 
   == Forrest ==
 
-The best I found for now come from Forrest, using the new zip protocol from cocoon, able
to resolve things like src="zip://content.xml@{folder}/test.sxw". This is a part of the trick.
The problem of their solution is to use a cinclude transformer, which is not cacheable. I
mean, you need to regenerate your aggregation each time it is requested. This is not a big
problem in Forrest context (essentially generate a site), but on a real life server...
+For now, the best solution is in Forrest, using the new zip protocol from cocoon, able to
resolve things like src="zip://content.xml@{folder}/test.sxw". This is a part of the trick.
The problem of their solution is to use a cinclude transformer, which is not cacheable. You
need to regenerate your aggregation each time it is requested. This is not a big problem in
Forrest context (essentially generate a site), but on a real life server...
 
 Their solution looks like that
 
@@ -81,18 +109,6 @@
 You may say, try a {{{<map:agreggate/>}}}... I tried, and produce so much problems
 of validation that I stopped.
 
-  == oo.xsp ==
-
-The attached xsp do quite the same job as the excellent Forrest solution,
-with these differences
- * the generator is controlled and know the files on which check changes : essentially the
sxw file (and also the xsp, for debug)
-
-
- * performances
-    * direct pipe cost ~10 ms
-    * xinclude cost ~160ms
-    * cinclude ~320ms
-    * oo.xsp generator cost ~200ms on first call, but is _cached_ (~40 ms on second call)
 
 
 
@@ -113,182 +129,3 @@
 || '''cited by'''  || '''about xfolio''' || '''about Open Office''' ||
 || [[FullSearch()]] || [[PageList(xfolio)]] || [[PageList(office)]] ||
 
-= CODE =
-
-{{{
-<xsp:page xmlns:xsp="http://apache.org/xsp">
-  <xsp:structure>
-    <xsp:include>org.apache.excalibur.source.Source</xsp:include>
-    <xsp:include>org.apache.excalibur.source.SourceException</xsp:include>
-    <xsp:include>org.apache.excalibur.source.SourceValidity</xsp:include>
-    <xsp:include>org.apache.cocoon.components.source.SourceUtil</xsp:include>
-    <xsp:include>org.apache.avalon.framework.parameters.ParameterException</xsp:include>
-    <xsp:include>org.apache.excalibur.source.impl.validity.ExpiresValidity</xsp:include>
-    <xsp:include>org.apache.excalibur.source.impl.validity.FileTimeStampValidity</xsp:include>
-    <xsp:include>org.apache.excalibur.source.impl.validity.AggregatedValidity</xsp:include>
-    <xsp:include>org.apache.cocoon.environment.SourceResolver</xsp:include>
-    <xsp:include>java.io.Serializable</xsp:include>
-    <xsp:include>java.util.Map</xsp:include>
-    <xsp:include>org.apache.avalon.framework.parameters.Parameters</xsp:include>
-    <xsp:include>org.apache.cocoon.xml.IncludeXMLConsumer</xsp:include>
-  </xsp:structure>
-  <xsp:logic>
-    // artificial slowdown to make the effects of the cache visible
-    final int DELAY_SECS = 2;
-
-
-    /** The input source */
-    protected Source sxwSource;
-    protected Source xspSource;
-
-    /**
-     * From org.apache.cocoon.generation.FileGenerator
-     *
-     * Setup the file generator.
-     * Try to get the last modification date of the source for caching.
-     */
-
-    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
-        throws ProcessingException, SAXException, IOException {
-
-        super.setup(resolver, objectModel, src, par);
-        String sxw="";
-        try {
-          sxw = (String)parameters.getParameter("sxw");
-          this.sxwSource = super.resolver.resolveURI(sxw);
-        } catch (SourceException se) {
-            throw SourceUtil.handle("oo.xsp, failed resolution sxw='" + sxw +"'.", se );
-        } catch (ParameterException pe) {
-           throw new ProcessingException ("oo.xsp, sxw param not found" , pe);
-        }
-        try {
-            this.xspSource = super.resolver.resolveURI(src);
-        } catch (SourceException se) {
-            throw SourceUtil.handle("oo.xsp, failed resolution xsp='" + src + "'.", se);
-        }
-
-    }
-
-
-    /**
-     * Recycle this component.
-     * All instance variables are set to <code>null</code>.
-     */
-    public void recycle() {
-        if (null != this.sxwSource) {
-            super.resolver.release(this.sxwSource);
-            this.sxwSource = null;
-        }
-        if (this.xspSource != null) {
-            super.resolver.release(this.xspSource);
-            this.xspSource = null;
-        }
-        super.recycle();
-    }
-
-    /**
-    * Generate the unique key for the cache.
-    *
-    * This key must be unique inside the space of this XSP page, it is used
-    * to find the page contents in the cache (if getValidity says that the
-    * contents are still valid).
-    *
-    * This method will be invoked before the getValidity() method.
-    *
-    * @return The generated key or null if the component
-    *         is currently not cacheable.
-    */
-
-    public java.io.Serializable getKey() {
-
-        String key=(this.sxwSource != null)?this.sxwSource.getURI():null;
-        return key;
-    }
-
-    /**
-    * Generate the validity object, tells the cache how long to
-    * keep contents having this key around.
-    *
-    * Before this method can be invoked the getKey() method
-    * will be invoked.
-    *
-    * In our case, validity combine the xsp file and the sxw file.
-    *
-    * @return The generated validity object or null if the
-    *         component is currently not cacheable.
-    */
-    public SourceValidity getValidity() {
-      AggregatedValidity out=new AggregatedValidity();
-      if (this.sxwSource != null) out.add(this.sxwSource.getValidity());
-      if (this.xspSource != null) out.add(this.xspSource.getValidity());
-      return out;
-
-    }
-
-
-
-	</xsp:logic>
-    <office:document
-xmlns:office="http://openoffice.org/2000/office"
-xmlns:style="http://openoffice.org/2000/style"
-xmlns:text="http://openoffice.org/2000/text"
-xmlns:table="http://openoffice.org/2000/table"
-xmlns:draw="http://openoffice.org/2000/drawing"
-xmlns:fo="http://www.w3.org/1999/XSL/Format"
-xmlns:xlink="http://www.w3.org/1999/xlink"
-xmlns:dc="http://purl.org/dc/elements/1.1/"
-xmlns:meta="http://openoffice.org/2000/meta"
-xmlns:number="http://openoffice.org/2000/datastyle"
-xmlns:svg="http://www.w3.org/2000/svg"
-xmlns:chart="http://openoffice.org/2000/chart"
-xmlns:dr3d="http://openoffice.org/2000/dr3d"
-xmlns:math="http://www.w3.org/1998/Math/MathML"
-xmlns:form="http://openoffice.org/2000/form"
-xmlns:script="http://openoffice.org/2000/script"
-xmlns:config="http://openoffice.org/2001/config"
-office:class="text"
-office:version="1.0">
-    <xsp:logic>
-<![CDATA[
-
-/*
-This debug commodity makes you sure that something is cached
-(DELAY_SECS if create, less if cached)
-
-          // slowdown page generation.
-            try {
-              Thread.sleep(DELAY_SECS * 1000L);
-            } catch (InterruptedException ie) {
-              // Not much that can be done...
-            }
-
-*/
-
-/*
-an xpointer may be nicer (to conform to ooxmlflat), but much more
-expensive, because it needs a complete DOM in memory
-
-Semantic transformation seems to be OK without styles.xml
-All useful textual contents are in meta.xml and content.xml (with the generated styles)
-*/
-
-
-// from org.apache.cocoon.transformation.XIncludeTransformer
-SourceUtil.toSAX(
-  super.resolver.resolveURI("zip://meta.xml@"+this.sxwSource.getURI())
-  , new IncludeXMLConsumer(this.contentHandler)
-);
-SourceUtil.toSAX(
-  super.resolver.resolveURI("zip://content.xml@"+this.sxwSource.getURI())
-  , new IncludeXMLConsumer(this.contentHandler)
-);
-
-
-]]>
-    </xsp:logic>
-
-
-    </office:document>
-</xsp:page>
-
-}}}

Mime
View raw message