def _transformSLVToHTML(self, string, editor='kupu', encoding=None):
        """transform Silva XML to HTML"""
        transformer = EditorTransformer(editor=editor)

        # we need to know what browser we are dealing with in order to know
        # what html to produce, unfortunately Mozilla uses different tags in
        # some cases (b instead of strong, i instead of em)
        browser = 'Mozilla'
        if self.REQUEST['HTTP_USER_AGENT'].find('MSIE') > -1:
            browser = 'IE'

        ctx = Context(f=StringIO(),
                        last_version=1,
                        url=self.aq_parent.absolute_url(),
                        browser=browser,
                        model=self.aq_parent)
        ctx.f.write(string)

        htmlnode = transformer.to_target(sourceobj=ctx.f.getvalue(), 
                                            context=ctx)
        if encoding is not None:
            ret = htmlnode.asBytes(encoding=encoding)
            ret = ret.replace('\xa0', ' ')
        else:
            ret = unicode(htmlnode.asBytes('utf8'),'utf8')
            ret = ret.replace(u'\xa0', u' ')

        return ret
    def _transformSLVToHTML(self, string, editor='kupu', encoding=None):
        """transform Silva XML to HTML"""
        transformer = EditorTransformer(editor=editor)

        # we need to know what browser we are dealing with in order to know
        # what html to produce, unfortunately Mozilla uses different tags in
        # some cases (b instead of strong, i instead of em)
        browser = 'Mozilla'
        if self.REQUEST['HTTP_USER_AGENT'].find('MSIE') > -1:
            browser = 'IE'

        ctx = Context(f=StringIO(),
                      last_version=1,
                      url=self.aq_parent.absolute_url(),
                      browser=browser,
                      model=self.aq_parent)
        ctx.f.write(string)

        htmlnode = transformer.to_target(sourceobj=ctx.f.getvalue(),
                                         context=ctx)
        if encoding is not None:
            ret = htmlnode.asBytes(encoding=encoding)
            ret = ret.replace('\xa0', ' ')
        else:
            ret = unicode(htmlnode.asBytes('utf8'), 'utf8')
            ret = ret.replace(u'\xa0', u' ')

        return ret
Пример #3
0
    def get_document_xml_as(self, format='kupu', request=None):
        """Render the Document XML on a different format.
        """
        transformer = EditorTransformer(editor=format)
        context = Context(self, request)

        rendered_document = transformer.to_target(
            sourceobj=self.get_document_xml(), context=context)

        result = unicode(rendered_document.asBytes('utf8'), 'utf8')
        result = result.replace(u'\xa0', u' ')
        return result
Пример #4
0
    def set_document_xml_from(self, data, format='kupu', request=None):
        """Set the document xml of the version from the given data
        in the given format.
        """
        transformer = EditorTransformer(editor=format)
        context = Context(self, request)

        document = transformer.to_source(targetobj=data, context=context)[0]
        title = document.find('title')[0].extract_text()
        content = document.find('doc')[0].asBytes(encoding="UTF8")
        self.content.manage_edit(content)
        self.set_title(title)

        notify(lifecycleevent.ObjectModifiedEvent(self))
    def _transformHTMLToSLV(self, string, editor='kupu', encoding=None):
        """transform (messy structure-wise) HTML to Silva XML"""
        transformer = EditorTransformer(editor=editor)

        # we need to know what browser we are dealing with in order to know
        # what html to produce, unfortunately Mozilla uses different tags in
        # some cases (b instead of strong, i instead of em)
        browser = 'Mozilla'
        if self.REQUEST['HTTP_USER_AGENT'].find('MSIE') > -1:
            browser = 'IE'

        ctx = Context(url=self.aq_parent.absolute_url(),
                        browser=browser,
                        model=self.aq_parent,
                        request=self.REQUEST)
        silvanode = transformer.to_source(targetobj=string, context=ctx)[0]

        title = silvanode.find('title')[0].extract_text() # unicode
        docnode = silvanode.find('doc')[0]
        content = docnode.asBytes(encoding="UTF8") # UTF-8

        return title, content
    def _transformHTMLToSLV(self, string, editor='kupu', encoding=None):
        """transform (messy structure-wise) HTML to Silva XML"""
        transformer = EditorTransformer(editor=editor)

        # we need to know what browser we are dealing with in order to know
        # what html to produce, unfortunately Mozilla uses different tags in
        # some cases (b instead of strong, i instead of em)
        browser = 'Mozilla'
        if self.REQUEST['HTTP_USER_AGENT'].find('MSIE') > -1:
            browser = 'IE'

        ctx = Context(url=self.aq_parent.absolute_url(),
                      browser=browser,
                      model=self.aq_parent,
                      request=self.REQUEST)
        silvanode = transformer.to_source(targetobj=string, context=ctx)[0]

        title = silvanode.find('title')[0].extract_text()  # unicode
        docnode = silvanode.find('doc')[0]
        content = docnode.asBytes(encoding="UTF8")  # UTF-8

        return title, content