[Zope-CVS] CVS: Packages/Moztop/moztopsupport/rdf - resource_types.pt:1.1 adapter.py:1.2 configure.zcml:1.2 container.py:1.2 contents.pt:1.2 interfaces.py:1.2

Stephan Richter srichter@cbu.edu
Fri, 21 Mar 2003 08:54:22 -0500


Update of /cvs-repository/Packages/Moztop/moztopsupport/rdf
In directory cvs.zope.org:/tmp/cvs-serv16555/moztopsupport/rdf

Modified Files:
	adapter.py configure.zcml container.py contents.pt 
	interfaces.py 
Added Files:
	resource_types.pt 
Log Message:
Fixed up moztopsupport to return correct and complete RDF for contents.rdf
and resource_types.rdf, but the work is not yet done.

I would like to move all RDF generation to the RDFNode and RDFContainer 
for the contents.rdf.


=== Added File Packages/Moztop/moztopsupport/rdf/resource_types.pt ===
<?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#">


<RDF:Description about="urn:moztop:resourcetypes:site">
  <dc:title>Site</dc:title>
  <site:styleid>site</site:styleid>
</RDF:Description>

<RDF:Description about="urn:moztop:resourcetypes:configurations">
  <dc:title>Configurations</dc:title>
  <site:styleid>configurations</site:styleid>
</RDF:Description>

<RDF:Description about="urn:moztop:resourcetypes:content">
  <dc:title>Content</dc:title>
  <site:styleid>Content</site:styleid>
</RDF:Description>

<RDF:Description about="urn:moztop:resourcetypes:packages">
  <dc:title>Packages</dc:title>
  <site:styleid>packages</site:styleid>
</RDF:Description>

<RDF:Description about="urn:moztop:resourcetypes:package">
  <dc:title>Package</dc:title>
  <site:styleid>package</site:styleid>
</RDF:Description>

<descriptions tal:replace="structure view/getResourceTypes" />

</rdf:RDF>


=== Packages/Moztop/moztopsupport/rdf/adapter.py 1.1 => 1.2 ===
--- Packages/Moztop/moztopsupport/rdf/adapter.py:1.1	Thu Mar 20 13:24:28 2003
+++ Packages/Moztop/moztopsupport/rdf/adapter.py	Fri Mar 21 08:53:51 2003
@@ -30,17 +30,31 @@
         self.context = object
 
     def getInfo(self, id, request):
