xref: /aosp_15_r20/external/spdx-tools/tvloader/parser2v3/parse_annotation.go (revision ba677afa8f67bb56cbc794f4d0e378e0da058e16)
1// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
2
3package parser2v3
4
5import (
6	"fmt"
7)
8
9func (parser *tvParser2_3) parsePairForAnnotation2_3(tag string, value string) error {
10	if parser.ann == nil {
11		return fmt.Errorf("no annotation struct created in parser ann pointer")
12	}
13
14	switch tag {
15	case "Annotator":
16		subkey, subvalue, err := extractSubs(value)
17		if err != nil {
18			return err
19		}
20		if subkey == "Person" || subkey == "Organization" || subkey == "Tool" {
21			parser.ann.Annotator.AnnotatorType = subkey
22			parser.ann.Annotator.Annotator = subvalue
23			return nil
24		}
25		return fmt.Errorf("unrecognized Annotator type %v", subkey)
26	case "AnnotationDate":
27		parser.ann.AnnotationDate = value
28	case "AnnotationType":
29		parser.ann.AnnotationType = value
30	case "SPDXREF":
31		deID, err := extractDocElementID(value)
32		if err != nil {
33			return err
34		}
35		parser.ann.AnnotationSPDXIdentifier = deID
36	case "AnnotationComment":
37		parser.ann.AnnotationComment = value
38	default:
39		return fmt.Errorf("received unknown tag %v in Annotation section", tag)
40	}
41
42	return nil
43}
44