コード例 #1
0
ファイル: feed.go プロジェクト: apognu/xml
func (f *Feed) validateLinks(err *utils.ErrorAggregator) {
	combinations := make([]string, 0)
	hasSelf := false

	for _, link := range f.Links {
		if link.Rel.Value == "alternate" {
			s := link.Type.Value + link.HrefLang.Value
			unique := true

			for _, comb := range combinations {
				if s == comb {
					err.NewError(xmlutils.NewError(LinkAlternateDuplicated, fmt.Sprintf("Alternate Link duplicated: hreflang '%s' type '%s'", link.HrefLang.Value, link.Type.Value)))
					unique = false
				}
			}

			if unique {
				combinations = append(combinations, s)
			}
		} else if link.Rel.Value == "self" {
			hasSelf = true
		}
	}

	if !hasSelf {
		err.NewError(xmlutils.NewError(MissingSelfLink, "Feed must have a link with rel attribute set to 'self'"))
	}
}
コード例 #2
0
ファイル: entry.go プロジェクト: apognu/xml
func (e *Entry) validateLinks(err *utils.ErrorAggregator) {
	combinations := make([]string, 0)
	hasAlternateRel := false

	for _, link := range e.Links {
		if link.Rel.Value == "alternate" {
			hasAlternateRel = true
			s := link.Type.Value + link.HrefLang.Value
			unique := true

			for _, comb := range combinations {
				if s == comb {
					err.NewError(xmlutils.NewError(LinkAlternateDuplicated, fmt.Sprintf("Alternate Link duplicated: hreflang '%s' type '%s'", link.HrefLang.Value, link.Type.Value)))
					unique = false
				}
			}

			if unique {
				combinations = append(combinations, s)
			}
		}
	}

	if e.Occurences.Count("content") == 0 && !hasAlternateRel {
		err.NewError(xmlutils.NewError(NoContentOrAlternateLink, "Entry should have either a Content element or a Link with alternate type"))
	}
}
コード例 #3
0
ファイル: store.go プロジェクト: apognu/xml
func (s *Store) Validate(errorAgg *utils.ErrorAggregator) {
	for _, store := range s.stores {
		for _, ext := range store.extensions {
			if _, ok := ext.(Attr); ok {
				if err := ext.Validate(); err != nil {
					errorAgg.NewError(err)
				}
			}
		}
	}
}
コード例 #4
0
ファイル: feed.go プロジェクト: apognu/xml
func (f *Feed) validateAuthors(err *utils.ErrorAggregator) {
	if len(f.Authors) > 0 {
		return
	}

	count := 0
	for _, entry := range f.Entries {

		if !entry.hasAuthor() {
			count += 1
		}
	}

	if count > 0 || len(f.Entries) == 0 {
		err.NewError(xmlutils.NewError(MissingAuthor, fmt.Sprintf("%v entry(ies) are missing author reference", count)))
	}
}
コード例 #5
0
ファイル: feed.go プロジェクト: apognu/xml
func (f *Feed) validateEntries(err *utils.ErrorAggregator) {
	combinations := make([]string, 0)

	for _, entry := range f.Entries {
		s := entry.Id.Content.Value + entry.Updated.Time.String()
		unique := true
		for _, comb := range combinations {

			if s == comb {
				err.NewError(xmlutils.NewError(EntryWithIdAndDateDuplicated, fmt.Sprintf("Entries are duplicated: id '%s' updated '%s'", entry.Id.Content.Value, entry.Updated.Time.String())))
				unique = false
			}
		}

		if unique {
			combinations = append(combinations, s)
		}
	}
}
コード例 #6
0
ファイル: source.go プロジェクト: apognu/xml
func (s *Source) validateLinks(err *utils.ErrorAggregator) {
	combinations := make([]string, 0)

	for _, link := range s.Links {
		if link.Rel.Value == "alternate" {
			s := link.Type.Value + link.HrefLang.Value
			unique := true

			for _, comb := range combinations {
				if s == comb {
					err.NewError(xmlutils.NewError(LinkAlternateDuplicated, fmt.Sprintf("Alternate Link duplicated: hreflang '%s' type '%s'", link.HrefLang.Value, link.Type.Value)))
					unique = false
				}
			}

			if unique {
				combinations = append(combinations, s)
			}
		}
	}

}
コード例 #7
0
ファイル: validator.go プロジェクト: apognu/xml
func ValidateElement(parentName string, el Valider, agg *utils.ErrorAggregator) {
	if err := el.Validate(); err != nil {
		agg.NewError(NewError(err.Flag(), fmt.Sprintf("%s's %s", parentName, err.Msg())))
	}
}
コード例 #8
0
ファイル: entry.go プロジェクト: apognu/xml
func (e *Entry) validateAuthors(err *utils.ErrorAggregator) {
	if e.Parent == nil && !e.hasAuthor() {
		err.NewError(xmlutils.NewError(MissingAuthor, "entry should contain at least one author"))
	}

}