You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Yves Vindevogel <yv...@implements.be> on 2003/03/14 12:45:40 UTC

Generator for OpenOffice, think I got it

Hi all,

I think I got a solution to use OpenOffice (Writer) files as a generator in 
Cocoon. 

First of all, thanks to Conal Tuohy and Upayavira for pointing me at some very 
important details.

Okay, what I did ....

My cocoon folder looks like this:
cocoon/resources/entities
cocoon/implements/sxw
cocoon/implements/xsl
cocoon/implements/....

The sitemap for the Implements site, is mounted as a submap of the sitemap in 
the /cocoon directory.

I've got the file "test.sxw" in my directory /implements/sxw
I've got the file "html.oowriter.xsl" in my directory /implements/xsl
I've got the files from, in my case 
opt/OpenOffice.org1.0/share/dtd/officedocument/1_0 (the DTD from OpenOffice) 
copied to the folder /cocoon/resources/entities


This is my sitemap (well, the part for OO)

                	<map:match pattern="sxw/*.html">
                        	<map:aggregate element="office:document">
                                        <map:part 
src="jar:http://web/implements/{1}.sxw!/content.xml"/>
                                        <map:part 
src="jar:http://web/implements/{1}.sxw!/meta.xml"/>
                                </map:aggregate>
                                <map:transform src="xsl/html.oowriter.xsl"/>
                                <map:serialize type="html"/>
                        </map:match>
			<map:match pattern="*.sxw">
                        	<map:read src="{1}.sxw" mime-type="application/zip"/>

                        </map:match>
The basic element is this one is the "jar:http://" thing.  Thanks to Conal for 
pointing me to this.  OpenOffices uses a kind of zip file to store its files 
in.  The Jar: protocol is able to read those zips straight away.  Conal made 
a wiki for this:
http://wiki.cocoondev.org/Wiki.jsp?page=JarProtocolExample

His wiki shows the <map:read>, which works fine.  You can read whatever you 
want from the zip file.

I went further: I wanted to use the content.xml in that zip in a generator.  
So I changed the <map:read> into <map:generate>
This results in an error:

message File "jar:http://web/implements/test.sxw!/office.dtd" not found.

description org.apache.cocoon.ProcessingException: Failed to execute=20
pipeline.: org.xml.sax.SAXParseException: File=20
"jar:http://web/implements/test.sxw!/office.dtd" not found.

This is correct, the dtd is not in the zipped file.  It's only a reference.
I modified the /resources/entities/catalog file.  I added two lines
(Thanks Upayavira for showing me this thing)

-- Open Office DTDs --
PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd"
PUBLIC "-//OpenOffice.org//DTD Manifest 1.0//EN" "Manifest.dtd"

That corrects the error, but gives a new one ....

org.apache.cocoon.ProcessingException:
Failed to execute pipeline.: 
org.xml.sax.SAXParseException: A '(' character or an element type is required 
in the declaration of element type "draw:text-box".

Appearantly, there's something in that file.  I looked at it, but I could not 
find a mistake.  I'm not an expert on those things, so, maybe someone can 
look into it for me ....

I used a workaround however.  You can modify the 
/resources/entities/office.dtd (from OO) file.  There's entries like this:


<!ENTITY % dtypes-mod SYSTEM "dtypes.mod">
%dtypes-mod;
<!ENTITY % nmspace-mod SYSTEM "nmspace.mod">
%nmspace-mod;
<!ENTITY % office-mod SYSTEM "office.mod">
%office-mod;
<!ENTITY % style-mod SYSTEM "style.mod">
%style-mod;
<!ENTITY % meta-mod SYSTEM "meta.mod">
%meta-mod;
<!ENTITY % script-mod SYSTEM "script.mod">
%script-mod;
<!ENTITY % drawing-mod SYSTEM "drawing.mod">
%drawing-mod;
<!ENTITY % text-mod SYSTEM "text.mod">
%text-mod;
<!ENTITY % table-mod SYSTEM "table.mod">
%table-mod;
<!ENTITY % chart-mod SYSTEM "chart.mod">
%chart-mod;
<!ENTITY % datastyl-mod SYSTEM "datastyl.mod">
%datastyl-mod;
<!ENTITY % form-mod SYSTEM "form.mod">
%form-mod;
<!ENTITY % settings-mod SYSTEM "settings.mod">
%settings-mod;


When you remove them all, the generator should work !!!
(Sax does not check a lot, this is a workaround, not a solution ;--)))

Next thing I did, was to use the <map:aggregate> to combine the files from the 
zipped file into one.  I enclose the original xml from all the files in a new 
<office:document> tag.  

After that, it outputs both files as a combined xml file, like we needed ... 
!!!!!

I then reused an xsl file I wrote before, when I extracted the files to xml 
with a little perl too.  This xsl file generates a very simple page in html, 
based on the document ...  (My html uses a library called RelativeLayers, 
this is why you see so many .js files)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/" 
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: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"
xmlns:meta="http://openoffice.org/2000/meta" 
xmlns:manifest="http://openoffice.org/2001/manifest"
office:class="text" office:version="1.0">

	<xsl:param name="relpath"/>
	<xsl:param name="content"/>

	<xsl:template match="office:document">
		<html>
		        <head>
		                <link type="text/css" rel="stylesheet">
                                	<xsl:attribute name="href"><xsl:value-of 
select="$relpath"/>/css/general.css</xsl:attribute>
                                </link>

                                <xsl:if test="$content=''">
                                        <script language="javascript">
                                                <xsl:attribute 
name="src"><xsl:value-of 
select="$relpath"/>/script/rl_error_stripped.js</xsl:attribute>
                                        </script>

                                        <script language="javascript">
                                                <xsl:attribute 
