2024-10-16 21:28:04 +02:00
|
|
|
package atom
|
2024-10-13 17:19:40 +02:00
|
|
|
|
2024-10-15 20:53:01 +02:00
|
|
|
import (
|
2024-10-17 20:10:18 +02:00
|
|
|
"encoding/xml"
|
2024-10-15 20:53:01 +02:00
|
|
|
"fmt"
|
|
|
|
)
|
2024-10-13 17:19:40 +02:00
|
|
|
|
|
|
|
type InlineXHTMLContent 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-17 19:44:27 +02:00
|
|
|
XHTMLDiv *XHTMLDiv
|
2024-10-13 17:19:40 +02:00
|
|
|
Type string `xml:"type,attr"`
|
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// newInlineXHTMLContent creates a new InlineXHTMLContent. It returns a
|
|
|
|
// *InlineXHTMLContent and an error.
|
2024-10-15 20:53:01 +02:00
|
|
|
func newInlineXHTMLContent(mediaType string, content any) (*InlineXHTMLContent, error) {
|
|
|
|
if mediaType != "xhtml" {
|
|
|
|
return nil, fmt.Errorf("media type %v incompatible with inline xhtml content", mediaType)
|
|
|
|
}
|
|
|
|
|
2024-10-17 19:44:27 +02:00
|
|
|
xhtmlDiv, ok := content.(*XHTMLDiv)
|
2024-10-17 18:12:56 +02:00
|
|
|
if !ok {
|
2024-10-15 20:53:01 +02:00
|
|
|
return nil, fmt.Errorf("content type %T incompatible with inline xhtml content", content)
|
|
|
|
}
|
|
|
|
|
2024-10-17 18:12:56 +02:00
|
|
|
return &InlineXHTMLContent{Type: mediaType, XHTMLDiv: xhtmlDiv}, nil
|
2024-10-15 20:53:01 +02:00
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// isContent checks whether the InlineXHTMLContent is a Content. It returns a
|
|
|
|
// bool.
|
2024-10-15 19:32:14 +02:00
|
|
|
func (i *InlineXHTMLContent) isContent() bool { return true }
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// hasSRC checks whether the InlineXHTMLContent has a SRC attribute. It returns
|
|
|
|
// a bool.
|
2024-10-15 19:32:14 +02:00
|
|
|
func (i *InlineXHTMLContent) hasSRC() bool { return false }
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// getType returns the Type of the InlineXHTMLContent as a string.
|
2024-10-15 19:32:14 +02:00
|
|
|
func (i *InlineXHTMLContent) getType() string { return i.Type }
|
2024-10-13 17:19:40 +02:00
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// Check checks the InlineXHTMLContent for incompatibilities with RFC4287. It
|
|
|
|
// returns an error.
|
2024-10-13 17:19:40 +02:00
|
|
|
func (i *InlineXHTMLContent) Check() error {
|
|
|
|
if i.Type != "xhtml" {
|
2024-10-18 19:04:08 +02:00
|
|
|
return fmt.Errorf("type attribute of inline xhtml content %v must be xhtml", i)
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
2024-10-17 18:12:56 +02:00
|
|
|
if err := i.XHTMLDiv.Check(); err != nil {
|
2024-10-18 19:04:08 +02:00
|
|
|
return fmt.Errorf("xhtml div element of inline xhtml content %v: %v", i, err)
|
2024-10-13 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|