2009-11-23 12:46:12 +00:00
|
|
|
package feeder
|
|
|
|
|
|
|
|
import "os"
|
|
|
|
import "xmlx"
|
|
|
|
|
|
|
|
func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
|
2010-05-23 14:21:30 +00:00
|
|
|
ns := "http://www.w3.org/2005/Atom"
|
|
|
|
channels := doc.SelectNodes(ns, "feed")
|
2009-11-23 12:46:12 +00:00
|
|
|
for _, node := range channels {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch := Channel{}
|
|
|
|
ch.Title = node.GetValue(ns, "title")
|
|
|
|
ch.LastBuildDate = node.GetValue(ns, "updated")
|
|
|
|
ch.Id = node.GetValue(ns, "id")
|
|
|
|
ch.Rights = node.GetValue(ns, "rights")
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list := node.SelectNodes(ns, "link")
|
|
|
|
ch.Links = make([]Link, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for i, v := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Links[i].Href = v.GetAttr("", "href")
|
|
|
|
ch.Links[i].Rel = v.GetAttr("", "rel")
|
|
|
|
ch.Links[i].Type = v.GetAttr("", "type")
|
|
|
|
ch.Links[i].HrefLang = v.GetAttr("", "hreflang")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
tn := node.SelectNode(ns, "subtitle")
|
2009-11-23 12:46:12 +00:00
|
|
|
if tn != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.SubTitle = SubTitle{}
|
|
|
|
ch.SubTitle.Type = tn.GetAttr("", "type")
|
|
|
|
ch.SubTitle.Text = tn.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if tn = node.SelectNode(ns, "generator"); tn != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Generator = Generator{}
|
|
|
|
ch.Generator.Uri = tn.GetAttr("", "uri")
|
|
|
|
ch.Generator.Version = tn.GetAttr("", "version")
|
|
|
|
ch.Generator.Text = tn.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if tn = node.SelectNode(ns, "author"); tn != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
ch.Author = Author{}
|
|
|
|
ch.Author.Name = tn.GetValue("", "name")
|
|
|
|
ch.Author.Uri = tn.GetValue("", "uri")
|
|
|
|
ch.Author.Email = tn.GetValue("", "email")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = node.SelectNodes(ns, "entry")
|
|
|
|
ch.Items = make([]Item, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for _, v := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
item := Item{}
|
|
|
|
item.Title = v.GetValue(ns, "title")
|
|
|
|
item.Id = v.GetValue(ns, "id")
|
|
|
|
item.PubDate = v.GetValue(ns, "updated")
|
|
|
|
item.Description = v.GetValue(ns, "summary")
|
2009-11-23 12:46:12 +00:00
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = v.SelectNodes(ns, "link")
|
|
|
|
item.Links = make([]Link, 0)
|
2009-11-23 12:46:12 +00:00
|
|
|
for _, lv := range list {
|
|
|
|
if tn.GetAttr(ns, "rel") == "enclosure" {
|
2010-05-23 14:21:30 +00:00
|
|
|
enc := Enclosure{}
|
|
|
|
enc.Url = lv.GetAttr("", "href")
|
|
|
|
enc.Type = lv.GetAttr("", "type")
|
2010-12-17 20:57:48 +00:00
|
|
|
item.Enclosures = append(item.Enclosures, enc)
|
2009-11-23 12:46:12 +00:00
|
|
|
} else {
|
2010-05-23 14:21:30 +00:00
|
|
|
lnk := Link{}
|
|
|
|
lnk.Href = lv.GetAttr("", "href")
|
|
|
|
lnk.Rel = lv.GetAttr("", "rel")
|
|
|
|
lnk.Type = lv.GetAttr("", "type")
|
|
|
|
lnk.HrefLang = lv.GetAttr("", "hreflang")
|
2010-12-17 20:57:48 +00:00
|
|
|
item.Links = append(item.Links, lnk)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-23 14:21:30 +00:00
|
|
|
list = v.SelectNodes(ns, "contributor")
|
|
|
|
item.Contributors = make([]string, len(list))
|
2009-11-23 12:46:12 +00:00
|
|
|
for ci, cv := range list {
|
2010-05-23 14:21:30 +00:00
|
|
|
item.Contributors[ci] = cv.GetValue("", "name")
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
if tn = v.SelectNode(ns, "content"); tn != nil {
|
2010-05-23 14:21:30 +00:00
|
|
|
item.Content = Content{}
|
|
|
|
item.Content.Type = tn.GetAttr("", "type")
|
|
|
|
item.Content.Lang = tn.GetValue("xml", "lang")
|
|
|
|
item.Content.Base = tn.GetValue("xml", "base")
|
|
|
|
item.Content.Text = tn.Value
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
2010-12-17 20:57:48 +00:00
|
|
|
ch.Items = append(ch.Items, item)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
|
2010-12-17 20:57:48 +00:00
|
|
|
this.Channels = append(this.Channels, ch)
|
2009-11-23 12:46:12 +00:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|