[Commits] (pavlov) ContentItemizing RSSChannel and RSSItem

commits at osafoundation.org commits at osafoundation.org
Thu Jan 15 14:46:40 PST 2004


Commit by: pavlov
Modified files:
osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/RSSData.py 1.7 1.8
osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/ZaoBaoAgent.py 1.8 1.9
osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/parcel.xml 1.10 1.11

Log message:
ContentItemizing RSSChannel and RSSItem


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/RSSData.py.diff?r1=text&tr1=1.7&r2=text&tr2=1.8
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/ZaoBaoAgent.py.diff?r1=text&tr1=1.8&r2=text&tr2=1.9
http://cvs.osafoundation.org/index.cgi/osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/parcel.xml.diff?r1=text&tr1=1.10&r2=text&tr2=1.11

Index: osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/RSSData.py
diff -u osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/RSSData.py:1.7 osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/RSSData.py:1.8
--- osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/RSSData.py:1.7	Fri Dec  5 15:06:36 2003
+++ osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/RSSData.py	Thu Jan 15 14:46:09 2004
@@ -1,15 +1,51 @@
-__revision__  = "$Revision: 1.7 $"
-__date__      = "$Date: 2003/12/05 23:06:36 $"
+__revision__  = "$Revision: 1.8 $"
+__date__      = "$Date: 2004/01/15 22:46:09 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
+import application.Globals as Globals
 from repository.item.Item import Item
 from repository.util.Path import Path
+from repository.parcel.Parcel import Parcel
+from OSAF.contentmodel.ContentModel import ContentItem
 import mx.DateTime
 import types
 
-BASE_PATH = '//parcels/OSAF/examples/zaobao'
-RSSITEM_KIND_PATH = BASE_PATH + '/RSSItem'
+##
+# ZaoBaoParcel
+##
+class ZaoBaoParcel(Parcel):
+    def __init__(self, name, parent, kind):
+        Parcel.__init__(self, name, parent, kind)
+
+    def _setUUIDs(self):
+        ZaoBaoParcel.RSSChannelKindID = self.find('RSSChannel').getUUID()
+        ZaoBaoParcel.RSSItemKindID = self.find('RSSItem').getUUID()
+
+    def onItemLoad(self):
+        super(ZaoBaoParcel, self).onItemLoad()
+        self._setUUIDs()
+
+    def startupParcel(self):
+        super(ZaoBaoParcel, self).startupParcel()
+        self._setUUIDs()
+
+    def getRSSChannelKind(cls):
+        assert cls.RSSChannelKindID, "ZaoBaoParcel not yet loaded"
+        return Globals.repository[cls.RSSChannelKindID]
+
+    getRSSChannelKind = classmethod(getRSSChannelKind)
+
+    def getRSSItemKind(cls):
+        assert cls.RSSItemKindID, "ZaoBaoParcel not yet loaded"
+        return Globals.repository[cls.RSSItemKindID]
+
+    getRSSItemKind = classmethod(getRSSItemKind)
+    
+    # The parcel knows the UUIDs for the Kinds, once the parcel is loaded
+    RSSChannelKindID = None
+    RSSItemKindID = None
+
 
 def SetAttribute(self, data, attr, nattr=None, encoding=None):
     if not nattr:
@@ -29,17 +65,14 @@
             SetAttribute(self, data, attr, encoding=encoding)
 
 
-class RSSChannel(Item):
-    def __getItemsParent(self):
-        repository = self.getRepository()
-        parent = repository.find('//userdata/contentitems')
-        if parent:
-            return parent
-        itemKind = repository.find('//Schema/Core/Item')
-        userdata = repository.find('//userdata')
-        if not userdata:
-            userdata = itemKind.newItem('userdata', repository)
-        return itemKind.newItem('contentitems', userdata)
+##
+# RSSChannel
+##
+class RSSChannel(ContentItem):
+    def __init__(self, name=None, parent=None, kind=None):
+        if not kind:
+            kind = ZaoBaoParcel.getRSSChannelKind()
+        super(RSSChannel, self).__init__(name, parent, kind)
 
     def Update(self, data):
         # get the encoding
@@ -70,14 +103,22 @@
 
     def _DoItems(self, items, encoding):
         # make children
-        itemKind = self.getRepository().find(RSSITEM_KIND_PATH)
         for itemData in items:
             #print 'new item'
-            item = itemKind.newItem(None, self.__getItemsParent())
+            item = RSSItem()
             item.Update(itemData, encoding)
             self.addValue('items', item)
 
-class RSSItem(Item):
+
+##
+# RSSItem
+##
+class RSSItem(ContentItem):
+    def __init__(self, name=None, parent=None, kind=None):
+        if not kind:
+            kind = ZaoBaoParcel.getRSSItemKind()
+        super(RSSItem, self).__init__(name, parent, kind)
+
     def Update(self, data, encoding):
         # fill in the item
         attrs = {'title':'displayName'}

