cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [WIKI-UPDATE] HowTos BringMeThisExample Gzip_XML_Serializer Wed Mar 19 17:00:04 2003
Date Wed, 19 Mar 2003 16:00:04 GMT
Page: , version: 81 on Wed Mar 19 15:20:38 2003
by BruceRobertson

- * __[Embed SVG Fonts|Embedding_SVG_Fonts]__  -- description of Cocoon-based tools that add
the svg:glyph elements necessary to render its text elements on a client lacking the specified
fonts. [BruceRobertson]

+ * __[Embed SVG Fonts|Embedding_SVG_Fonts]__  -- description of Cocoon-based tools that add
the svg:glyph elements necessary to render its text elements on a client lacking the specif.
+ * __[Gzipped Compress XML Output|Gzip_XML_Serializer]__  -- description of a serializer
that produces Gzipped XML output. Useful for generating *.svgz files, among other things.

Page: , version: 30 on Wed Mar
19 15:34:47 2003 by NicolaKen

- #Beep Beep
- ''And now'' 
- __ Che bello questo cms :-) __
- [linksite]
- ghjhghjghjgjgj

Page: , version: 1 on Wed Mar
19 15:59:58 2003 by BruceRobertson

New page created:
+ !Introduction
+ XML is meant to be human-readable. Often this means that the markup is pointlessly verbose
from the machine's standpoint. The common solution is to compress the XML -- the SVG spec,
for instance, stipulates that SVG viewers need to be able to read gzipped files as well as
uncompressed equivalent; and numerous applications, from Gnumeric to OpenOffice, compress
their XML before saving. When files are being sent over the internet, compression can make
the difference between impracticality and practicality. Working with SVG maps at the Heml
Project, I found I was producing files well over 500k in size. These could never be served
to the modem-connected great unwashed, but their gzipped equivalent, weighing in at less than
100k, could.
+ For more than a year, I used the mod_gzip module for Apache to do the compression -- an
effort partly described at [Cocoon_and_Apache_mod_gzip] --, but this was never entirely satisfactory.
mod_gzip is meant for compressing html and is based on the httpd negotiation between client
and server. A client must declare in its request header that it can handle gzip content. However,
SVG viewers and plugins rightly won't send this information, yet they can all digest svgz
conent. Secondly, any post-cocoon solution means that cocoon's cache will gobble up more of
your RAM by caching the uncompressed XML. If we could serialize the result within Cocoon,
its cache would hold the smaller gzipped version. (Someone correct me if Cocoon in fact compresses
the contents of its cache.)
+ !Enter GzipXMLSerializer
+ After some fiddling, I have come up with a hack on Cocoon's XMLSerializer that serializes
compressed XML content. For those interesting in the programming, the code is available through
+ [ViewCVS page |].
If this were to be integrated into Cocoon's API, I would recommend factoring out what is common
between XMLSerializer and this, then making both a subclass. If you just want to use the darn
thing to compress your own SVG, read on.
+ !Using GzipXMLSerializer
+ To use the GzipXMLSerializer, you'll need to download {{heml-cocoon-0_5.4-dev-20030221.jar}}
or later, found at []. You __don't__ need the massive {{heml-cocoon.war}}
file. This should go in your {{$TOMCAT/cocoon/WEB-INF/lib}} directory.
+ Next, you'll need to declare the serializer in the Serializers section of your sitemap,
+ {{    <map:serializers default="html">\\
+       <map:serializer name="gzip" mime-type="image/svg+xml"\\ src="org.heml.cocoon.serialization.GzipXMLSerializer"/>\\
+       <!-- all the other usual definitions go here -->\\
+       <!-- ... -->\\
+       </map:serializers>\\
+ }}
+ Finally, use the serializer as you would any other. I map the filename extension in this
way so that we can get png, svg or svgz :
+ {{
+ <!-- the part of the name after the dot indicates what sort of output we want -->
+               <map:select type="parameter">
+                 <map:parameter name="parameter-selector-test" value="{../../../2}"/>
+                 <map:when test="svg">
+                   <map:serialize type="svgxml"/>
+                 </map:when>
+                 <map:when test="jpg">
+                   <map:serialize type="svg2jpeg"/>
+                 </map:when>
+                 <map:when test="png">
+                   <map:serialize type="svg2png"/>
+                 </map:when>
+                 <map:when test="rss">
+                   <map:serialize type="xml"/>
+                 </map:when>
+                 <map:when test="xml">
+                   <map:serialize type="xml"/>
+                 </map:when>
+                 <map:when test="svgz">
+                   <map:serialize type="gzip"/>
+                 </map:when>
+               </map:select>
+ }}

View raw message