atom/inlineOtherContent.go

51 lines
1.5 KiB
Go

package atomfeed
import (
"errors"
"fmt"
"mime"
)
type InlineOtherContent struct {
*CommonAttributes
AnyElement any `xml:"anyelement,omitempty"`
Type MediaType `xml:"type,attr,omitempty"`
}
// newInlineOtherContent creates a new InlineOtherContent. It returns a
// *InlineOtherContent and an error.
func newInlineOtherContent(mediaType string, content any) (*InlineOtherContent, error) {
if mediaType, _, err := mime.ParseMediaType(mediaType); err != nil {
return nil, fmt.Errorf("media type %v incompatible with inline other content", mediaType)
}
return &InlineOtherContent{Type: MediaType(mediaType), AnyElement: content}, nil
}
// isContent checks whether the InlineOtherContent is a Content. It returns a
// bool.
func (i *InlineOtherContent) isContent() bool { return true }
// hasSRC checks whether the InlineOtherContent has a SRC attribute. It returns
// a bool.
func (i *InlineOtherContent) hasSRC() bool { return false }
// getType returns the Type of the InlineOtherContent as a string.
func (i *InlineOtherContent) getType() string { return string(i.Type) }
// Check checks the InlineOtherContent for incompatibilities with RFC4287. It
// returns an error.
func (i *InlineOtherContent) Check() error {
mediaType := i.getType()
if mediaType, _, err := mime.ParseMediaType(mediaType); err != nil {
return fmt.Errorf("type attribute %v incompatible with inline other content", mediaType)
}
if isCompositeMediaType(mediaType) {
return errors.New("type attribute of inline other content must not be a composite type")
}
return nil
}