Index: osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/parcel.xml
diff -u osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/parcel.xml:1.10 osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/parcel.xml:1.11
--- osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/parcel.xml:1.10	Fri Dec  5 15:06:36 2003
+++ osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/parcel.xml	Thu Jan 15 14:46:09 2004
@@ -2,11 +2,13 @@
 
 <Parcel describes="//parcels/OSAF/examples/zaobao"
         itemName="zaobao"
+        itemClass="OSAF.examples.zaobao.RSSData.ZaoBaoParcel"
         xmlns="//Schema/Core"
         xmlns:zaobao="//parcels/OSAF/examples/zaobao"
         xmlns:foo="//parcels/OSAF/framework"
         xmlns:bar="//parcels/OSAF/framework/agents"
-        xmlns:agent="//parcels/OSAF/framework/agents/schema">
+        xmlns:agent="//parcels/OSAF/framework/agents/schema"
+        xmlns:content="//parcels/OSAF/contentmodel">
 
   <displayName>ZaoBao RSS Schema</displayName>
   <description>RSS schema for ZaoBao parcel for 0.2 release</description>
@@ -102,7 +104,7 @@
     <attributes itemref="zaobao:RSSChannel/isUnread"/>
     <attributes itemref="zaobao:RSSChannel/items"/>
 
-    <superKinds itemref="Item"/>
+    <superKinds itemref="content:ContentItem"/>
     <classes key="python">OSAF.examples.zaobao.RSSData.RSSChannel</classes>
   </Kind>  
 
@@ -125,7 +127,7 @@
     <attributes itemref="zaobao:date"/>
 
     <attributes itemref="zaobao:RSSItem/channel"/>
-    <superKinds itemref="Item"/>
+    <superKinds itemref="content:ContentItem"/>
     <classes key="python">OSAF.examples.zaobao.RSSData.RSSItem</classes>
   </Kind>
 

Index: osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/ZaoBaoAgent.py
diff -u osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/ZaoBaoAgent.py:1.8 osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/ZaoBaoAgent.py:1.9
--- osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/ZaoBaoAgent.py:1.8	Fri Dec  5 15:06:36 2003
+++ osaf/chandler/Chandler/parcels/OSAF/examples/zaobao/ZaoBaoAgent.py	Thu Jan 15 14:46:09 2004
@@ -1,15 +1,17 @@
-__revision__  = "$Revision: 1.8 $"
-__date__      = "$Date: 2003/12/05 23:06:36 $"
+__revision__  = "$Revision: 1.9 $"
+__date__      = "$Date: 2004/01/15 22:46:09 $"
 __copyright__ = "Copyright (c) 2003 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
 from repository.item.Item import Item
+from repository.item.Query import KindQuery
 from OSAF.framework.agents.schema.Action import Action
+from OSAF.examples.zaobao.RSSData import ZaoBaoParcel,RSSChannel
 
 import feedparser
 
 _defaultBlogs = [ "http://www.pavlov.net/blog/rss10.rdf", \
-                  "http://blogs.osafoundation.org/news/index.rdf", \
+                  "http://www.osafoundation.org/rss/2.0/", \
                   "http://blogs.osafoundation.org/devnews/index.rdf", \
                   "http://blogs.osafoundation.org/zaobao/index.rdf", \
                   "http://blogs.osafoundation.org/mitch/index.rdf", \
@@ -18,12 +20,9 @@
                   "http://blogs.osafoundation.org/blogotomy/index.rdf", \
                   "http://lessig.org/blog/index.xml", \
                   "http://diveintomark.org/xml/rss.xml",
-                  "http://slashdot.org/index.rss",
                   "http://www.scripting.com/rss.xml",
                   "http://xml.newsisfree.com/feeds/15/2315.xml"]
 
-BASE_PATH = '//parcels/OSAF/examples/zaobao'
-
 class UpdateAction(Action):
     def Execute(self, agent, notification):
         repository = self.getRepository()
@@ -42,18 +41,19 @@
         #print 'Updated feeds'
 
     def __getFeeds(self):
-        repository = self.getRepository()
-        chanKind = repository.find(BASE_PATH + '/RSSChannel')
+
+        chanKind = ZaoBaoParcel.getRSSChannelKind()
 
         feeds = []
-        parent = repository.find(BASE_PATH)
 
-        for url in _defaultBlogs:
-            urlhash = str(hash(url))
-            item = repository.find(BASE_PATH + '/' + urlhash)
-            if not item:
-                item = chanKind.newItem(urlhash, parent)
-                item.url = url
+        for item in KindQuery().run([chanKind]):
             feeds.append(item)
+
+        # auto generate some feeds if there aren't any in the repository
+        if len(feeds) == 0:
+            for url in _defaultBlogs:
+                item = RSSChannel()
+                item.url = url
+                feeds.append(item)
 
         return feeds



More information about the Commits mailing list