File tree Expand file tree Collapse file tree 5 files changed +75
-11
lines changed Expand file tree Collapse file tree 5 files changed +75
-11
lines changed Original file line number Diff line number Diff line change @@ -53,9 +53,6 @@ func main() {
5353 fmt .Printf ("==============\n " )
5454 fmt .Printf ("%#v\n \n " , doc .CreationInfo )
5555
56- fmt .Printf ("==============\n " )
57- fmt .Printf ("Packages:\n " )
58- fmt .Printf ("==============\n " )
5956 // check whether the SPDX file has at least one package
6057 if doc .Packages == nil || len (doc .Packages ) < 1 {
6158 fmt .Printf ("No packages found in SPDX document\n " )
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "os"
6+
7+ "github.com/spdx/tools-golang/v0/rdfloader"
8+ "github.com/spdx/tools-golang/v0/rdfsaver"
9+
10+ "github.com/spdx/tools-golang/v0/rdfloader/rdf2v1"
11+ )
12+
13+ func main () {
14+
15+ // check that we've received the right number of arguments
16+ args := os .Args
17+ if len (args ) != 2 {
18+ fmt .Printf ("Usage: %v <spdx-file-in>\n " , args [0 ])
19+ fmt .Printf (" Load SPDX 2.1 tag-value file <spdx-file-in>, and\n " )
20+ fmt .Printf (" print a portion of its contents.\n " )
21+ return
22+ }
23+
24+ // storing the input
25+ input := args [1 ]
26+
27+ // try to load the SPDX file's contents as a rdf file, version 2.1
28+ doc2v1 := rdfloader .Reader2_1 (input )
29+
30+ err := rdfsaver .Saver2_1 (doc2v1 )
31+ if err != nil {
32+ fmt .Printf ("Error while saving the document." )
33+ return
34+ }
35+
36+ // if we got here, the file is now loaded into memory.
37+
38+ }
39+ func Parse2_1 (input string ) (* rdf2v1.Document , * rdf2v1.Snippet , error ) {
40+ parser := rdf2v1 .NewParser (input )
41+ defer fmt .Printf ("RDF Document parsed successfully.\n " )
42+ defer parser .Free ()
43+ return parser .Parse ()
44+ }
Original file line number Diff line number Diff line change @@ -61,3 +61,10 @@ licenses for subsequent versions of the same set of files.
6161
6262This example demonstrates loading an SPDX Rdf file from disk into memory,
6363and printing some of its contents to standard output.
64+
65+ ## 8-load-save-Rdf/
66+
67+ * rdfloader* , * rdfsaver*
68+
69+ This example demonstrates loading an SPDX RDF file from disk into memory,
70+ and re-saving it to a different file on disk.
Original file line number Diff line number Diff line change @@ -14,11 +14,20 @@ func Reader2_1(input string) *spdx.Document2_1 {
1414 if err != nil {
1515 fmt .Errorf ("Parsing Error" )
1616 }
17- doc2v1 := rdf2v1 .TransferDocument (spdxdoc , sp )
18- if doc2v1 == nil {
19- fmt .Errorf ("Translation Error" )
17+ if sp != nil {
18+ doc2v1 := rdf2v1 .TransferDocument (spdxdoc , sp )
19+ if doc2v1 == nil {
20+ fmt .Errorf ("Translation Error" )
21+ }
22+ return doc2v1
23+ } else {
24+ doc2v1 := rdf2v1 .TransferDocumentWithoutSnippets (spdxdoc )
25+ if doc2v1 == nil {
26+ fmt .Errorf ("Translation Error" )
27+ }
28+ return doc2v1
2029 }
21- return doc2v1
30+ return nil
2231}
2332
2433func Parse (input string ) (* rdf2v1.Document , * rdf2v1.Snippet , error ) {
Original file line number Diff line number Diff line change 11package rdfsaver
22
33import (
4+ "fmt"
45 "os"
56
6- "github.com/spdx/tools-golang/v0/rdfsaver/rdfsaver2v1 "
7+ "github.com/spdx/tools-golang/v0/spdx "
78
89 "github.com/spdx/tools-golang/v0/rdfloader/rdf2v1"
10+ "github.com/spdx/tools-golang/v0/rdfloader/rdfsaver2v1"
911)
1012
11- func Saver2_1 (spdxdoc * rdf2v1. Document , sp * rdf2v1. Snippet ) error {
13+ func Saver2_1 (doc2v1 * spdx. Document2_1 ) error {
1214
15+ newdoc2v1 := rdf2v1 .CollectDocument (doc2v1 )
16+ newsn2v1 := rdf2v1 .CollectSnippets (doc2v1 )
1317 output := os .Stdout
14- err := rdfsaver2v1 .Write (output , spdxdoc , sp )
15- return err
18+ errdoc := rdfsaver2v1 .WriteDocument (output , newdoc2v1 , newsn2v1 )
19+ if errdoc != nil {
20+ fmt .Errorf ("Parsing Error" )
21+ }
22+ return errdoc
1623}
You can’t perform that action at this time.
0 commit comments