[Zope-CVS] CVS: Packages/Moztop/moztopsupport/rdf - __init__.py:1.1 adapter.py:1.1 configure.zcml:1.1 container.py:1.1 interfaces.py:1.1
Sidnei da Silva
sidnei@x3ng.com.br
Thu, 20 Mar 2003 13:24:29 -0500
Update of /cvs-repository/Packages/Moztop/moztopsupport/rdf
In directory cvs.zope.org:/tmp/cvs-serv22557/moztopsupport/rdf
Added Files:
__init__.py adapter.py configure.zcml container.py
interfaces.py
Log Message:
Big refactoring. Renamed idesupport to moztop support. Adding a utility to get Resource Types
=== Added File Packages/Moztop/moztopsupport/rdf/__init__.py ===
##############################################################################
#
# Copyright (c) 2002, 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.
#
##############################################################################
__doc__ = """ RDF Support for Moztop Extension Product
$Id: __init__.py,v 1.1 2003/03/20 18:24:28 sidnei Exp $
"""
=== Added File Packages/Moztop/moztopsupport/rdf/adapter.py ===
##############################################################################
#
# Copyright (c) 2002, 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.
#
##############################################################################
__doc__ = """ Adapters for RDF Support of Moztop Extension Product
$Id: adapter.py,v 1.1 2003/03/20 18:24:28 sidnei Exp $
"""
from moztopsupport.rdf.interfaces import IRDFNode, IRDFContainer
from moztopsupport.interfaces import IResourceTypesUtility
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.component import getAdapter, getView, getUtility
class RDFNode:
'''RDF representation of a node.'''
__implements__ = IRDFNode
def __init__(self, object):
self.context = object
def getInfo(self, id, request):
context = self.context
dc = getAdapter(context, IZopeDublinCore)
url = str(getView(context, 'absolute_url', request))
utility = getUtility(self.context, IResourceTypesUtility)
resource_type = utility.getResourceTypeFor(self.context).lower()
fillIn = {'title' : dc.title or id,
'rdf_url' : url,
'type' : resource_type}
return fillIn
class RDFContainer:
'''RDF representation of a Container.'''
__implements__ = IRDFContainer
def __init__(self, object):
self.context = object
def getInfo(self, request):
context = self.context
url = str(getView(context, 'absolute_url', request))
items = context.items()
subs = []
for item in items:
subs.append('%s/%s' % (url, item[0]))
return subs
=== Added File Packages/Moztop/moztopsupport/rdf/configure.zcml ===
<zopeConfigure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser" >
<browser:pages
for="zope.app.interfaces.container.IContainer"
permission="zope.View"
class=".container.Contents" >
<browser:page name="contents.rdf" attribute="contents" />
<browser:page name="resource_types.rdf" attribute="resource_types" />
</browser:pages>
<adapter
provides=".interfaces.IRDFNode"
for="*"
permission="zope.ManageContent"
factory=".adapter.RDFNode"
/>
<adapter
provides=".interfaces.IRDFContainer"
for="zope.app.interfaces.container.IReadContainer"
permission="zope.ManageContent"
factory=".adapter.RDFContainer"
/>
</zopeConfigure>
=== Added File Packages/Moztop/moztopsupport/rdf/container.py ===
##############################################################################
#
# Copyright (c) 2002, 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.
#
##############################################################################
__doc__ = """ Container RDF views.
$Id: container.py,v 1.1 2003/03/20 18:24:28 sidnei Exp $
"""
from zope.app.browser.container.adding import Adding
from zope.component import getUtility, getService, getView, queryAdapter, getAdapter
from zope.app.interfaces.container import IContainer, IReadContainer, IZopeContainer
from zope.app.interfaces.services.service import IServiceManagerContainer
from zope.proxy.context import ContextWrapper
from zope.publisher.browser import BrowserView
from zope.app.content.folder import RootFolder
from zope.proxy.introspection import removeAllProxies
from zope.app.traversing import traverse
from moztopsupport.rdf.interfaces import IRDFNode, IRDFContainer
from moztopsupport.interfaces import IResourceTypesUtility
class Contents(BrowserView):
"""Displays Container content (generated recursively) in Moztop-readable
RDF format."""
def _makeSubtree(self, id, base):
"""Create the contents tree in RDF format. This is of course a
recursive method."""
rdf = ''
fillIn = {}
rdf_node = queryAdapter(base, IRDFNode)
if rdf_node is not None:
fillIn = rdf_node.getInfo(id, self.request)
fillIn = removeAllProxies(fillIn)
rdf += _node % fillIn
rdf_container = queryAdapter(base, IRDFContainer)
if fillIn and rdf_container is not None:
subs = rdf_container.getInfo(self.request)
if subs:
subs_rdf = ''
for sub in subs:
subs_rdf += _sub_node % ({'rdf_url':sub})
rdf += _sub_nodes % ({'rdf_url':fillIn['rdf_url'],
'subs_rdf':subs_rdf})
if fillIn and IReadContainer.isImplementedBy(base):
items = base.items()
for id, obj in items:
w_obj = ContextWrapper(obj, base, name=id)
rdf += self._makeSubtree(id, w_obj)
return rdf
def contents(self):
"""API method that outputs the created contents RDF content
directly."""
context = self.context
rdf = _rdf_start
rdf += self._makeSubtree('', self.context)
#smc = queryAdapter(self.context, IServiceManagerContainer)
#if smc is not None:
# sm = smc.queryServiceManager(None)
# if sm is not None:
# sm = ContextWrapper(sm, self.context, name='++etc++Services')
# rdf += self._makeSubtree('', sm, prefix='configurations')
rdf += _rdf_end
self.request.response.setHeader('Content-Type', 'text/xml')
return rdf
def resource_types(self):
"""API method that outputs the available resource types
RDF directly"""
utility = getUtility(self.context, IResourceTypesUtility)
available_types = utility.getAvailableResourceTypes()
rdf = _resource_start
for t in available_types:
rdf += _resource_node % {'resource_type':''.join(t.lower().split()), \
'title':t }
rdf += _resource_end
self.request.response.setHeader('Content-Type', 'text/xml')
return rdf
# Some useful raw RDF snippets.
_rdf_start = '''\
<?xml version="1.0"?>
<rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:nc="http://home.netscape.com/NC-rdf#"
xmlns:dc="http://www.purl.org/dc/1.1#"
xmlns:oscom="http://www.oscom.org/rdf#"
xmlns:D="http://www.webdav.org/rdf#">
'''
_rdf_end = '''\
</rdf:rdf>
'''
_node = '''\
<rdf:description
rdf:about="%(rdf_url)s">
<dc:title>%(title)s</dc:title>
<oscom:resourcetype rdf:resource="urn:moztop:resourcetypes:%(type)s"/>
</rdf:description>
'''
_sub_node = '''<rdf:li resource="%(rdf_url)s"/>'''
_sub_nodes = '''\
<rdf:description
rdf:about="%(rdf_url)s">
<nc:subitems>
<rdf:seq>
%(subs_rdf)s
</rdf:seq>
</nc:subitems>
</rdf:description>'''
_resource_start = '''\
<?xml version="1.0"?>
<rdf:rdf xmlns:dc="http://www.purl.org/dc/1.1#"
xmlns:oscom="http://www.oscom.org/rdf#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
'''
_resource_node = '''\
<rdf:description about="urn:moztop:resourcetypes:%(resource_type)s">
<dc:title>%(title)s</dc:title>
<oscom:styleid>%(resource_type)s</oscom:styleid>
</rdf:description>
'''
_resource_end = '''\
</rdf:rdf>
'''
=== Added File Packages/Moztop/moztopsupport/rdf/interfaces.py ===
##############################################################################
#
# Copyright (c) 2002, 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.
#
##############################################################################
__doc__ = """ Interfaces definition for RDF Support of Moztop Extension Product
$Id: interfaces.py,v 1.1 2003/03/20 18:24:28 sidnei Exp $
"""
from zope.interface import Interface
class IRDFNode(Interface):
'''RDF representation of a node.'''
def getInfo():
'''Returns a dict containing the needed data to build
a RDF node.'''
class IRDFContainer(Interface):
'''RDF representation of a container.'''
def getInfo():
'''Returns a list of the subitems for building
a RDF container.'''