- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables
Class ::xowiki::RSS-client
::xowiki::RSS-client create ... \
[ -url url ]
Class Relations
::xotcl::Class create ::xowiki::RSS-client \ -superclass ::xotcl::ObjectMethods (to be applied on the object)
getRSSVersion (scripted)
set root [$doc documentElement] switch [$root nodeName] { rss { if {[$root hasAttribute version]} { return [$root getAttribute version] } # Best guess as most stuff is optional... return 0.92 } rdf:RDF { return 1.0 } default { return 0 } }node_text (scripted)
set n [$node selectNode $xpath] if {$n ne ""} { return [$n nodeValue] } else { return "" }node_uri (scripted)
set n [$node selectNode $xpath] if {$n ne ""} { # Only if there is a lonely &, quote it back to an entity. return [string map { & %26 } [$n nodeValue]] } else { return "" }Methods (to be applied on instances)
channel (scripted)
return [self]::channelinit (scripted)
set XML [:load] if {$XML ne ""} { :parse $XML }items (scripted)
return ${:items}load (scripted)
set request [util::http::get -url [:url]] set status [dict get $request status] set data [expr {[dict exists $request page] ? [dict get $request page] : ""}] #:msg "statuscode = [$r set status_code], content_type=[$r set content_type]" #set f [open [ad_tmpdir]/feed w]; fconfigure $f -translation binary; puts $f [$r set data]; close $f # if {[$r exists status] && [$r set status] eq "canceled"} { # set :errorMessage [$r set cancel_message] # } if {$status != 200} { set :errorMessage "$status - $data" } return $data # the following does not appear to be necessary due to changes in http-client-procs. #set charset utf-8 #regexp {^<\?xml\s+version\s*=\s*\S+\s+encoding\s*=\s*[\"'](\S+)[\"']} $xml _ charset #ns_log notice "charse=$charset,xml=$xml" #return [encoding convertfrom [string tolower $charset] $xml]parse (scripted)
set doc [ dom parse -- $data ] set root [ $doc documentElement ] switch [RSS-client getRSSVersion $doc] { 0.91 - 0.92 - 0.93 - 2.0 { array set :xpath { title {/rss/channel/title/text()} link {/rss/channel/link/text()} imgNode {/rss/channel/image/title} imgTitle {/rss/channel/image/title/text()} imgLink {/rss/channel/image/url/text()} imgWidth {/rss/channel/image/width/text()} imgHeight {/rss/channel/image/height/text()} stories {/rss/channel/item} itemTitle {title/text()} itemLink {link/text()} itemPubDate {pubDate/text()} itemDesc {description/text()} } } 1.0 { array set :xpath { title {/rdf:RDF/*[local-name()='channel']/*[local-name()='title']/text()} link {/rdf:RDF/*[local-name()='channel']/*[local-name()='link']/text()} imgNode {/rdf:RDF/*[local-name()='image']} imgTitle {/rdf:RDF/*[local-name()='image']/*[local-name()='title']/text()} imgLink {/rdf:RDF/*[local-name()='image']/*[local-name()='url']/text()} imgWidth {/rdf:RDF/*[local-name()='image']/*[local-name()='width']/text()} imgHeight {/rdf:RDF/*[local-name()='image']/*[local-name()='height']/text()} stories {/rdf:RDF/*[local-name()='item']} itemTitle {*[local-name()='title']/text()} itemLink {*[local-name()='link']/text()} itemPubDate {*[local-name()='pubDate']/text()} itemDesc {*[local-name()='description']/text()} } } default { set :errorMessage "Unsupported RSS schema [RSS-client getRSSVersion $doc]" return #error "Unsupported schema [RSS-client getRSSVersion $doc]" } } # Channel set cN [ $root child 1 channel ] set channel [::xowiki::RSS-client::channel create [self]::channel -root $cN] # Items set :items {} set stories [$root selectNodes [set :xpath(stories)] ] foreach iN $stories { lappend :items [::xowiki::RSS-client::item new -childof [self] -node $iN ] }url (setter)
xpath (scripted)
return [set :xpath($key)]
- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables