1
##############################################################################
3
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
6
# This software is subject to the provisions of the Zope Public License,
7
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
13
##############################################################################
14
"""DTML Page content component
16
$Id: dtmlpage.py 67630 2006-04-27 00:54:03Z jim $
18
__docformat__ = 'restructuredtext'
20
from persistent import Persistent
22
from zope.documenttemplate.untrusted import UntrustedHTML
23
from zope.interface import implements
24
from zope.annotation.interfaces import IAnnotatable
25
from zope.filerepresentation.interfaces import IFileFactory
27
from zope.app.container.contained import Contained
28
from zope.app.publication.interfaces import IFileContent
30
from interfaces import IDTMLPage, IRenderDTMLPage
32
class DTMLPage(Persistent, Contained):
33
implements(IDTMLPage, IRenderDTMLPage, IFileContent, IAnnotatable)
35
def __init__(self, source=''):
36
self.setSource(source)
39
'''See interface `IDTMLPage`'''
40
return self.template.read()
42
def setSource(self, text, content_type='text/html'):
43
'''See interface `IDTMLPage`'''
44
self.template = UntrustedHTML(text)
45
self.content_type = content_type
47
def render(self, request, *args, **kw):
48
"""See interface `IDTMLRenderPage`"""
49
return self.template(self.__parent__, request, REQUEST=request, **kw)
54
source = property(getSource, setSource, None,
55
"""Source of the DTML Page.""")
57
class DTMLFactory(object):
58
implements(IFileFactory)
60
def __init__(self, context):
61
self.context = context
63
def __call__(self, name, content_type, data):
65
r.setSource(data, content_type or 'text/html')