[Zope-CVS] CVS: Packages/Moztop/idesupport/rdf - container.py:1.6

Stephan Richter srichter@cbu.edu
Thu, 20 Feb 2003 18:28:38 -0500


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

Modified Files:
	container.py 
Log Message:
Fixed contents.rdf to return the correct RDF Paul wants. Wrote some 
comments in the code too for better understanding.


=== Packages/Moztop/idesupport/rdf/container.py 1.5 => 1.6 ===
--- Packages/Moztop/idesupport/rdf/container.py:1.5	Thu Feb 20 17:17:49 2003
+++ Packages/Moztop/idesupport/rdf/container.py	Thu Feb 20 18:28:37 2003
@@ -22,12 +22,23 @@
 from zope.app.content.folder import RootFolder
 
 class Contents(BrowserView):
+    """Displays Container content (generated recursively) in Moztop-readable
+    RDF format."""
 
     __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 = {}
@@ -38,9 +49,12 @@
         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:
-            return 'folder'
+            # Do not make this lower case!
+            return 'Folder'
         service = getService(None, 'Factories')
         for name in service._GlobalFactoryService__factories.keys():
             try:
@@ -48,36 +62,32 @@
                     return name
             except:
                 pass
-            
-    def _createContentList(self):
-        adding = Adding(self.context, self.request)
-        info = adding.addingInfo()
-        res = ""
-##        for type in info:
-##            res += ('  <rdf:Description ' +
-##                    'ID="%(action)s" dc:title="%(title)s"/>\n' %type)
-        return res
 
-    def _make_subtree(self, id, base, prefix=''):
+    # ******************************************************************
+            
+    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:localhost:content%s:%s"/>' %(
-                    fillIn['rdf_url'], item[0]))
+                    '      <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._make_subtree(':'+item[0], item[1],
+                rdf += self._makeSubtree(':'+item[0], item[1],
                                           fillIn['rdf_url'])
         else:
             rdf += _node %fillIn
@@ -86,36 +96,46 @@
 
 
     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'
         rdf  = _rdf_start
-        rdf +=  self._make_subtree('', self.context)
-        rdf += _rdf_end %self._createContentList()
+        rdf +=  self._makeSubtree('', self.context)
+        rdf += _rdf_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#"
+<rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:nc="http://home.netscape.com/NC-rdf#"
          xmlns:site="http://www.zope.org/rdf#"
          xmlns:dc="http://www.purl.org/dc/1.1#">
 '''
 
 _rdf_end = '''
-%s
-</rdf:RDF>
+</rdf:rdf>
 '''
 
 _node = '''
-<rdf:Description rdf:about="urn:moztop:sites:localhost:content%(rdf_url)s">%(sub_nodes)s
+<rdf:description
+     rdf:about="urn:moztop:sites:%(site_id)s:content%(rdf_url)s">
   <dc:title>%(title)s</dc:title>
   <site:resourcetype resource="urn:moztop:resourcetypes:%(type)s"/>
-</rdf:Description>
+</rdf:description>
+
+<rdf:description
+     rdf:about="urn:moztop:sites:%(site_id)s:content%(rdf_url)s">
+%(sub_nodes)s
+</rdf:description>
 '''
 
 _sub_nodes = '''\
   <nc:subitems>
-    <rdf:Seq>
+    <rdf:seq>
 %s
-    </rdf:Seq>
+    </rdf:seq>
   </nc:subitems>'''