changeset 1596:74413d52c439

Started with WFS Capabilities parser.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 14 Dec 2018 18:35:09 +0100
parents f6596daf2079
children 98a1636c7255
files cmd/wfs/main.go pkg/wfs/capabilities.go
diffstat 2 files changed, 163 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wfs/main.go	Fri Dec 14 18:35:09 2018 +0100
@@ -0,0 +1,64 @@
+// This is Free Software under GNU Affero General Public License v >= 3.0
+// without warranty, see README.md and license for details.
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// License-Filename: LICENSES/AGPL-3.0.txt
+//
+// Copyright (C) 2018 by via donau
+//   – Österreichische Wasserstraßen-Gesellschaft mbH
+// Software engineering by Intevation GmbH
+//
+// Author(s):
+//  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+package main
+
+import (
+	"bufio"
+	"flag"
+	"fmt"
+	"log"
+	"os"
+
+	"gemma.intevation.de/gemma/pkg/wfs"
+)
+
+func loadCapabilities(fname string) (*wfs.Capabilities, error) {
+	f, err := os.Open(fname)
+	if err != nil {
+		return nil, err
+	}
+	defer f.Close()
+	return wfs.ParseCapabilities(bufio.NewReader(f))
+}
+
+func main() {
+	flag.Parse()
+
+	for _, arg := range flag.Args() {
+		caps, err := loadCapabilities(arg)
+		if err != nil {
+			log.Fatalf("error: %v\n", err)
+		}
+
+		fmt.Printf("title: %s\n", caps.ServiceIdentification.Title)
+		fmt.Printf("type: %s\n", caps.ServiceIdentification.ServiceType)
+		fmt.Printf("version: %s\n", caps.ServiceIdentification.ServiceTypeVersion)
+		for _, operation := range caps.OperationsMetadata.Operations {
+			fmt.Printf("\t%s\n", operation.Name)
+			if operation.DCP.HTTP.Get != nil {
+				fmt.Printf("\t\tGet: %s\n", operation.DCP.HTTP.Get.HRef)
+			}
+			if operation.DCP.HTTP.Post != nil {
+				fmt.Printf("\t\tPost: %s\n", operation.DCP.HTTP.Post.HRef)
+			}
+
+			for _, p := range operation.Parameters {
+				fmt.Printf("\t\tparameter: %s\n", p.Name)
+				for _, av := range p.AllowedValues.AllowedValues {
+					fmt.Printf("\t\t\t%s\n", av.Value)
+				}
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pkg/wfs/capabilities.go	Fri Dec 14 18:35:09 2018 +0100
@@ -0,0 +1,99 @@
+// This is Free Software under GNU Affero General Public License v >= 3.0
+// without warranty, see README.md and license for details.
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// License-Filename: LICENSES/AGPL-3.0.txt
+//
+// Copyright (C) 2018 by via donau
+//   – Österreichische Wasserstraßen-Gesellschaft mbH
+// Software engineering by Intevation GmbH
+//
+// Author(s):
+//  * Sascha L. Teichmann <sascha.teichmann@intevation.de>
+
+package wfs
+
+import (
+	"encoding/xml"
+	"io"
+
+	"golang.org/x/net/html/charset"
+)
+
+type ServiceIdentification struct {
+	XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 ServiceIdentification"`
+
+	Title              string
+	ServiceType        string
+	ServiceTypeVersion string
+}
+
+type Get struct {
+	XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 Get"`
+	HRef    string   `xml:"http://www.w3.org/1999/xlink href,attr"`
+}
+
+type Post struct {
+	XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 Post"`
+	HRef    string   `xml:"http://www.w3.org/1999/xlink href,attr"`
+}
+
+type HTTP struct {
+	XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 HTTP"`
+	Get     *Get     `xml:"Get"`
+	Post    *Post    `xml:"Post"`
+}
+
+type DCP struct {
+	XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 DCP"`
+	HTTP    HTTP     `xml:"HTTP"`
+}
+
+type AllowedValue struct {
+	XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 Value"`
+	Value   string   `xml:",cdata"`
+}
+
+type AllowedValues struct {
+	XMLName       xml.Name       `xml:"http://www.opengis.net/ows/1.1 AllowedValues"`
+	AllowedValues []AllowedValue `xml:"Value"`
+}
+
+type Parameter struct {
+	XMLName       xml.Name      `xml:"http://www.opengis.net/ows/1.1 Parameter"`
+	Name          string        `xml:"name,attr"`
+	AllowedValues AllowedValues `xml:"AllowedValues"`
+}
+
+type Operation struct {
+	XMLName    xml.Name     `xml:"http://www.opengis.net/ows/1.1 Operation"`
+	Name       string       `xml:"name,attr"`
+	DCP        DCP          `xml:"DCP"`
+	Parameters []*Parameter `xml:"Parameter"`
+}
+
+type OperationsMetadata struct {
+	XMLName    xml.Name     `xml:"http://www.opengis.net/ows/1.1 OperationsMetadata"`
+	Operations []*Operation `xml:"http://www.opengis.net/ows/1.1 Operation"`
+}
+
+type Capabilities struct {
+	XMLName xml.Name `xml:"http://www.opengis.net/wfs/2.0 WFS_Capabilities"`
+
+	ServiceIdentification ServiceIdentification
+	OperationsMetadata    OperationsMetadata
+}
+
+func ParseCapabilities(r io.Reader) (*Capabilities, error) {
+
+	decoder := xml.NewDecoder(r)
+	decoder.CharsetReader = charset.NewReaderLabel
+
+	var capabilities Capabilities
+
+	if err := decoder.Decode(&capabilities); err != nil {
+		return nil, err
+	}
+
+	return &capabilities, nil
+}