[Zope3-checkins] CVS: zopeproducts/xml/xslt - README.txt:1.1 __init__.py:1.1 configure.zcml:1.1 foursuitetransformer.py:1.1 sheet.py:1.1

Philipp von Weitershausen philikon@philikon.de
Fri, 20 Jun 2003 11:11:42 -0400


Update of /cvs-repository/zopeproducts/xml/xslt
In directory cvs.zope.org:/tmp/cvs-serv15767/xml/xslt

Added Files:
	README.txt __init__.py configure.zcml foursuitetransformer.py 
	sheet.py 
Log Message:
Moved the xml_examples, xslt, xslt_examples and xmldom products to one
xml product.


=== Added File zopeproducts/xml/xslt/README.txt ===

XSLT support for Zope3
======================

Installation
============

In order to use this product, you will have to include the package in
your products.zcml file.

Requirements
============

Currently, this product requires 4Suite 1.0a1 or higher.

Example
=======

Please check out zopeproducts/xslt_example for an example.

Later on we may want to implement a special ZCML directive to set up
an XSLT adapter which converts from one XML schema to another one
using an XSLT style sheets like this:

  <zopexml:xsltadapter
    for="http://xml.zope.org/xml_examples/apple"
    provides="http://xml.zope.org/xml_examples/pear"
    xslt="apple-pear.xsl" />


=== Added File zopeproducts/xml/xslt/__init__.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: __init__.py,v 1.1 2003/06/20 15:11:41 philikon Exp $
"""


=== Added File zopeproducts/xml/xslt/configure.zcml ===
<zopeConfigure
   xmlns="http://namespaces.zope.org/zope"
   xmlns:zopexml="http://namespaces.zope.org/zope-xml">

<!-- XXX security for some reason doesn't let us use this? -->
<utility factory=".foursuitetransformer.FourSuiteTransformer"
         provides="zopeproducts.xml.interfaces.xslt.IXSLTTransformer"
         permission="zope.View" />

</zopeConfigure>


=== Added File zopeproducts/xml/xslt/foursuitetransformer.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: foursuitetransformer.py,v 1.1 2003/06/20 15:11:41 philikon Exp $
"""

from StringIO import StringIO

from zope.interface import implements
from zope.component import getAdapter
from zope.app.interfaces.xml.source import IXMLText
from zope.app.xml.w3cschemalocations import\
     setInstanceInterfacesForXMLText

from Ft.Xml.Xslt import Processor, XsltException
from Ft.Xml.InputSource import InputSource

from zopeproducts.xml.interfaces.xslt import IXSLTTransformer, XSLTError

class XMLText:

    implements(IXMLText)

    def __init__(self, xml="<doc/>"):
        self.source = xml
        setInstanceInterfacesForXMLText(self)

class FourSuiteTransformer:
    """
    XSLT transformer using 4Suite
    """

    implements(IXSLTTransformer)

    def transform(self, xslt, xml):
        namespaceMap = {} #XXX
        processor = Processor.Processor()

        xslt_text = getAdapter(xslt, IXMLText)
        xml_text = getAdapter(xml, IXMLText)

        try:
            # XXX URN resolver
            # XXX catalogs
            xml_source = InputSource(StringIO(xml_text.source), ".") #XXX no URI
            xslt_source = InputSource(StringIO(xslt_text.source), ".") #XXX no URI
            processor.appendStylesheet(xslt_source)
            result = processor.run(xml_source)

        except XsltException, e:
            raise XSLTError(str(e))
            
        except (XPath.RuntimeException, XPath.CompiletimeException), e:
            if hasattr(e, 'stylesheetUri'):
                message = "While processing %s\n%s" % e.stylesheetUri, str(e)
                raise XSLTError(message)
            else:
                raise XSLTError(str(e))

        return XMLText(result)


=== Added File zopeproducts/xml/xslt/sheet.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: sheet.py,v 1.1 2003/06/20 15:11:41 philikon Exp $
"""

from zope.interface import implements
from zope.component import getUtility
from zope.app.interfaces.xml.source import IXMLText
from zopeproducts.xml.interfaces.xslt import IXSLTSheet, IXSLTTransformer
from zope.proxy import removeAllProxies

__metaclass__ = type

class XSLTSheet:
    """
    A XSLT sheet

    Objects of this class instanciated with XSLT data can act as adapter
    factories
    """
    implements(IXSLTSheet, IXMLText)

    def __init__(self, xslt_text):
        self.source = xslt_text

    def __call__(self, context):
        transformer = getUtility(context, IXSLTTransformer)
        # XXX don't know why we don't have the right security context
        transformer = removeAllProxies(transformer)
        return transformer.transform(self, context)