Mercurial > gemma
annotate pkg/soap/validate.go @ 4550:aa2d0006e742 iso-areas
Write iso lines between classes to SVG for debugging.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 30 Sep 2019 16:34:55 +0200 |
parents | bd09d6ad4c14 |
children | 31973f6f5cca |
rev | line source |
---|---|
2181
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package soap |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "bytes" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 "encoding/xml" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "fmt" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "io" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 "io/ioutil" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 "os" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 "os/exec" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 "path/filepath" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 "strings" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 "golang.org/x/net/html/charset" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 "gemma.intevation.de/gemma/pkg/config" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 ) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 const linter = "xmllint" |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 type ( |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 ValidationError string |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 foundError string |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 ) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 func (ef foundError) Error() string { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 return string(ef) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 func (ve ValidationError) Error() string { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 return string(ve) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 func FindSchema(name string) (string, error) { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 name = strings.ToLower(name) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 config.WaitReady() |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 for _, root := range filepath.SplitList(config.SchemaDirs()) { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 if err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 return err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 if info == nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 return nil |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 if info.Mode().IsRegular() && strings.ToLower(info.Name()) == name { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 return foundError(path) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 return nil |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 }) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 if path, ok := err.(foundError); ok { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 return string(path), nil |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 if err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 return "", err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return "", nil |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 func ValidateFile(fname, schema string, dst interface{}) error { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 f, err := os.Open(fname) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 if err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 return err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 defer f.Close() |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 return Validate(f, schema, dst) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 func Validate(r io.Reader, schema string, dst interface{}) error { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 schemaPath, err := FindSchema(schema) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 if err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 return err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 if schemaPath == "" { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 return fmt.Errorf("no schema file '%s' found", schema) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 linterPath, err := exec.LookPath(linter) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 if err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 return err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 type envelope struct { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 _ xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"` |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 Body *struct { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 Inner []byte `xml:",innerxml"` |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 } `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"` |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 content, err := ioutil.ReadAll(r) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 if err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 return err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 dec := xml.NewDecoder(bytes.NewReader(content)) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 dec.CharsetReader = charset.NewReaderLabel |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 var env envelope |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 if err := dec.Decode(&env); err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 return err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 // It has a body -> throw envelope away. |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 if env.Body != nil && len(env.Body.Inner) > 0 { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 content = env.Body.Inner |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 cmd := exec.Command( |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 linterPath, |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 "--schema", schemaPath, |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 "--noout", |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 "-") |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 var stderr bytes.Buffer |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 cmd.Stdin = bytes.NewReader(content) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 cmd.Stderr = &stderr |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 cmd.Stdout = ioutil.Discard |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 if err := cmd.Start(); err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 return err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 if err := cmd.Wait(); err != nil { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 if err2, ok := err.(*exec.ExitError); ok { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 if !err2.Success() { |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 return ValidationError(stderr.String()) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 return err |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 } |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 // Validation successful -> Deserialize. |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 dec = xml.NewDecoder(bytes.NewReader(content)) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 dec.CharsetReader = charset.NewReaderLabel |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 return dec.Decode(dst) |
bd09d6ad4c14
SOAP: Add validating parser (uses 'xmllint') for manual uploads.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 } |