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

xml.py

############################################################################
#                                                                          #
#             copyright (c) 2004 ITB, Humboldt-University Berlin           #
#             written by: Raphael Ritz, r.ritz@biologie.hu-berlin.de       #
#                                                                          #
############################################################################

"""XMLRenderer (MODS) class"""

# Python stuff
import os

# Zope stuff
from Globals import InitializeClass
from App.Dialogs import MessageDialog

# CMF stuff
from Products.CMFCore.utils import getToolByName

# Bibliography stuff
from Products.CMFBibliographyAT.tool.renderers.base \
     import IBibliographyRenderer, BibliographyRenderer


00025 class XMLRenderer(BibliographyRenderer):
    """
    specific XML renderer (MODS)
    depends on the BibTeX renderer
    """

    __implements__ = (IBibliographyRenderer ,)

    meta_type = "XML Renderer"

    format = {'name':'XML (MODS)',
              'extension':'xml'}

00038     def __init__(self,
                 id = 'xml_mods',
                 title = "XML (MODS) renderer - depends on the bibtex renderer"):
        """
        initializes id and title
        """
        self.id = id
        self.title = title

00047     def render(self, object):
        """
        renders a bibliography object in XML (MODS) format
        """
        bib_tool = getToolByName(object, 'portal_bibliography')
        bibtex_source = bib_tool.render(object, 'bib')

        # open a pipe
        (fi, fo, fe) = os.popen3('bib2xml ', 't')
        # provide the input
        fi.write(bibtex_source)
        fi.close()
        # get the output
        xml = fo.read()
        fo.close()
        # get the staus/error message
        # (this isn't used but we don't want it in the output)
        error = fe.read()
        fe.close()
        # done
        return xml


# Class instanciation
InitializeClass(XMLRenderer)


def manage_addXMLRenderer(self, REQUEST=None):
    """ """
    try:
        self._setObject('xml_mods', XMLRenderer())
    except:
        return MessageDialog(
            title='Bibliography tool warning message',
            message='The renderer you attempted to add already exists.',
            action='manage_main')
    return self.manage_main(self, REQUEST)

Generated by  Doxygen 1.6.0   Back to index