[Zope3-checkins] CVS: zopeproducts/xslt - README.txt:1.1 __init__.py:1.1 configure.zcml:1.1 foursuitetransformer.py:1.1 interfaces.py:1.1 sheet.py:1.1
Martijn Faassen
m.faassen@vet.uu.nl
Sun, 13 Apr 2003 11:58:04 -0400
Update of /cvs-repository/zopeproducts/xslt
In directory cvs.zope.org:/tmp/cvs-serv23322
Added Files:
README.txt __init__.py configure.zcml foursuitetransformer.py
interfaces.py sheet.py
Log Message:
Added initial version of xslt package. This package defines a simple
(currently too simple) way to plug in different XSLT transformation engines
into Zope using a utility. One utility based on 4suite is provided.
See the xslt_examples (checked in after this) for an early example of
usage.
=== Added File zopeproducts/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/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/04/13 15:58:03 faassen Exp $
"""
=== Added File zopeproducts/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=".interfaces.IXSLTTransformer"
permission="zope.View" />
</zopeConfigure>
=== Added File zopeproducts/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/04/13 15:58:03 faassen Exp $
"""
from StringIO import StringIO
from interfaces import IXSLTTransformer, XSLTError
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
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/xslt/interfaces.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: interfaces.py,v 1.1 2003/04/13 15:58:03 faassen Exp $
"""
from zope.interface import Interface
class XSLTError(Exception):
pass
class IXSLTTransformer(Interface):
"""
Transforms XML using XSLT
"""
def tranform(xslt, xml):
"""
Transforms xml according to xslt. Both xml and xslt have to implement
IXMLSource. The result will also be an IXMLSource.
"""
class IXSLTSheet(Interface):
"""
An XSLT sheet
"""
def __call__(xml):
"""
Transforms xml which is an IXMLSource
"""
=== Added File zopeproducts/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/04/13 15:58:03 faassen Exp $
"""
from zope.component import getUtility
from zope.app.interfaces.xml.source import IXMLText
from zopeproducts.xslt.interfaces import IXSLTSheet, IXSLTTransformer
from zope.proxy.introspection 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)