48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
package atom
|
|
|
|
import (
|
|
"encoding/xml"
|
|
"fmt"
|
|
)
|
|
|
|
type Category struct {
|
|
XMLName xml.Name `xml:"category"`
|
|
*CommonAttributes
|
|
Term string `xml:"term,attr"`
|
|
Scheme string `xml:"scheme,attr,omitempty"` // IRI
|
|
Label string `xml:"label,attr,omitempty"`
|
|
}
|
|
|
|
// NewCategory creates a new Category. It returns a *Category.
|
|
func NewCategory(term string) *Category {
|
|
return &Category{
|
|
CommonAttributes: newCommonAttributes(),
|
|
Term: term,
|
|
}
|
|
}
|
|
|
|
// SetLabel sets the Label attribute of the Category.
|
|
func (c *Category) SetLabel(label string) {
|
|
c.Label = Unescape(label)
|
|
}
|
|
|
|
// Check checks the Category for incompatibilities with RFC4287. It returns an
|
|
// error.
|
|
func (c *Category) Check() error {
|
|
if c.Term == "" {
|
|
return fmt.Errorf("term attribute of category %v empty", c)
|
|
}
|
|
|
|
if c.Scheme != "" {
|
|
if !isValidIRI(c.Scheme) {
|
|
return fmt.Errorf("scheme attribute of category %v not correctly formatted", c)
|
|
}
|
|
}
|
|
|
|
if !isCorrectlyEscaped(c.Label) {
|
|
return fmt.Errorf("label attribute of category %v not correctly escaped", c)
|
|
}
|
|
|
|
return nil
|
|
}
|