name="src"><xsl:value-of 
select="$relpath"/>/script/rl_browser_stripped.js</xsl:attribute>
                                        </script>

                                        <script language="javascript">
                                                <xsl:attribute 
name="src"><xsl:value-of 
select="$relpath"/>/script/rl_utility_stripped.js</xsl:attribute>
                                        </script>

                                        <script language="javascript">
                                                <xsl:attribute 
name="src"><xsl:value-of 
select="$relpath"/>/script/rl_window_stripped.js</xsl:attribute>
                                        </script>

                                        <script language="javascript">
                                                <xsl:attribute 
name="src"><xsl:value-of 
select="$relpath"/>/script/rl_layer_stripped.js</xsl:attribute>
                                        </script>

                                        <script language="javascript">
                                                <xsl:attribute 
name="src"><xsl:value-of 
select="$relpath"/>/script/rl_source_stripped.js</xsl:attribute>
                                        </script>

                                        <script language="javascript">
                                        layerTitle = new RelativeLayer(
                                                        "divTitle", "", "",
                                                        "100%-2", "20", LEFT, 
"1", TOP, "1", "-50%", "-50%",
                                                        "100%", "100%", LEFT, 
"50%", TOP, "50%", "0", "0",
                                                        "#F0F0F0", "") ;

                                        layerContent = new RelativeLayer(
                                                        "divContent", "", "",
                                                        "100%-2", "100%-23", 
LEFT, "1", TOP, "22", "-50%", "-50%",
                                                        "100%", "100%", LEFT, 
"50%", TOP, "50%", "0", "0",
                                                        "#FFFFFF", "") ;

                                        layerTitle.setVisible (true) ;
                                        layerContent.setVisible (true) ;
                                        </script>
                                </xsl:if>
		        </head>

		        <body>
				<xsl:if test="$content='only'">
                                	<xsl:attribute 
name="class">content</xsl:attribute>
                                </xsl:if>

                        	<xsl:if test="$content=''">
                        		<div id="divTitle" class="title"><xsl:value-of 
select="$content"/><xsl:value-of 
select="office:document-meta/office:meta/dc:title"/></div>

                                        <div id="divContent" class="content">
                                                <iframe src="?content=only" 
style="width:100%; height:100%" frameborder="0"></iframe>
                                        </div>
                          	</xsl:if>

                                <xsl:if test="$content='only'">
					<xsl:for-each select="office:document-content/office:body/*">
						<xsl:apply-templates select="."/>
					</xsl:for-each>
                                </xsl:if>
		        </body>
		</html>
	</xsl:template>

	<xsl:template match="text:p">
		<p>
			<xsl:for-each select="node()">
				<xsl:choose>
					<xsl:when test="name()=''">
						<xsl:value-of select="."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:apply-templates select="."/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</p>
	</xsl:template>

	<xsl:template match="text:p" mode="table">
			<xsl:for-each select="node()">
				<xsl:choose>
					<xsl:when test="name()=''">
						<xsl:value-of select="."/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:apply-templates select="."/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="text:a">
		<a>
			<xsl:attribute name="href"><xsl:value-of 
select="@xlink:href"/></xsl:attribute>
			<xsl:value-of select="."/>
		</a>
	</xsl:template>
	<xsl:template match="table:table">
		<table>
			<xsl:for-each select="table:table-header-rows/table:table-row">
				<tr>
					<xsl:for-each select="table:table-cell">
						<th>
							<xsl:value-of select="text:p"/>
						</th>
					</xsl:for-each>
				</tr>
			</xsl:for-each>
			
			<xsl:for-each select="table:table-row">
				<tr>
						<xsl:choose>
							<xsl:when test="position() mod 2 = 1">
								<xsl:attribute name="class">odd</xsl:attribute>
							</xsl:when>
							<xsl:otherwise>
								<xsl:attribute name="class">even</xsl:attribute>
							</xsl:otherwise>
						</xsl:choose>
					<xsl:for-each select="table:table-cell">
						<td>
							<xsl:apply-templates select="." mode="table"/>
						</td>
					</xsl:for-each>
				</tr>
			</xsl:for-each>
		</table>
	</xsl:template>
	<xsl:template match="text:line-break">
		<br/>
	</xsl:template>

	<xsl:template match="text:h">
		<xsl:choose>
			<xsl:when test="@text:level='1'">
				<h1><xsl:value-of select="."/></h1>
			</xsl:when>
			<xsl:when test="@text:level='2'">
				<h2><xsl:value-of select="."/></h2>
			</xsl:when>
			<xsl:when test="@text:level='3'">
				<h3><xsl:value-of select="."/></h3>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
        
        <xsl:template match="text()"></xsl:template>
</xsl:stylesheet>


Et voila !!!!  That's it ....
Once again, thanks to all who helped.

Could somebody please check this to see if he/she could reproduce my work on 
his/her machine ??



-- 
Met vriendelijke groeten,
Kind regards,
Bien à vous,

Yves Vindevogel

Implements
Kempische Steenweg 206  --  3500 Hasselt  --  Belgium
Phone/Fax: +32 (11) 43.55.76  --  Mobile: +32 (478) 80.82.91
Mail: yves.vindevogel@implements.be  --  www.implements.be

Quote: The winner never says participating is more important than winning.

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org


Re: Generator for OpenOffice, think I got it

Posted by Upayavira <uv...@upaya.co.uk>.
On 14 Mar 2003 at 12:45, Yves Vindevogel wrote:

<snip good stuff/>

Would you be willing to make a Wiki page out of this? Go to: wiki.cocoondev.org.
That would help a lot of people in the future.

Oh, and well done!!

Regards, Upayavira


---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org