[Zope-CVS] CVS: Packages/Moztop/idesupport/rdf - adapter.py:1.1 interfaces.py:1.1 configure.zcml:1.3 container.py:1.7
Sidnei da Silva
sidnei@x3ng.com.br
Sat, 8 Mar 2003 15:01:05 -0500
Update of /cvs-repository/Packages/Moztop/idesupport/rdf
In directory cvs.zope.org:/tmp/cvs-serv6471/idesupport/rdf
Modified Files:
configure.zcml container.py
Added Files:
adapter.py interfaces.py
Log Message:
re-enabling zope3 support.
=== Added File Packages/Moztop/idesupport/rdf/adapter.py ===
from interfaces import IRDFNode, IRDFContainer
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.component import getAdapter, getView
class RDFNode:
'''RDF representation of a node.'''
__implements__ = IRDFNode
def __init__(self, object):
self.context = object
def _getContentType(self):
"""This method is used to determine the Content Type name of an
object."""
obj = self.context
return obj.__class__.__name__
def getInfo(self, id, request, _prefix=''):
context = self.context
dc = getAdapter(context, IZopeDublinCore)
url = str(getView(context, 'absolute_url', request))
if _prefix:
if not _prefix.startswith(':'):
_prefix = ':' + _prefix
if not _prefix.endswith(':'):
_prefix = _prefix + ':'
fillIn = {'title' : dc.title or id,
'rdf_url' : _prefix + id ,
'identifier' : url,
'type' : self._getContentType()}
return fillIn
class RDFContainer:
'''RDF representation of a Container.'''
__implements__ = IRDFContainer
def __init__(self, object):
self.context = object
def getInfo(self, _prefix=''):
context = self.context
items = context.items()
if _prefix:
if not _prefix.startswith(':'):
_prefix = ':' + _prefix
if not _prefix.endswith(':'):
_prefix = _prefix + ':'
subs = []
for item in items:
subs.append(_prefix + item[0])
return subs
=== Added File Packages/Moztop/idesupport/rdf/interfaces.py ===
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.'''
=== Packages/Moztop/idesupport/rdf/configure.zcml 1.2 => 1.3 ===
--- Packages/Moztop/idesupport/rdf/configure.zcml:1.2 Wed Jan 15 07:40:50 2003
+++ Packages/Moztop/idesupport/rdf/configure.zcml Sat Mar 8 15:00:33 2003
@@ -11,4 +11,18 @@
</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>
=== Packages/Moztop/idesupport/rdf/container.py 1.6 => 1.7 ===
--- Packages/Moztop/idesupport/rdf/container.py:1.6 Thu Feb 20 18:28:37 2003
+++ Packages/Moztop/idesupport/rdf/container.py Sat Mar 8 15:00:33 2003
@@ -16,10 +16,12 @@
$Id$
"""
from zope.app.browser.container.adding import Adding
-from zope.component import getFactoryInterfaces, getService
+from zope.component import getFactoryInterfaces, getService, getView, queryAdapter, getAdapter
from zope.app.interfaces.container import IContainer, IZopeContainer
from zope.publisher.browser import BrowserView
from zope.app.content.folder import RootFolder
+from interfaces import IRDFNode, IRDFContainer
+from zope.proxy.introspection import removeAllProxies
class Contents(BrowserView):
"""Displays Container content (generated recursively) in Moztop-readable
@@ -27,79 +29,49 @@
__used_for__ = IContainer
- # Variable containing a map of Content Type names --> interfaces
- _map = None
-
- # ******************************************************************
- # XXX: The following two methods a re a horrible hack, since Zope 3
- # does not have a concept of a Content Type yet. I can't wait
- # for the day when Content Types are mapped to one particular
- # interface.
-
- def _createNameInterfacesMapping(self):
- """Creates a map of Content Type names and their associated
- interfaces."""
- if self._map is not None:
- return self._map
- self._map = {}
- info = Adding(self.context, self.request).addingInfo()
- service = getService(None, 'Factories')
- for type in info:
- self._map[type['action']] = service.getInterfaces(type['action'])
- return self._map
-
- def _getContentTypeOfObject(self, obj):
- """This method is used to determine the Content Type name of an
- object."""
- # Handle RootFolder special, since it is not in Factory Service
- if obj.__class__ == RootFolder:
- # Do not make this lower case!
- return 'Folder'
- service = getService(None, 'Factories')
- for name in service._GlobalFactoryService__factories.keys():
- try:
- if obj.__class__ == service.createObject(name).__class__:
- return name
- except:
- pass
# ******************************************************************
def _makeSubtree(self, id, base, prefix=''):
"""Create the contents tree in RDF format. This is of course a
recursive method."""
- rdf = ''
- fillIn = {'title': id[1:],
- 'site_id': self.site_id,
- 'rdf_url': prefix + id,
- 'sub_nodes': '',
- 'type': self._getContentTypeOfObject(base)}
- if fillIn['type'] in ['Folder', 'RootFolder']:
- items = base.items()
- subs = []
- for item in items:
- subs.append(
- ' <rdf:li resource="urn:moztop:sites:%s:content%s:%s"/>' %(
- self.site_id, fillIn['rdf_url'], item[0]))
- if subs:
- fillIn['sub_nodes'] = "\n" + _sub_nodes %'\n'.join(subs)
- rdf += _node %fillIn
-
- for item in items:
- rdf += self._makeSubtree(':'+item[0], item[1],
- fillIn['rdf_url'])
- else:
- rdf += _node %fillIn
-
+ rdf = ''
+ realm = self.realm
+ fillIn = {}
+
+ if queryAdapter(base, IRDFNode):
+ node = getAdapter(base, IRDFNode)
+ fillIn = node.getInfo(id, self.request, prefix)
+ fillIn = removeAllProxies(fillIn)
+ fillIn.update({'realm':realm})
+ rdf += _node % fillIn
+
+ if fillIn and queryAdapter(base, IRDFContainer):
+ _prefix = fillIn['rdf_url'] or ':'
+ subs = getAdapter(base, IRDFContainer).getInfo(_prefix)
+ subs_rdf = ''
+ for sub in subs:
+ subs_rdf += _sub_node % ({'realm':realm, 'rdf_url':sub})
+ rdf += _sub_nodes % ({'realm':realm, 'rdf_url':fillIn['rdf_url'],
+ 'subs_rdf':subs_rdf})
+
+ if fillIn and queryAdapter(base, IZopeContainer):
+ container = getAdapter(base, IZopeContainer)
+ items = container.items()
+ _prefix = fillIn['rdf_url'] or ':'
+ for id, obj in items:
+ rdf += self._makeSubtree(id, obj,
+ _prefix)
return rdf
def contents(self):
"""API method that outputs the created contents RDF content
directly."""
- # XXX: Some more sophisticated site id calculation should go here
- self.site_id = 'localhost'
+ context = self.context
+ view = getView(context, 'config.xml', self.request)
+ self.realm = view.getRealm()
rdf = _rdf_start
rdf += self._makeSubtree('', self.context)
rdf += _rdf_end
@@ -122,20 +94,21 @@
_node = '''
<rdf:description
- rdf:about="urn:moztop:sites:%(site_id)s:content%(rdf_url)s">
+ rdf:about="urn:moztop:sites:%(realm)s:content%(rdf_url)s">
<dc:title>%(title)s</dc:title>
+ <dc:identifier>%(identifier)s</dc:identifier>
<site:resourcetype resource="urn:moztop:resourcetypes:%(type)s"/>
</rdf:description>
-
-<rdf:description
- rdf:about="urn:moztop:sites:%(site_id)s:content%(rdf_url)s">
-%(sub_nodes)s
-</rdf:description>
'''
+_sub_node = '''<rdf:li resource="urn:moztop:sites:%(realm)s:content%(rdf_url)s"/>'''
+
_sub_nodes = '''\
+<rdf:description
+ rdf:about="urn:moztop:sites:%(realm)s:content%(rdf_url)s">
<nc:subitems>
<rdf:seq>
-%s
+%(subs_rdf)s
</rdf:seq>
- </nc:subitems>'''
+ </nc:subitems>
+</rdf:description>'''