Added more error handling and necessary functions
This commit is contained in:
@@ -9,18 +9,19 @@ import (
|
||||
type OutOfLineContent struct {
|
||||
XMLName xml.Name `xml:"content"`
|
||||
*CommonAttributes
|
||||
Type MediaType `xml:"type,attr,omitempty"`
|
||||
SRC IRI `xml:"src,attr"`
|
||||
Type string `xml:"type,attr,omitempty"` // MediaType
|
||||
SRC string `xml:"src,attr"` // IRI
|
||||
}
|
||||
|
||||
// newOutOfLineContent creates a new OutOfLineContent. It returns a
|
||||
// *OutOfLineContent and an error.
|
||||
func newOutOfLineContent(mediaType string, content any) (*OutOfLineContent, error) {
|
||||
if mediaType, _, err := mime.ParseMediaType(mediaType); err != nil {
|
||||
return nil, fmt.Errorf("media type %v incompatible with out of line content", mediaType)
|
||||
if !isValidMediaType(mediaType) {
|
||||
return nil, fmt.Errorf("error creating new out of line content: media type %v invalid", mediaType)
|
||||
}
|
||||
mediaType, _, _ = mime.ParseMediaType(mediaType)
|
||||
|
||||
iri, ok := content.(IRI)
|
||||
iri, ok := content.(string)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("content type %T incompatible with out of line content", content)
|
||||
}
|
||||
@@ -29,7 +30,7 @@ func newOutOfLineContent(mediaType string, content any) (*OutOfLineContent, erro
|
||||
return nil, fmt.Errorf("content %v not a valid uri", iri)
|
||||
}
|
||||
|
||||
return &OutOfLineContent{Type: MediaType(mediaType), SRC: iri}, nil
|
||||
return &OutOfLineContent{Type: mediaType, SRC: iri}, nil
|
||||
}
|
||||
|
||||
// isContent checks whether the OutOfLineContent is a Content. It returns a
|
||||
@@ -41,15 +42,15 @@ func (o *OutOfLineContent) isContent() bool { return true }
|
||||
func (o *OutOfLineContent) hasSRC() bool { return true }
|
||||
|
||||
// getType returns the Type of the OutOfLineContent as a string.
|
||||
func (o *OutOfLineContent) getType() string { return string(o.Type) }
|
||||
func (o *OutOfLineContent) getType() string { return o.Type }
|
||||
|
||||
// Check checks the OutOfLineContent for incompatibilities with RFC4287. It
|
||||
// returns an error.
|
||||
func (o *OutOfLineContent) Check() error {
|
||||
mediaType := o.getType()
|
||||
|
||||
if mediaType, _, err := mime.ParseMediaType(mediaType); err != nil {
|
||||
return fmt.Errorf("type attribute %v incompatible with out of line content", mediaType)
|
||||
if !isValidMediaType(mediaType) {
|
||||
return fmt.Errorf("type attribute of out of line content %v invalid media type", o)
|
||||
}
|
||||
|
||||
if isCompositeMediaType(mediaType) {
|
||||
|
Reference in New Issue
Block a user