Пример #1
0
func (t *TextConstruct) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
	t.name = el.Name.Local
	t.Extension = extension.InitExtension(t.name, t.Extension.Manager)
	t.reset()

	for _, attr := range el.Attr {
		switch attr.Name.Space {
		case xmlutils.XML_NS:
			t.ProcessAttr(attr)

		case "":
			if attr.Name.Local == "type" {
				t.Type = attr.Value
				break
			}
		default:
			t.Extension.ProcessAttr(attr, t)
		}
	}

	switch t.Type {
	case "text", "html":
		t.PlainText.Parent = t
		return t.PlainText, nil

	case "xhtml":
		t.XHTML.Parent = t
		return t.XHTML, nil
	}

	return t.PlainText, nil
}
Пример #2
0
func NewChannelExt(manager extension.Manager) *Channel {
	c := Channel{
		Title:          NewBasicElementExt(manager),
		Link:           NewBasicElementExt(manager),
		Description:    NewUnescapedContentExt(manager),
		Language:       NewBasicElementExt(manager),
		Copyright:      NewBasicElementExt(manager),
		ManagingEditor: NewBasicElementExt(manager),
		Webmaster:      NewBasicElementExt(manager),
		PubDate:        NewDateExt(manager),
		LastBuildDate:  NewDateExt(manager),
		Generator:      NewBasicElementExt(manager),
		Docs:           NewBasicElementExt(manager),
		Cloud:          NewCloudExt(manager),
		Ttl:            NewBasicElementExt(manager),
		Image:          NewImageExt(manager),
		Rating:         NewBasicElementExt(manager),
		SkipHours:      NewBasicElementExt(manager),
		SkipDays:       NewBasicElementExt(manager),

		depth: xmlutils.NewDepthWatcher(),
	}

	c.init()
	c.Extension = extension.InitExtension("channel", manager)

	return &c
}
Пример #3
0
func NewCloudExt(manager extension.Manager) *Cloud {
	c := NewCloud()

	c.Extension = extension.InitExtension("cloud", manager)

	return c
}
Пример #4
0
func NewBasicElementExt(manager extension.Manager) *BasicElement {
	b := NewBasicElement()

	b.Extension = extension.InitExtension("basicelement", manager)

	return b
}
Пример #5
0
Файл: id.go Проект: apognu/xml
func NewIdExt(manager extension.Manager) *Id {
	i := NewId()

	i.Extension = extension.InitExtension("id", manager)

	return i
}
Пример #6
0
func NewDateExt(manager extension.Manager) *Date {
	d := NewDate()

	d.Extension = extension.InitExtension("date", manager)

	return d
}
Пример #7
0
Файл: date.go Проект: apognu/xml
func NewDateExt(manager extension.Manager) *Date {
	d := NewDate()
	d.depth.SetMaxDepth(1)
	d.Extension = extension.InitExtension("date", manager)

	return d
}
Пример #8
0
func NewBasicElementExt(parent xmlutils.Visitor, manager extension.Manager) *BasicElement {
	b := NewBasicElement(parent)

	b.Extension = extension.InitExtension("basicelement", manager)

	return b
}
Пример #9
0
func newWrapperExt(manager extension.Manager) *wrapper {
	w := newWrapper()

	w.Extensions = extension.InitExtension("__", manager)

	return w
}
Пример #10
0
func NewPersonExt(manager extension.Manager) *Person {
	p := Person{depth: xmlutils.NewDepthWatcher()}

	p.Name = NewBasicElementExt(&p, manager)
	p.Uri = NewBasicElementExt(&p, manager)
	p.Email = NewBasicElementExt(&p, manager)

	p.Extension = extension.InitExtension("person", manager)

	p.init()

	return &p
}
Пример #11
0
func NewImageExt(manager extension.Manager) *Image {
	i := Image{depth: xmlutils.NewDepthWatcher()}

	i.Url = NewBasicElementExt(manager)
	i.Title = NewBasicElementExt(manager)
	i.Link = NewBasicElementExt(manager)
	i.Width = NewBasicElementExt(manager)
	i.Height = NewBasicElementExt(manager)
	i.Description = NewBasicElementExt(manager)

	i.init()
	i.Extension = extension.InitExtension("image", manager)

	return &i
}
Пример #12
0
func (b *BasicElement) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
	if b.depth.IsRoot() {
		b.name = el.Name
		b.Extension = extension.InitExtension(b.name.Local, b.Extension.Manager)

		for _, attr := range el.Attr {
			b.Extension.ProcessAttr(attr, b)
		}
	}

	if b.depth.Down() == xmlutils.MaxDepthReached {
		return b, xmlutils.NewError(LeafElementHasChild, fmt.Sprintf("'%s' shoud not have childs", b.Name))
	}

	return b, nil
}
Пример #13
0
func NewSourceExt(manager extension.Manager) *Source {
	s := Source{
		Generator: NewGeneratorExt(manager),
		Icon:      NewIconExt(manager),
		Id:        NewIdExt(manager),
		Logo:      NewLogoExt(manager),
		Rights:    NewTextConstructExt(manager),
		Subtitle:  NewTextConstructExt(manager),
		Title:     NewTextConstructExt(manager),
		Updated:   NewDateExt(manager),

		depth: xmlutils.NewDepthWatcher(),
	}

	s.init()
	s.Extension = extension.InitExtension("source", manager)

	return &s
}
Пример #14
0
Файл: feed.go Проект: apognu/xml
func NewFeedExt(manager extension.Manager) *Feed {
	f := Feed{
		Generator: NewGeneratorExt(manager),
		Icon:      NewIconExt(manager),
		Id:        NewIdExt(manager),
		Logo:      NewLogoExt(manager),
		Rights:    NewTextConstructExt(manager),
		Subtitle:  NewTextConstructExt(manager),
		Title:     NewTextConstructExt(manager),
		Updated:   NewDateExt(manager),

		depth: xmlutils.NewDepthWatcher(),
	}

	f.init()
	f.Extension = extension.InitExtension("feed", manager)

	return &f
}
Пример #15
0
func NewEntryExt(manager extension.Manager) *Entry {
	e := Entry{
		Content:   NewContentExt(manager),
		Id:        NewIdExt(manager),
		Published: NewDateExt(manager),
		Rights:    NewTextConstructExt(manager),
		Source:    NewSourceExt(manager),
		Summary:   NewTextConstructExt(manager),
		Title:     NewTextConstructExt(manager),
		Updated:   NewDateExt(manager),

		depth: xmlutils.NewDepthWatcher(),
	}

	e.init()
	e.Extension = extension.InitExtension("entry", manager)

	return &e
}
Пример #16
0
Файл: item.go Проект: apognu/xml
func NewItemExt(manager extension.Manager) *Item {
	i := Item{
		Title:       NewBasicElementExt(manager),
		Link:        NewBasicElementExt(manager),
		Description: NewUnescapedContentExt(manager),
		Author:      NewBasicElementExt(manager),
		Comments:    NewBasicElementExt(manager),
		Enclosure:   NewEnclosureExt(manager),
		Guid:        NewGuidExt(manager),
		PubDate:     NewDateExt(manager),
		Source:      NewSourceExt(manager),

		depth: xmlutils.NewDepthWatcher(),
	}

	i.init()
	i.Extension = extension.InitExtension("item", manager)

	return &i
}
Пример #17
0
func (u *UnescapedContent) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
	if u.depth.IsRoot() {
		u.name = el.Name
		u.Extension = extension.InitExtension(u.name.Local, u.Extension.Manager)

		for _, attr := range el.Attr {
			u.Extension.ProcessAttr(attr, u)
		}
	}

	err := utils.NewErrorAggregator()

	u.depth.Down()

	if error := u.EncodeXHTMLToken(el); error != nil {
		err.NewError(xmlutils.NewError(XHTMLEncodeToStringError, "cannot encode XHTML"))
	}

	return u, err.ErrorObject()
}
Пример #18
0
func (p *Person) ProcessStartElement(el xmlutils.StartElement) (xmlutils.Visitor, xmlutils.ParserError) {
	if p.depth.IsRoot() {
		p.reset()
		p.name = el.Name.Local
		p.Extension = extension.InitExtension(p.name, p.Extension.Manager)
		for _, attr := range el.Attr {
			if !p.ProcessAttr(attr) {
				p.Extension.ProcessAttr(attr, p)
			}
		}

	}

	switch el.Name.Space {
	case "", "http://www.w3.org/2005/atom":
		switch el.Name.Local {
		case "name":
			p.Name.Content.IncOccurence()
			p.Name.Reset()
			return p.Name.ProcessStartElement(el)
		case "uri":
			p.Uri.Content.IncOccurence()
			p.Uri.Reset()
			return p.Uri.ProcessStartElement(el)
		case "email":
			p.Email.Content.IncOccurence()
			p.Email.Reset()
			return p.Email.ProcessStartElement(el)
		}
	default:
		return p.Extension.ProcessElement(el, p)
	}

	p.depth.Down()

	return p, nil
}
Пример #19
0
func NewEnclosureExt(manager extension.Manager) *Enclosure {
	e := NewEnclosure()
	e.Extension = extension.InitExtension("enclosure", manager)

	return e
}
Пример #20
0
func NewSourceExt(manager extension.Manager) *Source {
	s := NewSource()
	s.Extension = extension.InitExtension("source", manager)

	return s
}
Пример #21
0
func NewTextConstructExt(manager extension.Manager) *TextConstruct {
	t := NewTextConstruct()

	t.Extension = extension.InitExtension("textconstruct", manager)
	return t
}
Пример #22
0
func NewCategoryExt(manager extension.Manager) *Category {
	c := NewCategory()
	c.Extension = extension.InitExtension("category", manager)

	return c
}
Пример #23
0
Файл: guid.go Проект: apognu/xml
func NewGuidExt(manager extension.Manager) *Guid {
	g := NewGuid()
	g.Extension = extension.InitExtension("guid", manager)

	return g
}
Пример #24
0
Файл: link.go Проект: apognu/xml
func NewLinkExt(manager extension.Manager) *Link {
	l := NewLink()
	l.Extension = extension.InitExtension("link", manager)

	return l
}
Пример #25
0
func NewGeneratorExt(manager extension.Manager) *Generator {
	g := NewGenerator()
	g.Extension = extension.InitExtension("generator", manager)

	return g
}
Пример #26
0
Файл: logo.go Проект: apognu/xml
func NewLogoExt(manager extension.Manager) *Logo {
	l := NewLogo()
	l.Extension = extension.InitExtension("logo", manager)

	return l
}
Пример #27
0
Файл: icon.go Проект: apognu/xml
func NewIconExt(manager extension.Manager) *Icon {
	i := NewIcon()

	i.Extension = extension.InitExtension("icon", manager)
	return i
}
Пример #28
0
func NewContentExt(manager extension.Manager) *Content {
	c := NewContent()
	c.Extension = extension.InitExtension("content", manager)

	return c
}
Пример #29
0
func NewUnescapedContentExt(manager extension.Manager) *UnescapedContent {
	u := NewUnescapedContent()
	u.Extension = extension.InitExtension("unescaped", manager)

	return u
}