Logo Search packages:      
Sourcecode: zope-attachmentfield version File versions  Download package

def AttachmentField::ooconverter::oo_to_html::cook (   self,
  document,
  encoding = None 
)

object usable converter
render the document by xslt to html
document needs to be a DynZip instance

Definition at line 197 of file ooconverter.py.

00197                                            :
        """ 
        object usable converter
        render the document by xslt to html
        document needs to be a DynZip instance
        """

        params={}
        # default params
        packageURL='doc'
        params.update({  'absoluteSourceDirRef': "'%s'" % (packageURL)
                        , 'disableLinkedTableOfContent': 'true()'
                        , 'disableJava': 'false()'
                        , 'dpi': "'86'"
                })

        if _DEBUG_XSLT:
            params.update({'debug': 'true()'})

        # create temp files
        tmpfiles=[]
        for f in (('stylesFileURL','styles.xml'), ('metaFileURL','meta.xml')):
            # get unique filename and write contents to this file
                try:
                    t=tempfile.mktemp()
                    tmpfiles.append(t)
                    file=open(t, 'wb', -1)
                    file.write(document.read(f[1]))
                    file.close()
                    # update the parameters to reflect the temporary files
                    params.update({f[0]: "'%s'" % (t)})
                except: pass

        # libxml2 encoding translation
        xmlOutEnc=self.getOutEncoding(default=encoding)
        # read the content xml
        thisdoc=document.read('content.xml')
        # parse the content
        doc=libxml2.parseDoc(thisdoc)
        # apply the stylesheet (xslt transformation)
        result=_style.applyStylesheet(doc, params)
        # write html to string
        html=result.serialize(encoding=xmlOutEnc)
        # free memory
        result.freeDoc()
        doc.freeDoc()

        try:
            # return parsed rendered document parts
            # (headers, styles, body, images)
            body, styles = self.parseText(html)
            images = self.parseImages(html)
            headers = self.parseMetadata(document.read('meta.xml'))
            return headers, styles, body, images

        finally:
            # clean up created temp files
            for t in tmpfiles:
                try: os.unlink(t)
                except: pass


    def parseMetadata(self, xml):


Generated by  Doxygen 1.6.0   Back to index