2024-10-16 21:28:04 +02:00
|
|
|
package atom
|
2024-10-13 17:19:40 +02:00
|
|
|
|
2024-10-15 21:01:40 +02:00
|
|
|
import (
|
2024-10-17 20:10:18 +02:00
|
|
|
"encoding/xml"
|
2024-10-15 21:01:40 +02:00
|
|
|
"fmt"
|
|
|
|
"mime"
|
|
|
|
)
|
2024-10-15 19:53:17 +02:00
|
|
|
|
2024-10-13 17:19:40 +02:00
|
|
|
type InlineOtherContent struct {
|
2024-10-17 20:10:18 +02:00
|
|
|
XMLName xml.Name `xml:"content"`
|
2024-10-13 17:19:40 +02:00
|
|
|
*CommonAttributes
|
2024-10-19 12:28:09 +02:00
|
|
|
AnyElement any `xml:",chardata"`
|
|
|
|
Type string `xml:"type,attr,omitempty"` // MediaType
|
2024-10-15 21:01:40 +02:00
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// newInlineOtherContent creates a new InlineOtherContent. It returns a
|
|
|
|
// *InlineOtherContent and an error.
|
2024-10-15 21:01:40 +02:00
|
|
|
func newInlineOtherContent(mediaType string, content any) (*InlineOtherContent, error) {
|
2024-10-19 12:28:09 +02:00
|
|
|
if !isValidMediaType(mediaType) {
|
|
|
|
return nil, fmt.Errorf("error creating new inline other content: media type %v invalid", mediaType)
|
2024-10-15 21:01:40 +02:00
|
|
|
}
|
2024-10-19 12:28:09 +02:00
|
|
|
mediaType, _, _ = mime.ParseMediaType(mediaType)
|
2024-10-15 21:01:40 +02:00
|
|
|
|
2024-10-19 12:28:09 +02:00
|
|
|
return &InlineOtherContent{Type: mediaType, AnyElement: content}, nil
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// isContent checks whether the InlineOtherContent is a Content. It returns a
|
|
|
|
// bool.
|
2024-10-15 19:32:14 +02:00
|
|
|
func (i *InlineOtherContent) isContent() bool { return true }
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// hasSRC checks whether the InlineOtherContent has a SRC attribute. It returns
|
|
|
|
// a bool.
|
2024-10-15 19:32:14 +02:00
|
|
|
func (i *InlineOtherContent) hasSRC() bool { return false }
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// getType returns the Type of the InlineOtherContent as a string.
|
2024-10-19 12:28:09 +02:00
|
|
|
func (i *InlineOtherContent) getType() string { return i.Type }
|
2024-10-13 17:19:40 +02:00
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// Check checks the InlineOtherContent for incompatibilities with RFC4287. It
|
|
|
|
// returns an error.
|
2024-10-15 19:53:17 +02:00
|
|
|
func (i *InlineOtherContent) Check() error {
|
2024-10-15 21:47:13 +02:00
|
|
|
mediaType := i.getType()
|
|
|
|
|
2024-10-19 12:28:09 +02:00
|
|
|
if !isValidMediaType(mediaType) {
|
|
|
|
return fmt.Errorf("type attribute of inline other content %v invalid media type", i)
|
2024-10-15 21:47:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if isCompositeMediaType(mediaType) {
|
2024-10-18 19:04:08 +02:00
|
|
|
return fmt.Errorf("type attribute of inline other content %v must not be a composite type", i)
|
2024-10-15 19:53:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|