2024-10-16 21:28:04 +02:00
|
|
|
package atom
|
2024-10-13 17:19:40 +02:00
|
|
|
|
|
|
|
import (
|
2024-10-17 20:10:18 +02:00
|
|
|
"encoding/xml"
|
2024-10-13 17:19:40 +02:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Category struct {
|
2024-10-17 20:10:18 +02:00
|
|
|
XMLName xml.Name `xml:"category"`
|
2024-10-13 17:19:40 +02:00
|
|
|
*CommonAttributes
|
2024-10-17 18:57:43 +02:00
|
|
|
Term string `xml:"term,attr"`
|
2024-10-19 12:28:09 +02:00
|
|
|
Scheme string `xml:"scheme,attr,omitempty"` // IRI
|
2024-10-20 15:17:53 +02:00
|
|
|
Label string `xml:"label,attr,omitempty"` // Must be unescaped
|
2024-10-15 22:17:10 +02:00
|
|
|
}
|
|
|
|
|
2024-10-19 14:12:51 +02:00
|
|
|
// NewCategory creates a new Category. It returns a *Category.
|
|
|
|
func NewCategory(term string) *Category {
|
2024-10-19 14:52:19 +02:00
|
|
|
return &Category{
|
2024-10-20 15:59:46 +02:00
|
|
|
CommonAttributes: NewCommonAttributes(),
|
2024-10-19 14:52:19 +02:00
|
|
|
Term: term,
|
|
|
|
}
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// Check checks the Category for incompatibilities with RFC4287. It returns an
|
|
|
|
// error.
|
2024-10-13 17:19:40 +02:00
|
|
|
func (c *Category) Check() error {
|
|
|
|
if c.Term == "" {
|
2024-10-18 19:04:08 +02:00
|
|
|
return fmt.Errorf("term attribute of category %v empty", c)
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
2024-10-16 16:48:44 +02:00
|
|
|
if c.Scheme != "" {
|
2024-10-16 17:33:25 +02:00
|
|
|
if !isValidIRI(c.Scheme) {
|
2024-10-18 19:04:08 +02:00
|
|
|
return fmt.Errorf("scheme attribute of category %v not correctly formatted", c)
|
2024-10-16 16:48:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-16 16:51:39 +02:00
|
|
|
if !isCorrectlyEscaped(c.Label) {
|
2024-10-18 19:04:08 +02:00
|
|
|
return fmt.Errorf("label attribute of category %v not correctly escaped", c)
|
2024-10-16 16:51:39 +02:00
|
|
|
}
|
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
return nil
|
|
|
|
}
|