-        context = self.context
-        dc = getAdapter(context, IZopeDublinCore)
-        url = str(getView(context, 'absolute_url', request))
+        dc = getAdapter(self.context, IZopeDublinCore)
+        url = str(getView(self.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
+        return {'title' : dc.title or id,
+                'rdf_url' : url,
+                'type' : resource_type}
+
+    def getListEntry(self, id, request):
+        return self._listEntry %self.getInfo(id, request)
+
+    def getDescription(self, id, request):
+        return self._description %self.getInfo(id, request)
+
+    _listEntry = '''      <rdf:li resource="%(rdf_url)s"/>\n'''
+
+    _description = '''\
+<rdf:Description rdf:about="%(rdf_url)s">
+  <dc:title>%(title)s</dc:title>
+  <oscom:resourcetype rdf:resource="urn:moztop:resourcetypes:%(type)s"/>
+</rdf:Description>
+
+'''
+
 
 class RDFContainer:
     '''RDF representation of a Container.'''


=== Packages/Moztop/moztopsupport/rdf/configure.zcml 1.1 => 1.2 ===
--- Packages/Moztop/moztopsupport/rdf/configure.zcml:1.1	Thu Mar 20 13:24:28 2003
+++ Packages/Moztop/moztopsupport/rdf/configure.zcml	Fri Mar 21 08:53:51 2003
@@ -6,10 +6,14 @@
       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>
 
+  <browser:pages
+      for="zope.app.interfaces.container.IContainer"
+      permission="zope.View" 
+      class=".container.ResourceTypes" >
+    <browser:page name="resource_types.rdf" attribute="resource_types" />
   </browser:pages>
 
   <adapter 


=== Packages/Moztop/moztopsupport/rdf/container.py 1.1 => 1.2 ===
--- Packages/Moztop/moztopsupport/rdf/container.py:1.1	Thu Mar 20 13:24:28 2003
+++ Packages/Moztop/moztopsupport/rdf/container.py	Fri Mar 21 08:53:51 2003
@@ -11,27 +11,105 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-__doc__ = """ Container RDF views.
+"""This module contains views that return RDF datasources for a site.
 
 $Id$
 """
 
-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.container import IReadContainer
+from zope.app.interfaces.dublincore import IZopeDublinCore
 from zope.app.interfaces.services.service import IServiceManagerContainer
+from zope.app.interfaces.traversing import IObjectName
+
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.app.traversing import traverse
+from zope.component import getUtility, getView, queryAdapter, getAdapter
+from zope.proxy.introspection import removeAllProxies
 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."""
 
+    ##################
+    # View methods required for the contents.rdf page template
+
+    def getSiteURL(self):
+        """Return the site URL."""
+        return str(getView(self.context, 'absolute_url', self.request))
+
+
+    def getSiteURN(self):
+        """Get the URN of the site."""
+        return '%s/%s' %(self.getSiteURL(), 'rsd.xml')
+
+
+    def getSiteTitle(self):
+        """Get the title of the site."""
+        dc = getAdapter(self.context, IZopeDublinCore)
+        title = dc.title
+        if not title:
+	    title = str(getAdapter(self.context, IObjectName))
+	if not title:
+            title = 'Zope 3 at ' + str(getView(
+                self.context, 'absolute_url', self.request))
+        return title
+
+
+    def getSiteContentList(self):
+        """Return an list of the content (RDF string)"""
+        rdf = "\n"
+        for id, obj in self.context.items():
+            wrapped = ContextWrapper(obj, self.context, name=id)
+            node = queryAdapter(wrapped, IRDFNode)
+            rdf += node.getListEntry(id, self.request)
+        return rdf + "    "
+
+
+    def getSiteContentDescriptions(self):
+        """Return all content descriptions (RDF string)"""
+        rdf = "\n"
+        for id, obj in self.context.items():        
+            wrapped = ContextWrapper(obj, self.context, name=id)            
+            rdf +=  self._makeSubtree(id, wrapped)
+        return rdf
+
+
+    def getPackageList(self):
+        """Return an list of the packages (RDF string)"""
+        rdf = "\n"
+        packages = self._getServiceManager()
+        for id, pkg in packages.items():
+            wrapped = ContextWrapper(pkg, packages, name=id)
+            node = queryAdapter(wrapped, IRDFNode)
+            rdf += node.getListEntry(id, self.request)
+        return rdf + "    "
+
+
+    def getPackageDescriptions(self):
+        """Return all pacakge descriptions (RDF string)"""
+        rdf = "\n"
+        packages = self._getServiceManager()
+        for id, pkg in packages.items():
+            wrapped = ContextWrapper(pkg, packages, name=id)
+            rdf +=  self._makeSubtree(id, wrapped)
+        return rdf
+
+    #
+    ##################
+
+    def _getServiceManager(self):
+        """Return local Service Manager"""
+        smc = queryAdapter(self.context, IServiceManagerContainer)
+        sm = smc.queryServiceManager(None)
+        return ContextWrapper(sm, self.context, name='++etc++Services')
+
+
     def _makeSubtree(self, id, base):
         """Create the contents tree in RDF format. This is of course a
         recursive method."""
@@ -39,11 +117,9 @@
         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
+        node = queryAdapter(base, IRDFNode)
+        if node is not None:
+            rdf += node.getDescription(id, self.request)
 
         rdf_container = queryAdapter(base, IRDFContainer)
         if fillIn and rdf_container is not None:
@@ -51,7 +127,7 @@
             if subs:
                 subs_rdf = ''
                 for sub in subs:
-                    subs_rdf += _sub_node % ({'rdf_url':sub})
+                    subs_rdf += _sub_node %{'rdf_url' : sub}
                 rdf += _sub_nodes % ({'rdf_url':fillIn['rdf_url'],
                                       'subs_rdf':subs_rdf})
 
@@ -64,84 +140,55 @@
 
 
     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
+        self.request.response.setHeader('content-type', 'text/xml')
+        return self._template()
+    
+    _template = ViewPageTemplateFile("contents.pt")
 
-    def resource_types(self):
+
+class ResourceTypes(BrowserView):
+    """A view that manages the RDF listing of all available resource types."""
+    
+    def getResourceTypes(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')
+        rdf = ""
+        for type in available_types:
+            rdf += _resource_node % {
+                'resource_type' : ''.join(type.lower().split()),
+                'title' : type}
         return rdf
 
-# Some useful raw RDF snippets.
-_rdf_start = '''\
-<?xml version="1.0"?>
+    def resource_types(self):
+        self.request.response.setHeader('content-type', 'text/xml')
+        return self._template()
 
-<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#">
-'''
+    _template = ViewPageTemplateFile("resource_types.pt")
 
-_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>
-'''
+# Some useful raw RDF snippets.
 
-_sub_node = '''<rdf:li resource="%(rdf_url)s"/>'''
+_sub_node = '''      <rdf:li resource="%(rdf_url)s"/>\n'''
 
 _sub_nodes = '''\
-<rdf:description
-     rdf:about="%(rdf_url)s">
+<rdf:Description rdf:about="%(rdf_url)s">
   <nc:subitems>
-    <rdf:seq>
+    <rdf:Seq>
 %(subs_rdf)s
-    </rdf:seq>
+    </rdf:Seq>
   </nc:subitems>
-</rdf:description>'''
+</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>
-'''
+<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>
 '''
+
+


=== Packages/Moztop/moztopsupport/rdf/contents.pt 1.1 => 1.2 ===
--- Packages/Moztop/moztopsupport/rdf/contents.pt:1.1	Thu Mar 20 17:45:14 2003
+++ Packages/Moztop/moztopsupport/rdf/contents.pt	Fri Mar 21 08:53:51 2003
@@ -23,24 +23,24 @@
 </rdf:Description>
 
 <rdf:Description rdf:about="http://localhost:8080/++etc++Services/Views"
-    tal:attributes="rdf:about string:$(view/getSiteURL)/++etc++Services/Views">
+    tal:attributes="rdf:about string:${view/getSiteURL}/++etc++Services/Views">
   <dc:title>Views</dc:title>
   <oscom:resourcetype rdf:resource="urn:moztop:resourcetypes:views"/>
 </rdf:Description>
 
 <rdf:Description 
     rdf:about="http://localhost:8080/++etc++Services/Configurations"
-    tal:attributes="rdf:about string:$(view/getSiteURL)/++etc++Services/Configurations">
+    tal:attributes="rdf:about string:${view/getSiteURL}/++etc++Services/Configurations">
   <dc:title>Configurations</dc:title>
   <oscom:resourcetype rdf:resource="urn:moztop:resourcetypes:configurations"/>
 </rdf:Description>
 
 <rdf:Description rdf:about="http://localhost:8080/"
-    tal:attributes="rdf:about string:$(view/getSiteURL)/">
+    tal:attributes="rdf:about string:${view/getSiteURL}/">
   <dc:title>Content</dc:title>
   <oscom:resourcetype rdf:resource="urn:moztop:resourcetypes:content"/>
   <nc:subitems>
-    <rdf:Seq tal:content="view/getSiteContentList">
+    <rdf:Seq tal:content="structure view/getSiteContentList">
       <rdf:li resource="http://localhost:8080/Folder1" />
     </rdf:Seq>
   </nc:subitems>
@@ -48,24 +48,24 @@
 
 <rdf:Description
     rdf:about="http://localhost:8080/++etc++Services/Bundles"
-    tal:attributes="rdf:about string:$(view/getSiteURL)/++etc++Services/Bundles">
+    tal:attributes="rdf:about string:${view/getSiteURL}/++etc++Services/Bundles">
   <dc:title>Bundles</dc:title>
   <oscom:resourcetype rdf:resource="urn:moztop:resourcetypes:bundles"/>
 </rdf:Description>
 
 <rdf:Description rdf:about="http://localhost:8080/++etc++Services/Packages"
-    tal:attributes="rdf:about string:$(view/getSiteURL)/++etc++Services/Packages">
+    tal:attributes="rdf:about string:${view/getSiteURL}/++etc++Services/Packages">
   <dc:title>Packages</dc:title>
   <oscom:resourcetype rdf:resource="urn:moztop:resourcetypes:packages"/>
   <nc:subitems>
-    <rdf:Seq tal:content="view/getPackageList">
+    <rdf:Seq tal:content="structure view/getPackageList">
       <rdf:li 
           resource="http://localhost:8080/++etc++/Services/Packages/default" />
     </rdf:Seq>
   </nc:subitems>
 </rdf:Description>
 
-<descriptions tal:replace="view/getSiteContentDescriptions" />
-<descriptions tal:replace="view/getPackageDescriptions" />
+<descriptions tal:replace="structure view/getSiteContentDescriptions" />
+<descriptions tal:replace="structure view/getPackageDescriptions" />
 
 </rdf:RDF>


=== Packages/Moztop/moztopsupport/rdf/interfaces.py 1.1 => 1.2 ===
--- Packages/Moztop/moztopsupport/rdf/interfaces.py:1.1	Thu Mar 20 13:24:28 2003
+++ Packages/Moztop/moztopsupport/rdf/interfaces.py	Fri Mar 21 08:53:51 2003
@@ -25,6 +25,12 @@
         '''Returns a dict containing the needed data to build
         a RDF node.'''
 
+    def getListEntry():
+        """Return a rdf:li element for this node."""
+
+    def getDescription():
+        """Return a rdf:Description for this node."""
+
 
 class IRDFContainer(Interface):
     '''RDF representation of a container.'''