5 Replies Latest reply on May 22, 2009 2:22 PM by Production Monkey

    RSS on Director?

    ginod Level 1

      Director support RSS channels?

       

      Regards

        • 1. Re: RSS on Director?
          Production Monkey Level 3

          Sure can.

          • 2. Re: RSS on Director?
            ginod Level 1

            where do i start?

            • 3. Re: RSS on Director?
              Production Monkey Level 3

              An old post of mine: http://forums.adobe.com/message/27729#27729

               

              The code seems to have been lost when Adobe changed forum servers, so here it is.

               

              --  Basic RSS

              -- Copyright Randal Holmes 2009
              -- MIT license  http//www.opensource.org/licenses/mit-license.php

              -- Public Properties
              property  source  -- the text string returned from the server
              property  channel  -- list of channel information if any
              property  feed  -- list of feed information if any
              property  items  -- list of lists. Data for each item if any
              property  entries  -- list of lists. Data for each entry is any


              -- Private Properties
              property  Ancestor  -- proplist version of any returned xml
              property  pNetOpData  -- proplist of data used in talking to the internet and making a callback
              property  pUpdateInterval  -- the time in milliseconds between retrieving data from the server
              property  pUpdateTimeOb  -- timeout object used to make the updateInterval call


              ------------------------------------------------------------------------------------------ --------
              -- PUBLIC METHODS
              ------------------------------------------------------------------------------------------ --------

              on new me, URL, DataList, CallingOb, CallbackHandler  -- String, Propery List, Object, Symbol
                --
                -- Sample ("http//www.mydomain/getData.php",["name""myName","password""lk93mdkf"], Object, #objectHandler)
                -- Sample  GoogleUK_RSS = script("Basic RSS").new("http//news.google.com/news", ["ned""uk","topic""n","output""atom"], me, #showNetData)
               
                --   URL -  the url of a server side script, xml file, html file, etc.
                --   DataList -   a property list of data you want to send to the server side script. *** NOTE  The properties names should be Strings do to case sensitivity on the server side.
                --   CallingOb -  an object to send returned data to. 
                --   CallBackHandler - a Symbol  Handler in CallingOb.
               
                -- store info for network operations and callbacks.
                pNetOpData = [#id0, #URL"", #DataList[], CallbackOb0, CallBackHandler0]
                pNetOpData.URL = URL
                pNetOpData.DataList = DataList
                pNetOpData.CallBackOb = CallingOb
                pNetOpData.CallBackHandler = CallbackHandler
               
                -- set default time delay between server calls. Use setUpdateInterval() method to change this value.
                pUpdateInterval = 5 * 60 * 1000  -- five minutes
               
                me.resetProps()  -- make sure all properties have valid values.
                return me
              end new


              -- begins the process of calling a server and retrieving the RSS feed data.
              on start me
                me.getFeedData()
                pUpdateTimeOb = timeout().new("RSS_Update_"&me, pUpdateInterval, #getFeedData  , me) 
              end start


              -- ends the process of calling a server and retrieving the RSS feed data.
              on stop me
                if pUpdateTimeOb.objectP then
                  pUpdateTimeOb.forget()
                  pUpdateTimeOb = void
                end if
              end stop


              -- sets the delay between server calls.
              on setUpdateInterval me, Minutes  -- integer
                pUpdateInterval = Minutes * 60 * 1000
                if pUpdateTimeOb.objectP then pUpdateTimeOb.period = pUpdateInterval
              end setUpdateInterval


              -- returns a list of the data for all nodes with the name "NodeName"
              on getNodes me, NodeName  -- String
                if NodeName.StringP = false then return []  -- require a string to be passed in.
               
                Nodes = []  -- storage for any nodes we may find.
               
                -- go through each list in this object and find those nodes named "NodeName".
                -- Note "ancestor" contains the complete xml data sent from the server, if any exists.
                repeat with Index = 1 to ancestor.count
                  if ancestor.getPropAt(Index) = NodeName then
                    me.addNodeData(ancestor[Index], Nodes)  -- found a valid node. Add its data to Nodes.
                  else
                    me.searchNode(ancestor[Index], Nodes, NodeName) -- search this node for a node named "NodeName"
                  end if
                end repeat
               
                return Nodes
              end getNode


              ------------------------------------------------------------------------------------------ --------
              -- PRIVATE METHODS
              ------------------------------------------------------------------------------------------ --------

              -- initializes object properties
              on resetProps me
                ancestor = []
                source = ""
                channel = []
                feed = []
                items = []
                entries = []
              end resetProps


              -- makes call to the server and sets up a timeout object to monitor the network status.
              on getFeedData me
                -- store net id
                pNetOpData.id = _movie.getNetText(pNetOpData.URL , pNetOpData.DataList)
                timeout().new("NetMonitor_"&me, 300, #monitorNetOps  , me) 
              end getFeedData

               

              -- Polls the current network operation to see if it is done or errored out.
              -- Parses any data returned from the server.
              -- Makes callback to inform the registered object that new data is ready.
              on monitorNetOps me, TimeOb
                -- check if net operation is done
                if  netDone(pNetOpData.id) then
                  TimeOb.forget()  -- stop checking network status
                 
                  -- check for network error
                  if netError(pNetOpData.id) <> "OK" then  -- there was a network error
                    ErrorMessage = me.getErrorMessage(netError(pNetOpData.id))
                    call(pNetOpData.CallBackHandler, pNetOpData.CallBackOb, 1, ErrorMessage, me) -- handler,object,error, errorMsg, This object
                    exit 
                  else  -- no error.
                    me.resetProps()  -- clear out old data.
                    source = netTextResult(pNetOpData.id)  -- store data sent back.
                  end if
                else  -- network operation is not complete. Continue to wait.
                  exit
                end if
               
                --** We have data to work with. Parse it. **
               
                -- delete any header info preceding xml structure at the top of the returned text.
                SourceCpy = source  -- make copy of the source text so that we don't strip any information from it.
                repeat while SourceCpy.char[1] <> "<"      --char[1..5] <> "<?xml"  --**** This line may need modification do to inconsitent formatting of feed data.
                  delete SourceCpy.line[1]
                end repeat
               
                if SourceCpy.line.count = 0 then  -- no xml to work with. We are done.
                  ErrorMessage = "Not an XML document. Could not parse."
                  call(pNetOpData.CallBackHandler, pNetOpData.CallBackOb, 1, ErrorMessage, me) -- handler,object,error, errorMsg, This object
                  exit
                end if
               
                -- convert returned text to xml
                objXml = new xtra("xmlparser")
                Error = objXml.parseString(SourceCpy)
                if Error then
                  ErrorMessage = "XML parsing error."
                  call(pNetOpData.CallBackHandler, pNetOpData.CallBackOb, 1, ErrorMessage, me) -- handler,object,error, errorMsg, This object
                  exit
                end if
               
                -- convert xml to a property list and make it part of this object
                ancestor = objXml.makeList()
               
                -- assign data to public properties. This provides easier access to commonly desired data.
                TmpChannel = me.getNodes("channel")
                if TmpChannel.count = 1 then
                  channel = TmpChannel[1]
                else
                  channel = TmpChannel
                end if
               
                Tmpfeed= me.getNodes("feed")
                if Tmpfeed.count = 1 then
                  feed = Tmpfeed[1]
                else
                  feed = Tmpfeed
                end if
               
                items = me.getNodes("item")
                entries = me.getNodes("entry")
               
                -- let the registered object know that the feed data has been updated and all is cool.
                call(pNetOpData.CallBackHandler, pNetOpData.CallBackOb, 0, "", me) -- handler,object,error, errorMsg, This object
              end monitorNetOps


              -- recursive method that looks for nodes named "NodeName" and then calls itself if there is more data to check.
              on searchNode me, CurNode, Nodes, NodeName
                if ilk(CurNode) <> #PropList then return  -- if down to raw data and not a list, then exit out of here.
               
                repeat with Index = 1 to CurNode.count
                  if CurNode.getPropAt(Index) = NodeName then
                    me.addNodeData(CurNode[Index], Nodes)  -- found a node named "NodeName". Add its data to Nodes.
                  else
                    me.searchNode(CurNode[Index], Nodes, NodeName)  -- search this node for a node named "NodeName"
                  end if
                end repeat
              end searchNode


              -- adds all data in "CurNode" to the "Nodes" list
              on addNodeData me, CurNode, Nodes
                NodeData = []
                repeat with Index = 2 to CurNode.count
                  PropName = CurNode.getPropAt(Index)
                  if PropName = "!CHARDATA" then  -- node contains a single piece of data
                    NodeData = CurNode[Index]
                    exit repeat
                  else  -- node contains multiple pieces of data
                    if CurNode[Index].count >= 2 then
                      NodeData[Symbol(PropName)] = CurNode[Index][2]
                    else
                      NodeData[Symbol(PropName)] = ""
                    end if
                  end if
                end repeat
               
                Nodes.add(NodeData)
              end addNodeData

               

              -- Returns error message
              on getErrorMessage me, ErrorNum
                case ErrorNum of
                  0 return("Everything is okay.")
                  4 return("Bad MOA class. The required network or nonnetwork Xtra extensions are improperly installed or not installed at all.")
                  5 return("Bad MOA Interface. See 4.") 
                  6 return("Bad URL or Bad MOA class. The required network or nonnetwork Xtra extensions are improperly installed or not installed at all.")
                  20 return("Internal error. Returned by netError() in the Netscape browser if the browser detected a network or internal error.")
                  4146 return("Connection could not be established with the remote host.")
                  4149 return("Data supplied by the server was in an unexpected format.")
                  4150 return("Unexpected early closing of connection.")
                  4154 return("Operation could not be completed due to timeout.")
                  4155 return("Not enough memory available to complete the transaction.") 
                  4156 return("Protocol reply to request indicates an error in the reply.")
                  4157 return("Transaction failed to be authenticated.")
                  4159 return("Invalid URL.")
                  4164 return("Could not create a socket.")
                  4165 return("Requested object could not be found (URL may be incorrect).")
                  4166 return("Generic proxy failure.")
                  4167 return("Transfer was intentionally interrupted by client.")
                  4242 return("Download stopped by netAbort(url).")
                  4836 return("Download stopped for an unknown reason, possibly a network error, or the download was abandoned.")
                  otherwise return("Unknown network error.")
                end case
              end getErrorMessage

              • 4. Re: RSS on Director?
                ginod Level 1

                 

                 

                do you have some sampler to see it running?

                • 5. Re: RSS on Director?
                  Production Monkey Level 3

                  The old post explains how to use the code including four sample feeds.

                  1 person found this helpful