Example #1
0
// Returns the type of the feed, ie. "atom" or "rss", and the version number as an array.
// The first item in the array is the major and the second the minor version number.
func (this *Feed) GetVersionInfo(doc *xmlx.Document) (ftype string, fversion [2]int) {
	var node *xmlx.Node

	if this.isAtom(doc) {
		ftype = "atom"
		fversion = [2]int{1, 0}
		return
	}

	if this.isRss(doc) {
		ftype = "rss"
		major := 0
		minor := 0
		version := node.As("", "version")
		p := strings.Index(version, ".")
		if p != -1 {
			major, _ = strconv.Atoi(version[0:p])
			minor, _ = strconv.Atoi(version[p+1 : len(version)])
		}
		fversion = [2]int{major, minor}
		return
	}

	// issue#5: Some documents have an RDF root node instead of rss.
	if node = doc.SelectNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "RDF"); node != nil {
		ftype = "rss"
		fversion = [2]int{1, 1}
		return
	}

	ftype = "unknown"
	fversion = [2]int{0, 0}
	return
}
Example #2
0
func addChild(node *xmlx.Node, name string, attribs Attribs, contents string) *xmlx.Node {
	child := xmlx.NewNode(xmlx.NT_ELEMENT)
	child.Name.Local = name
	child.Value = contents

	for key, val := range attribs {
		child.SetAttr(key, fmt.Sprintf("%v", val))
	}

	node.AddChild(child)

	return child
}
Example #3
0
func getExtension(node *xmlx.Node) (Extension, bool) {
	var extension Extension
	if node.Name.Space != "" {
		extension = Extension{Name: node.Name.Local, Value: node.GetValue()}
		extension.Attrs = make(map[string]string)
		extension.Childrens = make(map[string][]Extension, 0)
		for _, x := range node.Attributes {
			extension.Attrs[x.Name.Local] = x.Value
		}
		for _, y := range node.Children {
			children, ok := getExtension(y)
			if ok {
				extension.Childrens[y.Name.Local] = append(extension.Childrens[y.Name.Local], children)
			}
		}
		return extension, true
	} else {
		return extension, false
	}
}
Example #4
0
File: rss.go Project: hawx/riviera
func getExtension(node *xmlx.Node) (extension Extension, ok bool) {
	if node.Name.Space == "" {
		return extension, false
	}

	extension = Extension{
		Name:      node.Name.Local,
		Value:     node.GetValue(),
		Attrs:     make(map[string]string),
		Childrens: make(map[string][]Extension, 0),
	}

	for _, attr := range node.Attributes {
		extension.Attrs[attr.Name.Local] = attr.Value
	}

	for _, child := range node.Children {
		if ext, ok := getExtension(child); ok {
			extension.Childrens[child.Name.Local] = append(extension.Childrens[child.Name.Local], ext)
		}
	}

	return extension, true
}
Example #5
0
func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
	var foundChannels []*Channel
	var ch *Channel
	var i *Item
	var n *xmlx.Node
	var list, tl []*xmlx.Node
	const ns = "*"

	root := doc.SelectNode(ns, "rss")
	if root == nil {
		root = doc.SelectNode(ns, "RDF")
	}

	if root == nil {
		return errors.New("Failed to find rss/rdf node in XML.")
	}

	channels := root.SelectNodes(ns, "channel")
	for _, node := range channels {
		ch = new(Channel)
		foundChannels = append(foundChannels, ch)

		ch.Title = node.S(ns, "title")
		list = node.SelectNodes(ns, "link")
		ch.Links = make([]Link, len(list))

		for i, v := range list {
			if v.Name.Space == "http://www.w3.org/2005/Atom" && v.Name.Local == "link" {
				ch.Links[i].Href = v.As("", "href")
				ch.Links[i].Rel = v.As("", "rel")
				ch.Links[i].Type = v.As("", "type")
				ch.Links[i].HrefLang = v.As("", "hreflang")
			} else {
				ch.Links[i].Href = v.GetValue()
			}
		}

		ch.Description = node.S(ns, "description")
		ch.Language = node.S(ns, "language")
		ch.Copyright = node.S(ns, "copyright")
		ch.ManagingEditor = node.S(ns, "managingEditor")
		ch.WebMaster = node.S(ns, "webMaster")
		ch.PubDate = node.S(ns, "pubDate")
		ch.LastBuildDate = node.S(ns, "lastBuildDate")
		ch.Docs = node.S(ns, "docs")

		list = node.SelectNodes(ns, "category")
		ch.Categories = make([]*Category, len(list))
		for i, v := range list {
			ch.Categories[i] = new(Category)
			ch.Categories[i].Domain = v.As(ns, "domain")
			ch.Categories[i].Text = v.GetValue()
		}

		if n = node.SelectNode(ns, "generator"); n != nil {
			ch.Generator = Generator{}
			ch.Generator.Text = n.GetValue()
		}

		ch.TTL = node.I(ns, "ttl")
		ch.Rating = node.S(ns, "rating")

		list = node.SelectNodes(ns, "hour")
		ch.SkipHours = make([]int, len(list))
		for i, v := range list {
			ch.SkipHours[i] = v.I(ns, "hour")
		}

		list = node.SelectNodes(ns, "days")
		ch.SkipDays = make([]int, len(list))
		for i, v := range list {
			ch.SkipDays[i] = days[v.GetValue()]
		}

		if n = node.SelectNode(ns, "image"); n != nil {
			ch.Image.Title = n.S(ns, "title")
			ch.Image.Url = n.S(ns, "url")
			ch.Image.Link = n.S(ns, "link")
			ch.Image.Width = n.I(ns, "width")
			ch.Image.Height = n.I(ns, "height")
			ch.Image.Description = n.S(ns, "description")
		}

		if n = node.SelectNode(ns, "cloud"); n != nil {
			ch.Cloud = Cloud{}
			ch.Cloud.Domain = n.As(ns, "domain")
			ch.Cloud.Port = n.Ai(ns, "port")
			ch.Cloud.Path = n.As(ns, "path")
			ch.Cloud.RegisterProcedure = n.As(ns, "registerProcedure")
			ch.Cloud.Protocol = n.As(ns, "protocol")
		}

		if n = node.SelectNode(ns, "textInput"); n != nil {
			ch.TextInput = Input{}
			ch.TextInput.Title = n.S(ns, "title")
			ch.TextInput.Description = n.S(ns, "description")
			ch.TextInput.Name = n.S(ns, "name")
			ch.TextInput.Link = n.S(ns, "link")
		}

		list = node.SelectNodes(ns, "item")
		if len(list) == 0 {
			list = doc.SelectNodes(ns, "item")
		}

		for _, item := range list {
			i = new(Item)
			i.Title = item.S(ns, "title")
			i.Description = item.S(ns, "description")
			i.Latitude = item.S(ns, "lat")
			i.Longitude = item.S(ns, "long")

			tl = item.SelectNodes(ns, "link")
			for _, v := range tl {
				lnk := new(Link)
				if v.Name.Space == "http://www.w3.org/2005/Atom" && v.Name.Local == "link" {
					lnk.Href = v.As("", "href")
					lnk.Rel = v.As("", "rel")
					lnk.Type = v.As("", "type")
					lnk.HrefLang = v.As("", "hreflang")
				} else {
					lnk.Href = v.GetValue()
				}

				i.Links = append(i.Links, lnk)
			}

			if n = item.SelectNode(ns, "author"); n != nil {
				i.Author.Name = n.GetValue()

			} else if n = item.SelectNode(ns, "creator"); n != nil {
				i.Author.Name = n.GetValue()
			}

			i.Comments = item.S(ns, "comments")

			guid := item.S(ns, "guid")
			if len(guid) > 0 {
				i.Guid = &guid
			}

			i.PubDate = item.S(ns, "pubDate")

			tl = item.SelectNodes(ns, "category")
			for _, lv := range tl {
				cat := new(Category)
				cat.Domain = lv.As(ns, "domain")
				cat.Text = lv.GetValue()
				i.Categories = append(i.Categories, cat)
			}

			tl = item.SelectNodes(ns, "enclosure")
			for _, lv := range tl {
				enc := new(Enclosure)
				enc.Url = lv.As(ns, "url")
				enc.Length = lv.Ai64(ns, "length")
				enc.Type = lv.As(ns, "type")
				i.Enclosures = append(i.Enclosures, enc)
			}

			if src := item.SelectNode(ns, "source"); src != nil {
				i.Source = new(Source)
				i.Source.Url = src.As(ns, "url")
				i.Source.Text = src.GetValue()
			}

			tl = item.SelectNodes("http://purl.org/rss/1.0/modules/content/", "*")
			for _, lv := range tl {
				if lv.Name.Local == "encoded" {
					i.Content = new(Content)
					i.Content.Text = lv.String()
					break
				}
			}

			tl = item.SelectNodes(ns, ns)
			i.Extensions = make(map[string]map[string][]Extension)
			for _, lv := range tl {
				getExtensions(&i.Extensions, lv)
			}

			ch.Items = append(ch.Items, i)
		}

		x := node.SelectNodes(ns, ns)
		ch.Extensions = make(map[string]map[string][]Extension)
		for _, v := range x {
			if v.Name.Space != "" {
				getExtensions(&ch.Extensions, v)
			}
		}

	}
	this.Channels = foundChannels
	return
}
Example #6
0
func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
	ns := "http://www.w3.org/2005/Atom"
	channels := doc.SelectNodes(ns, "feed")

	var foundChannels []*Channel
	var ch *Channel
	var i *Item
	var tn *xmlx.Node
	var list []*xmlx.Node

	for _, node := range channels {
		ch = new(Channel)
		foundChannels = append(foundChannels, ch)

		ch.Title = node.S(ns, "title")
		ch.LastBuildDate = node.S(ns, "updated")
		ch.Id = node.S(ns, "id")
		ch.Rights = node.S(ns, "rights")

		list = node.SelectNodes(ns, "link")
		ch.Links = make([]Link, len(list))
		for i, v := range list {
			ch.Links[i].Href = v.As("", "href")
			ch.Links[i].Rel = v.As("", "rel")
			ch.Links[i].Type = v.As("", "type")
			ch.Links[i].HrefLang = v.As("", "hreflang")
		}

		if tn = node.SelectNode(ns, "subtitle"); tn != nil {
			ch.SubTitle = SubTitle{}
			ch.SubTitle.Type = tn.As("", "type")
			ch.SubTitle.Text = tn.GetValue()
		}

		if tn = node.SelectNode(ns, "generator"); tn != nil {
			ch.Generator = Generator{}
			ch.Generator.Uri = tn.As("", "uri")
			ch.Generator.Version = tn.As("", "version")
			ch.Generator.Text = tn.GetValue()
		}

		if tn = node.SelectNode(ns, "author"); tn != nil {
			ch.Author = Author{}
			ch.Author.Name = tn.S("", "name")
			ch.Author.Uri = tn.S("", "uri")
			ch.Author.Email = tn.S("", "email")
		}

		list = node.SelectNodes(ns, "entry")

		for _, item := range list {
			i = new(Item)
			i.Title = item.S(ns, "title")
			i.Id = item.S(ns, "id")
			i.PubDate = item.S(ns, "updated")
			i.Description = item.S(ns, "summary")

			links := item.SelectNodes(ns, "link")
			for _, lv := range links {
				if lv.As(ns, "rel") == "enclosure" {
					enc := new(Enclosure)
					enc.Url = lv.As("", "href")
					enc.Type = lv.As("", "type")
					i.Enclosures = append(i.Enclosures, enc)
				} else {
					lnk := new(Link)
					lnk.Href = lv.As("", "href")
					lnk.Rel = lv.As("", "rel")
					lnk.Type = lv.As("", "type")
					lnk.HrefLang = lv.As("", "hreflang")
					i.Links = append(i.Links, lnk)
				}
			}

			list = item.SelectNodes(ns, "contributor")
			for _, cv := range list {
				i.Contributors = append(i.Contributors, cv.S("", "name"))
			}

			list = item.SelectNodes(ns, "category")
			for _, cv := range list {
				cat := new(Category)
				cat.Domain = ""
				cat.Text = cv.As("", "term")
				i.Categories = append(i.Categories, cat)
			}

			if tn = item.SelectNode(ns, "content"); tn != nil {
				i.Content = new(Content)
				i.Content.Type = tn.As("", "type")
				i.Content.Lang = tn.S("xml", "lang")
				i.Content.Base = tn.S("xml", "base")
				i.Content.Text = tn.GetValue()
			}

			if tn = item.SelectNode(ns, "author"); tn != nil {
				i.Author = Author{}
				i.Author.Name = tn.S(ns, "name")
				i.Author.Uri = tn.S(ns, "uri")
				i.Author.Email = tn.S(ns, "email")
			}

			ch.Items = append(ch.Items, i)
		}
	}
	this.Channels = foundChannels
	return
}
Example #7
0
func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
	ns := "http://www.w3.org/2005/Atom"
	channels := doc.SelectNodes(ns, "feed")

	getChan := func(id, title string) *Channel {
		for _, c := range this.Channels {
			switch {
			case len(id) > 0:
				if c.Id == id {
					return c
				}
			case len(title) > 0:
				if c.Title == title {
					return c
				}
			}
		}
		return nil
	}

	haveItem := func(ch *Channel, id, title, desc string) bool {
		for _, item := range ch.Items {
			switch {
			case len(id) > 0:
				if item.Id == id {
					return true
				}
			case len(title) > 0:
				if item.Title == title {
					return true
				}
			case len(desc) > 0:
				if item.Description == desc {
					return true
				}
			}
		}
		return false
	}

	var ch *Channel
	var i *Item
	var tn *xmlx.Node
	var list []*xmlx.Node

	for _, node := range channels {
		if ch = getChan(node.S(ns, "id"), node.S(ns, "title")); ch == nil {
			ch = new(Channel)
			this.Channels = append(this.Channels, ch)
		}

		ch.Title = node.S(ns, "title")
		ch.LastBuildDate = node.S(ns, "updated")
		ch.Id = node.S(ns, "id")
		ch.Rights = node.S(ns, "rights")

		list = node.SelectNodes(ns, "link")
		ch.Links = make([]Link, len(list))
		for i, v := range list {
			ch.Links[i].Href = v.As("", "href")
			ch.Links[i].Rel = v.As("", "rel")
			ch.Links[i].Type = v.As("", "type")
			ch.Links[i].HrefLang = v.As("", "hreflang")
		}

		if tn = node.SelectNode(ns, "subtitle"); tn != nil {
			ch.SubTitle = SubTitle{}
			ch.SubTitle.Type = tn.As("", "type")
			ch.SubTitle.Text = tn.Value
		}

		if tn = node.SelectNode(ns, "generator"); tn != nil {
			ch.Generator = Generator{}
			ch.Generator.Uri = tn.As("", "uri")
			ch.Generator.Version = tn.As("", "version")
			ch.Generator.Text = tn.Value
		}

		if tn = node.SelectNode(ns, "author"); tn != nil {
			ch.Author = Author{}
			ch.Author.Name = tn.S("", "name")
			ch.Author.Uri = tn.S("", "uri")
			ch.Author.Email = tn.S("", "email")
		}

		itemcount := len(ch.Items)
		list = node.SelectNodes(ns, "entry")

		for _, item := range list {
			if haveItem(ch, item.S(ns, "id"), item.S(ns, "title"), item.S(ns, "summary")) {
				continue
			}

			i = new(Item)
			i.Title = item.S(ns, "title")
			i.Id = item.S(ns, "id")
			i.PubDate = item.S(ns, "updated")
			i.Description = item.S(ns, "summary")

			links := item.SelectNodes(ns, "link")
			for _, lv := range links {
				if lv.As(ns, "rel") == "enclosure" {
					enc := new(Enclosure)
					enc.Url = lv.As("", "href")
					enc.Type = lv.As("", "type")
					i.Enclosures = append(i.Enclosures, enc)
				} else {
					lnk := new(Link)
					lnk.Href = lv.As("", "href")
					lnk.Rel = lv.As("", "rel")
					lnk.Type = lv.As("", "type")
					lnk.HrefLang = lv.As("", "hreflang")
					i.Links = append(i.Links, lnk)
				}
			}

			list = item.SelectNodes(ns, "contributor")
			for _, cv := range list {
				i.Contributors = append(i.Contributors, cv.S("", "name"))
			}

			if tn = item.SelectNode(ns, "content"); tn != nil {
				i.Content = new(Content)
				i.Content.Type = tn.As("", "type")
				i.Content.Lang = tn.S("xml", "lang")
				i.Content.Base = tn.S("xml", "base")
				i.Content.Text = tn.Value
			}

			if tn = item.SelectNode(ns, "author"); tn != nil {
				i.Author = Author{}
				i.Author.Name = tn.S(ns, "name")
				i.Author.Uri = tn.S(ns, "uri")
				i.Author.Email = tn.S(ns, "email")
			}

			ch.Items = append(ch.Items, i)
		}

		if itemcount != len(ch.Items) && this.itemhandler != nil {
			this.itemhandler(this, ch, ch.Items[itemcount:])
		}
	}
	return
}
Example #8
0
func (this *Feed) readRss2(doc *xmlx.Document) (err error) {
	days := make(map[string]int)
	days["Monday"] = 1
	days["Tuesday"] = 2
	days["Wednesday"] = 3
	days["Thursday"] = 4
	days["Friday"] = 5
	days["Saturday"] = 6
	days["Sunday"] = 7

	getChan := func(pubdate, title string) *Channel {
		for _, c := range this.Channels {
			switch {
			case len(pubdate) > 0:
				if c.PubDate == pubdate {
					return c
				}
			case len(title) > 0:
				if c.Title == title {
					return c
				}
			}
		}
		return nil
	}

	var ch *Channel
	var i *Item
	var n *xmlx.Node
	var list, tl []*xmlx.Node
	const ns = "*"

	root := doc.SelectNode(ns, "rss")
	if root == nil {
		root = doc.SelectNode(ns, "RDF")
	}

	if root == nil {
		return errors.New("Failed to find rss/rdf node in XML.")
	}

	channels := root.SelectNodes(ns, "channel")
	for _, node := range channels {
		if ch = getChan(node.S(ns, "pubDate"), node.S(ns, "title")); ch == nil {
			ch = new(Channel)
			this.Channels = append(this.Channels, ch)
		}

		ch.Title = node.S(ns, "title")
		list = node.SelectNodes(ns, "link")
		ch.Links = make([]Link, len(list))

		for i, v := range list {
			ch.Links[i].Href = v.GetValue()
		}

		ch.Description = node.S(ns, "description")
		ch.Language = node.S(ns, "language")
		ch.Copyright = node.S(ns, "copyright")
		ch.ManagingEditor = node.S(ns, "managingEditor")
		ch.WebMaster = node.S(ns, "webMaster")
		ch.PubDate = node.S(ns, "pubDate")
		ch.LastBuildDate = node.S(ns, "lastBuildDate")
		ch.Docs = node.S(ns, "docs")

		list = node.SelectNodes(ns, "category")
		ch.Categories = make([]*Category, len(list))
		for i, v := range list {
			ch.Categories[i] = new(Category)
			ch.Categories[i].Domain = v.As(ns, "domain")
			ch.Categories[i].Text = v.GetValue()
		}

		if n = node.SelectNode(ns, "generator"); n != nil {
			ch.Generator = Generator{}
			ch.Generator.Text = n.GetValue()
		}

		ch.TTL = node.I(ns, "ttl")
		ch.Rating = node.S(ns, "rating")

		list = node.SelectNodes(ns, "hour")
		ch.SkipHours = make([]int, len(list))
		for i, v := range list {
			ch.SkipHours[i] = v.I(ns, "hour")
		}

		list = node.SelectNodes(ns, "days")
		ch.SkipDays = make([]int, len(list))
		for i, v := range list {
			ch.SkipDays[i] = days[v.GetValue()]
		}

		if n = node.SelectNode(ns, "image"); n != nil {
			ch.Image.Title = n.S(ns, "title")
			ch.Image.Url = n.S(ns, "url")
			ch.Image.Link = n.S(ns, "link")
			ch.Image.Width = n.I(ns, "width")
			ch.Image.Height = n.I(ns, "height")
			ch.Image.Description = n.S(ns, "description")
		}

		if n = node.SelectNode(ns, "cloud"); n != nil {
			ch.Cloud = Cloud{}
			ch.Cloud.Domain = n.As(ns, "domain")
			ch.Cloud.Port = n.Ai(ns, "port")
			ch.Cloud.Path = n.As(ns, "path")
			ch.Cloud.RegisterProcedure = n.As(ns, "registerProcedure")
			ch.Cloud.Protocol = n.As(ns, "protocol")
		}

		if n = node.SelectNode(ns, "textInput"); n != nil {
			ch.TextInput = Input{}
			ch.TextInput.Title = n.S(ns, "title")
			ch.TextInput.Description = n.S(ns, "description")
			ch.TextInput.Name = n.S(ns, "name")
			ch.TextInput.Link = n.S(ns, "link")
		}

		itemcount := len(ch.Items)
		list = node.SelectNodes(ns, "item")
		if len(list) == 0 {
			list = doc.SelectNodes(ns, "item")
		}

		for _, item := range list {
			i = new(Item)
			i.Title = item.S(ns, "title")
			i.Description = item.S(ns, "description")

			tl = item.SelectNodes(ns, "link")
			for _, v := range tl {
				lnk := new(Link)
				lnk.Href = v.GetValue()
				i.Links = append(i.Links, lnk)
			}

			if n = item.SelectNode(ns, "author"); n != nil {
				i.Author = Author{}
				i.Author.Name = n.GetValue()
			}
			if n = item.SelectNode(ns, "creator"); n != nil {
				i.Author = Author{Name: n.GetValue()}
			}

			i.Comments = item.S(ns, "comments")
			i.Guid = item.S(ns, "guid")
			i.PubDate = item.S(ns, "pubDate")

			tl = item.SelectNodes(ns, "category")
			for _, lv := range tl {
				cat := new(Category)
				cat.Domain = lv.As(ns, "domain")
				cat.Text = lv.GetValue()
				i.Categories = append(i.Categories, cat)
			}

			tl = item.SelectNodes(ns, "enclosure")
			for _, lv := range tl {
				enc := new(Enclosure)
				enc.Url = lv.As(ns, "url")
				enc.Length = lv.Ai64(ns, "length")
				enc.Type = lv.As(ns, "type")
				i.Enclosures = append(i.Enclosures, enc)
			}

			if src := item.SelectNode(ns, "source"); src != nil {
				i.Source = new(Source)
				i.Source.Url = src.As(ns, "url")
				i.Source.Text = src.GetValue()
			}

			tl = item.SelectNodes("http://purl.org/rss/1.0/modules/content/", "*")
			for _, lv := range tl {
				if lv.Name.Local == "encoded" {
					i.Content = new(Content)
					i.Content.Text = lv.String()
					break
				}
			}

			ch.Items = append(ch.Items, i)
		}

		if itemcount != len(ch.Items) && this.itemhandler != nil {
			this.itemhandler(this, ch, ch.Items[itemcount:])
		}
	}
	return
}
Example #9
0
File: rss.go Project: hawx/riviera
func readRssChannel(ns string, doc *xmlx.Document, node *xmlx.Node) *Channel {
	ch := &Channel{
		Title:          node.S(ns, "title"),
		Description:    node.S(ns, "description"),
		Language:       node.S(ns, "language"),
		Copyright:      node.S(ns, "copyright"),
		ManagingEditor: node.S(ns, "managingEditor"),
		WebMaster:      node.S(ns, "webMaster"),
		PubDate:        node.S(ns, "pubDate"),
		LastBuildDate:  node.S(ns, "lastBuildDate"),
		Docs:           node.S(ns, "docs"),
		TTL:            node.I(ns, "ttl"),
		Rating:         node.S(ns, "rating"),
	}

	for _, v := range node.SelectNodes(ns, "link") {
		lnk := Link{}
		if v.Name.Space == "http://www.w3.org/2005/Atom" && v.Name.Local == "link" {
			lnk.Href = v.As("", "href")
			lnk.Rel = v.As("", "rel")
			lnk.Type = v.As("", "type")
			lnk.HrefLang = v.As("", "hreflang")
		} else {
			lnk.Href = v.GetValue()
		}

		ch.Links = append(ch.Links, lnk)
	}

	for _, v := range node.SelectNodes(ns, "category") {
		ch.Categories = append(ch.Categories, Category{
			Domain: v.As(ns, "domain"),
			Text:   v.GetValue(),
		})
	}

	if n := node.SelectNode(ns, "generator"); n != nil {
		ch.Generator = Generator{
			Text: n.GetValue(),
		}
	}

	for _, v := range node.SelectNodes(ns, "hour") {
		ch.SkipHours = append(ch.SkipHours, v.I(ns, "hour"))
	}

	for _, v := range node.SelectNodes(ns, "days") {
		ch.SkipDays = append(ch.SkipDays, days[v.GetValue()])
	}

	if n := node.SelectNode(ns, "image"); n != nil {
		ch.Image = Image{
			Title:       n.S(ns, "title"),
			Url:         n.S(ns, "url"),
			Link:        n.S(ns, "link"),
			Width:       n.I(ns, "width"),
			Height:      n.I(ns, "height"),
			Description: n.S(ns, "description"),
		}
	}

	if n := node.SelectNode(ns, "cloud"); n != nil {
		ch.Cloud = Cloud{
			Domain:            n.As(ns, "domain"),
			Port:              n.Ai(ns, "port"),
			Path:              n.As(ns, "path"),
			RegisterProcedure: n.As(ns, "registerProcedure"),
			Protocol:          n.As(ns, "protocol"),
		}
	}

	if n := node.SelectNode(ns, "textInput"); n != nil {
		ch.TextInput = Input{
			Title:       n.S(ns, "title"),
			Description: n.S(ns, "description"),
			Name:        n.S(ns, "name"),
			Link:        n.S(ns, "link"),
		}
	}

	list := node.SelectNodes(ns, "item")
	if len(list) == 0 {
		list = doc.SelectNodes(ns, "item")
	}

	for _, item := range list {
		ch.Items = append(ch.Items, readRssItem(ns, item))
	}

	ch.Extensions = make(map[string]map[string][]Extension)
	for _, v := range node.Children {
		getExtensions(&ch.Extensions, v)
	}

	return ch
}
Example #10
0
File: rss.go Project: hawx/riviera
func readRssItem(ns string, item *xmlx.Node) *Item {
	i := &Item{
		Title:       item.S(ns, "title"),
		Description: item.S(ns, "description"),
		Comments:    item.S(ns, "comments"),
		PubDate:     item.S(ns, "pubDate"),
	}

	for _, v := range item.SelectNodes(ns, "link") {
		if v.Name.Space == "http://www.w3.org/2005/Atom" && v.Name.Local == "link" {
			i.Links = append(i.Links, Link{
				Href:     v.As("", "href"),
				Rel:      v.As("", "rel"),
				Type:     v.As("", "type"),
				HrefLang: v.As("", "hreflang"),
			})
		} else {
			i.Links = append(i.Links, Link{Href: v.GetValue()})
		}
	}

	if n := item.SelectNode(ns, "author"); n != nil {
		i.Author.Name = n.GetValue()

	} else if n := item.SelectNode(ns, "creator"); n != nil {
		i.Author.Name = n.GetValue()
	}

	if n := item.SelectNode(ns, "guid"); n != nil {
		i.Guid = &Guid{Guid: n.GetValue(), IsPermaLink: n.As("", "isPermalink") == "true"}
	}

	for _, lv := range item.SelectNodes(ns, "category") {
		i.Categories = append(i.Categories, Category{
			Domain: lv.As(ns, "domain"),
			Text:   lv.GetValue(),
		})
	}

	for _, lv := range item.SelectNodes(ns, "enclosure") {
		i.Enclosures = append(i.Enclosures, Enclosure{
			Url:    lv.As(ns, "url"),
			Length: lv.Ai64(ns, "length"),
			Type:   lv.As(ns, "type"),
		})
	}

	if src := item.SelectNode(ns, "source"); src != nil {
		i.Source = new(Source)
		i.Source.Url = src.As(ns, "url")
		i.Source.Text = src.GetValue()
	}

	for _, lv := range item.SelectNodes("http://purl.org/rss/1.0/modules/content/", "*") {
		if lv.Name.Local == "encoded" {
			i.Content = &Content{
				Text: lv.String(),
			}
			break
		}
	}

	i.Extensions = make(map[string]map[string][]Extension)
	for _, lv := range item.Children {
		getExtensions(&i.Extensions, lv)
	}

	return i
}
Example #11
0
File: atom.go Project: hawx/riviera
func readAtomItem(ns string, item *xmlx.Node) *Item {
	i := &Item{
		Title:       item.S(ns, "title"),
		Id:          item.S(ns, "id"),
		PubDate:     item.S(ns, "updated"),
		Description: item.S(ns, "summary"),
	}

	for _, v := range item.SelectNodes(ns, "link") {
		if v.As(ns, "rel") == "enclosure" {
			i.Enclosures = append(i.Enclosures, Enclosure{
				Url:  v.As("", "href"),
				Type: v.As("", "type"),
			})
		} else {
			i.Links = append(i.Links, Link{
				Href:     v.As("", "href"),
				Rel:      v.As("", "rel"),
				Type:     v.As("", "type"),
				HrefLang: v.As("", "hreflang"),
			})
		}
	}

	for _, v := range item.SelectNodes(ns, "contributor") {
		i.Contributors = append(i.Contributors, v.S("", "name"))
	}

	for _, cv := range item.SelectNodes(ns, "category") {
		i.Categories = append(i.Categories, Category{
			Domain: "",
			Text:   cv.As("", "term"),
		})
	}

	if tn := item.SelectNode(ns, "content"); tn != nil {
		i.Content = &Content{
			Type: tn.As("", "type"),
			Lang: tn.S("xml", "lang"),
			Base: tn.S("xml", "base"),
			Text: tn.GetValue(),
		}
	}

	if tn := item.SelectNode(ns, "author"); tn != nil {
		i.Author = Author{
			Name:  tn.S(ns, "name"),
			Uri:   tn.S(ns, "uri"),
			Email: tn.S(ns, "email"),
		}
	}

	return i
}
Example #12
0
File: atom.go Project: hawx/riviera
func readAtomChannel(ns string, node *xmlx.Node) *Channel {
	ch := &Channel{
		Title:         node.S(ns, "title"),
		LastBuildDate: node.S(ns, "updated"),
		Id:            node.S(ns, "id"),
		Rights:        node.S(ns, "rights"),
	}

	for _, v := range node.SelectNodesDirect(ns, "link") {
		ch.Links = append(ch.Links, Link{
			Href:     v.As("", "href"),
			Rel:      v.As("", "rel"),
			Type:     v.As("", "type"),
			HrefLang: v.As("", "hreflang"),
		})
	}

	if tn := node.SelectNode(ns, "subtitle"); tn != nil {
		ch.SubTitle = SubTitle{
			Type: tn.As("", "type"),
			Text: tn.GetValue(),
		}
	}

	if tn := node.SelectNode(ns, "generator"); tn != nil {
		ch.Generator = Generator{
			Uri:     tn.As("", "uri"),
			Version: tn.As("", "version"),
			Text:    tn.GetValue(),
		}
	}

	if tn := node.SelectNode(ns, "author"); tn != nil {
		ch.Author = Author{
			Name:  tn.S("", "name"),
			Uri:   tn.S("", "uri"),
			Email: tn.S("", "email"),
		}
	}

	for _, item := range node.SelectNodes(ns, "entry") {
		ch.Items = append(ch.Items, readAtomItem(ns, item))
	}

	return ch
}