Commit bdcdd216 authored by Fabien Devaux's avatar Fabien Devaux

Added inclusion of OLE documents and pictures.

See readme.txt for details.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6328 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2ee54c09
This diff is collapsed.
......@@ -34,7 +34,10 @@ from xml.dom import Node
from AccessControl import ClassSecurityInfo
from Globals import InitializeClass, get_request
from zipfile import ZipFile, ZIP_DEFLATED
from StringIO import StringIO
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
from zLOG import LOG
import imghdr
import random
......@@ -72,6 +75,7 @@ class OOoBuilder:
else :
self._document = StringIO(document)
self._image_count = 0
self._manifest_additions_list = []
security.declarePublic('replace')
def replace(self, filename, stream):
......@@ -83,6 +87,13 @@ class OOoBuilder:
zf = ZipFile(self._document, mode='a', compression=ZIP_DEFLATED)
except RuntimeError:
zf = ZipFile(self._document, mode='a')
try:
# remove the file first if it exists
fi = zf.getinfo(filename)
zf.filelist.remove( fi )
except KeyError:
# This is a new file
pass
zf.writestr(filename, stream)
zf.close()
......@@ -97,6 +108,16 @@ class OOoBuilder:
zf = ZipFile(self._document, mode='r')
return zf.read(filename)
security.declarePublic('getNameList')
def getNameList(self):
try:
zf = ZipFile(self._document, mode='r', compression=ZIP_DEFLATED)
except RuntimeError:
zf = ZipFile(self._document, mode='r')
li = zf.namelist()
zf.close()
return li
security.declarePublic('getMimeType')
def getMimeType(self):
return self.extract('mimetype')
......@@ -124,6 +145,40 @@ class OOoBuilder:
tal:attributes='dummy python:request.RESPONSE.setHeader("Content-Type", "text/html;; charset=utf-8")'
office:version='1.0'""")
"""
"""
security.declarePublic('addFileEntry')
def addFileEntry(self, full_path, media_type, content=None):
""" Add a file entry to the manifest and possibly is content """
self.addManifest(full_path, media_type)
if content:
self.replace(full_path, content)
security.declarePublic('addManifest')
def addManifest(self, full_path, media_type):
""" Add a path to the manifest """
li = '<manifest:file-entry manifest:media-type="%s" manifest:full-path="%s"/>'%(media_type, full_path)
self._manifest_additions_list.append(li)
security.declarePublic('updateManifest')
def updateManifest(self):
""" Add a path to the manifest """
MANIFEST_FILENAME = 'META-INF/manifest.xml'
meta_infos = self.extract(MANIFEST_FILENAME)
# prevent some duplicates
for meta_line in meta_infos.split('\n'):
for new_meta_line in self._manifest_additions_list:
if meta_line.strip() == new_meta_line:
self._manifest_additions_list.remove(new_meta_line)
# add the new lines
self._manifest_additions_list.append('</manifest:manifest>')
meta_infos = meta_infos.replace( self._manifest_additions_list[-1], '\n'.join(self._manifest_additions_list) )
self.replace(MANIFEST_FILENAME, meta_infos)
self._manifest_additions_list = []
security.declarePublic('addImage')
def addImage(self, image, format='png'):
"""
......@@ -300,8 +355,12 @@ class OOoParser:
if document:
try:
object_content = self.reader.fromString(self.oo_files[document[3:] + '/content.xml'])
for table in object_content.getElementsByTagName("table:table"):
tables = object_content.getElementsByTagName("table:table")
if tables:
for table in tables:
spreadsheets.append(table)
else: # XXX: insert the link to OLE document ?
pass
except:
pass
return spreadsheets
......
......@@ -9,7 +9,7 @@ OOo Templates allow to generate dynamic OpenOffice.org documents based
on templates.
</p>
<form action="addOOoTemplate" method="POST">
<form action="addOOoTemplate" enctype="multipart/form-data" method="POST">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
......@@ -34,6 +34,17 @@ on templates.
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-optional">
File
</div>
</td>
<td align="left" valign="top">
<input type="file" name="file" size="25" value="" />
</td>
</tr>
<tr>
<td align="left" valign="top">
</td>
......
......@@ -10,6 +10,34 @@ OOo Template
Rendering consists in replacing content.xml of the original OOo document
with the content.xml generated by the OOo Template.
Special tags for including content:
- <office:include>
Allow you to include another document in the current template (as an OLE attachment)
You must specify at least the path (can be either a single name or a path name using "/")
and the type of the document (generally calc or writer), the default is zope's content-type.
The size is always specified in centimeters (with attached "cm" suffix or not).
You can specify the style (defined in the sylesheet) with the "style" option.
You can also pass "x" and "y" attributes for positioning, it's mainly useful for draw documents.
Example:
<office:include type="calc" width="10.100cm" height="16.000cm" path="agenda" />
<office:include width="15" height="20" path="/reports/my_report" />
<office:include path="foo" />
- <office:include_img>
Not unlike <office:include>, allows you to include a picture document, refer to
the <office:include> part for details.
The optional "type" attribute specifies the picture format ; you can either
pass a full value ("image/jpeg") or the short version ("jpeg").
You can also pass position parameters with "x" and "y" attributes.
The maxwidth and maxheight parameters are useful to set constraints.
The aspect ratio information try to be kept (if you set only one size
or if a constraint is applied).
Example:
<office:include x="5cm" y="1cm" path="foo" />
Tips:
- it is possible to embed images by calling oo_builder.addImage(image)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment