atom/inlineOtherContent.go

53 lines
1.6 KiB
Go

package atom
import (
"encoding/xml"
"fmt"
"mime"
)
type InlineOtherContent struct {
XMLName xml.Name `xml:"content"`
*CommonAttributes
AnyElement any `xml:",chardata"`
Type string `xml:"type,attr,omitempty"` // MediaType
}
// newInlineOtherContent creates a new InlineOtherContent. It returns a
// *InlineOtherContent and an error.
func newInlineOtherContent(mediaType string, content any) (*InlineOtherContent, error) {
if !isValidMediaType(mediaType) {
return nil, fmt.Errorf("error creating new inline other content: media type %v invalid", mediaType)
}
mediaType, _, _ = mime.ParseMediaType(mediaType)
return &InlineOtherContent{Type: 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 i.Type }
// Check checks the InlineOtherContent for incompatibilities with RFC4287. It
// returns an error.
func (i *InlineOtherContent) Check() error {
mediaType := i.getType()
if !isValidMediaType(mediaType) {
return fmt.Errorf("type attribute of inline other content %v invalid media type", i)
}
if isCompositeMediaType(mediaType) {
return fmt.Errorf("type attribute of inline other content %v must not be a composite type", i)
}
return nil
}