Exemplo n.º 1
0
Arquivo: atom.go Projeto: 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
}
Exemplo n.º 2
0
Arquivo: atom.go Projeto: 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
}
Exemplo n.º 3
0
Arquivo: rss.go Projeto: 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
}
Exemplo n.º 4
0
Arquivo: rss.go Projeto: 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
}