Skip to content

Commit 1f5f9f0

Browse files
committed
prepare ogc api for content negotiation
1 parent 47c9599 commit 1f5f9f0

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/sparqlunicorn_ontdoc/export/api/ogcapifeaturesexporter.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
class OGCAPIFeaturesExporter:
1010

1111
@staticmethod
12-
def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, prefixnamespace, ogcapi, mergeJSON):
12+
def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, prefixnamespace, ogcapi, mergeJSON, contentnegotiation=False):
1313
apihtml = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /><metaname=\"description\" content=\"SwaggerUI\"/><title>SwaggerUI</title><link rel=\"stylesheet\" href=\"https://unpkg.com/swagger-ui-dist/swagger-ui.css\" /></head><body><div id=\"swagger-ui\"></div><script src=\"https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js\" crossorigin></script><script>const swaggerUrl = \"" + str(
1414
deploypath) + "/api/index.json\"; const apiUrl = \"" + str(
1515
deploypath) + "/\"; window.onload = () => {let swaggerJson = fetch(swaggerUrl).then(r => r.json().then(j => {j.servers[0].url = apiUrl; window.ui = SwaggerUIBundle({spec: j,dom_id: '#swagger-ui'});}));};</script></body></html>"
16+
collectionhtmlname="indexc.html"
17+
if contentnegotiation:
18+
collectionhtmlname="index.html"
1619
apijson = {"openapi": "3.0.1", "info": {"title": str(deploypath) + " Feature Collections",
1720
"description": "Feature Collections of " + str(deploypath)},
1821
"servers": [{"url": str(deploypath)}], "paths": {}}
@@ -95,7 +98,7 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
9598
"type": "application/json",
9699
"title": "Supported Feature Collections as JSON"
97100
}, {
98-
"href": str(deploypath) + "/collections/indexc.html",
101+
"href": str(deploypath) + "/collections/"+collectionhtmlname,
99102
"rel": "data",
100103
"type": "text/html",
101104
"title": "Supported Feature Collections as HTML"
@@ -179,7 +182,7 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
179182
currentcollection["links"] = [
180183
{"href": opwebcoll + "/items/index.json", "rel": "items", "type": "application/json",
181184
"title": "Collection as JSON"},
182-
{"href": opwebcoll + "/items/indexc.html", "rel": "items", "type": "text/html",
185+
{"href": opwebcoll + "/items/"+collectionhtmlname, "rel": "items", "type": "text/html",
183186
"title": "Collection as HTML"},
184187
{"href": opwebcoll + "/items/index.ttl", "rel": "collection", "type": "text/ttl",
185188
"title": "Collection as TTL"}]
@@ -202,15 +205,15 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
202205
coll.replace(outpath, "").replace("index.geojson", "").replace(".geojson", "")[1:]),
203206
"parameters": [], "responses": {"default": {"description": "default response", "content": {
204207
"application/json": {"schema": {"$ref": "#/components/schemas/Collections"},"example": None}}}}}}
205-
curcollrow = "<tr><td><a href=\"" + opweb.replace(".geojson", "") + "/items/indexc.html\">" + str(
208+
curcollrow = "<tr><td><a href=\"" + opweb.replace(".geojson", "") + "/items/"+collectionhtmlname+"\">" + str(
206209
featurecollectionspaths[coll]["name"]) + "</a></td><td>"+str(len(curcoll["features"]))+"</td><td><a href=\"" + opweb.replace(".geojson",
207-
"") + "/items/indexc.html\">[Collection as HTML]</a>&nbsp;<a href=\"" + opweb.replace(
210+
"") + "/items/"+collectionhtmlname+"\">[Collection as HTML]</a>&nbsp;<a href=\"" + opweb.replace(
208211
".geojson", "") + "/items/\">[Collection as JSON]</a>&nbsp;<a href=\"" + opweb.replace(".geojson",
209212
"") + "/items/index.ttl\">[Collection as TTL]</a></td></tr>"
210213
f = open(op + "index.json", "w", encoding="utf-8")
211214
f.write(json.dumps(currentcollection))
212215
f.close()
213-
f = open(op + "indexc.html", "w", encoding="utf-8")
216+
f = open(op + collectionhtmlname, "w", encoding="utf-8")
214217
f.write("<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /></head><body><h1>" + featurecollectionspaths[coll][
215218
"name"] + "</h1><table><thead><tr><th>Collection</th><th>Links</th></tr></thead><tbody>" + str(
216219
curcollrow) + "</tbody></table></html>")
@@ -241,8 +244,8 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
241244
coll.replace("//", "/").replace("index.geojson", "index.html").replace(
242245
"nonns_" + featurecollectionspaths[coll]["id"] + ".geojson",
243246
"nonns_" + featurecollectionspaths[coll]["id"] + ".html"),
244-
str(op + "/items/indexc.html").replace("//", "/"), outpath)
245-
f = open(str(op + "/items/indexc.html"), "w")
247+
str(op + "/items/"+collectionhtmlname).replace("//", "/"), outpath)
248+
f = open(str(op + "/items/"+collectionhtmlname), "w")
246249
if "nonns" in collid:
247250
f.write(
248251
"<html><head><meta http-equiv=\"refresh\" content=\"0; url=" + deploypath+"/"+collid+".html"+ "\" /></head></html>")
@@ -361,7 +364,7 @@ def generateOGCAPIFeaturesPages(outpath,deploypath, featurecollectionspaths, pre
361364
f = open(outpath + "/api/api.html", "w", encoding="utf-8")
362365
f.write(apihtml)
363366
f.close()
364-
f = open(outpath + "/collections/indexc.html", "w", encoding="utf-8")
367+
f = open(outpath + "/collections/"+collectionhtmlname, "w", encoding="utf-8")
365368
f.write(collectionshtml.replace("{{collectiontable}}", collectiontable))
366369
f.close()
367370
f = open(outpath + "/collections/index.json", "w", encoding="utf-8")

0 commit comments

Comments
 (0)