From 69a9398e61174a8f7c414fa8471d47a8ee0842ed Mon Sep 17 00:00:00 2001 From: Simon Oakes Date: Tue, 19 Jul 2022 13:12:14 +0100 Subject: [PATCH 01/44] Request facets in the negotiated language. --- ldregistry/templates/main/_page-category.vm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ldregistry/templates/main/_page-category.vm b/ldregistry/templates/main/_page-category.vm index 99a03b4..9434c97 100644 --- a/ldregistry/templates/main/_page-category.vm +++ b/ldregistry/templates/main/_page-category.vm @@ -5,7 +5,7 @@ #set($state="") #end - #set($fr=$registry.facetService.query($state)) + #set($fr=$registry.facetService.query($state, $language))
From 1516a9175aacf1da2c1825be4b10c240a92970f3 Mon Sep 17 00:00:00 2001 From: Mike Gormley Date: Wed, 7 Dec 2022 10:05:58 +0000 Subject: [PATCH 02/44] CDF-568 Update query example tutorial documentation. (#59) * Documentation changes to the query tutorial. * Add Identifiers documentation link to the footer * Add table and formatting * Add .idea path to .gitignore --- .gitignore | 3 +- ldregistry/templates/about/querying.vm | 88 ++++++++++++++------- ldregistry/templates/structure/_footer.vm | 5 +- ldregistry/ui/assets/js/querying-example.js | 44 +++++++---- ldregistry/ui/css/ui.css | 12 +-- 5 files changed, 100 insertions(+), 52 deletions(-) diff --git a/.gitignore b/.gitignore index 3c02684..ccaf781 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ /derby.log /cookie-jar .vagrant -/war/ROOT.war \ No newline at end of file +/war/ROOT.war +.idea \ No newline at end of file diff --git a/ldregistry/templates/about/querying.vm b/ldregistry/templates/about/querying.vm index 39a9344..86416b4 100644 --- a/ldregistry/templates/about/querying.vm +++ b/ldregistry/templates/about/querying.vm @@ -3,7 +3,7 @@
-

Populate Contents Tutorial

+

Query Registry Contents Tutorial

@@ -11,24 +11,47 @@ within other implementations.

Contents of a registry may be used as structured information. The registry provides a - query endpoint where queries using the W3 SPARQL query language may be run.

+ query endpoint where queries using the + W3C SPARQL query language may be run.

-

For example, JavaScript may be written to target the service query endpoint and - run a query that obtains all the registers and the current version +

For example, JavaScript may be written to target the service query (/system/query) endpoint and + run a query that obtains all the elements within a specific register and the associated labels for each element.

 let endpoint = "/system/query";
-let query = "prefix version: 
-            prefix reg: 
-            select * where {
-            ?register a reg:Register; version:currentVersion ?regVer.} limit 10"
+let query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
+                PREFIX reg: <http://purl.org/linked-data/registry#>
+                PREFIX version: <http://purl.org/linked-data/version#>
+                SELECT ?regdef ?label WHERE {
+                ?item reg:register <http://codes.wmo.int/49-2/AerodromeRecentWeather> ;
+                    version:currentVersion/reg:definition/reg:entity ?regdef ;
+                    version:currentVersion ?itemVer .
+                ?regdef rdfs:label ?label . } LIMIT 10"
+
+ +

The query above obtains the identifying URI and associated label text for each member of the + DataCategories/data-types register of terms. +

+ +

There is a SPARQL interface available from the _Advanced_ menu, which you can use to + experiment with queries and responses. You can try copying this query and running it + through the query web interface page, and also adapting query syntax to meet your needs. +

+ +

+ A JavaScript function can be provided to run the query on the endpoint and return + results that may be processed and presented, used in forms, and applied to other aspects of user + interaction. In this example, an HTML div container is created as the location for the output. +

+ +
+    <div id="results"></div>
 

- A javascript function can be provided to run the query on the end point and return - results that may be processed and presented, used in forms, and applied to other aspects - of user interaction. + This example creates an HTTP Request against the endpoint, checks for an OK (HTTP 200) response, + and sends the response content to a callback method.

@@ -38,25 +61,25 @@ function sparqlQueryJson(queryStr, endpoint, callback) {
     // Build the request URI
     let requestUri = endpoint + "?query=" + escape(queryStr) + "&output=json";
 
-    // Get our HTTP request object.
+    // Get our HTTP request object
     if (window.XMLHttpRequest) {
         let xhr = new XMLHttpRequest();
         xhr.open('GET', requestUri, true);
 
-        // Set up callback to get the response asynchronously.
+        // Set up callback to get the response asynchronously
         xhr.onreadystatechange = function () {
             if (xhr.readyState === 4) {
                 if (xhr.status === 200) {
                     // Do something with the results
                     callback(xhr.responseText);
                 } else {
-                    // Some kind of error occurred.
+                    // Some kind of error occurred
                     alert("Sparql query error: " + xhr.status + " " + xhr.responseText);
                 }
             }
         };
 
-        // Send the query to the endpoint.
+        // Send the query to the endpoint
         xhr.send();
     } else {
         divResults.innerHTML = "Your browser does not support XMLHttpRequest";
@@ -65,8 +88,10 @@ function sparqlQueryJson(queryStr, endpoint, callback) {
 

- Defining a callback function in the script to process results provides easy access to - information from the register. + Defining a callback function in the script to process results provides easy access to information + from the register. The JavaScript below loops through the results of the SPARQL query and outputs + them as rows in an HTML table. Actual usage would depend on the context and usage profile, which + is likely not a plain html table of elements but the general principle remains.

@@ -74,20 +99,28 @@ function myCallback(str) {
     // Convert result to JSON
     let jsonObj = eval('(' + str + ')');
 
-    // Build up a table of results.
+    // Build up a table of results
     let table = document.createElement("table");
     table.className = "table table-striped table-bordered datatable dataTable";
 
+    // Create table head
+    let tableHead = document.createElement("thead");
+    table.appendChild(tableHead);
+
     // Create column headers
-    let tableHeader = document.createElement("tr");
+    let tableHeadRow = document.createElement("tr");
 
     for (let dataColumn of jsonObj.head.vars) {
         let th = document.createElement("th");
         th.appendChild(document.createTextNode(dataColumn));
-        tableHeader.appendChild(th);
+        tableHeadRow.appendChild(th);
     }
 
-    table.appendChild(tableHeader);
+    tableHead.appendChild(tableHeadRow);
+
+    // Create table body
+    let tableBody = document.createElement("tbody");
+    table.appendChild(tableBody);
 
     // Create result rows
     for (let dataRow of jsonObj.results.bindings) {
@@ -100,7 +133,7 @@ function myCallback(str) {
             tableRow.appendChild(td);
         }
 
-        table.appendChild(tableRow);
+        tableBody.appendChild(tableRow);
     }
 
     // Append the table to the results HTML container
@@ -110,7 +143,7 @@ function myCallback(str) {
 

- Finally, call the sparqlQueryJson method to initiate the query. + Finally, call the sparqlQueryJson method to initiate the query.

@@ -119,14 +152,13 @@ sparqlQueryJson(query, endpoint, myCallback);
 
 

Queries may be structured to deliver the information required for a particular use case, - based on knowledge of the - targeted register information. + based on knowledge of the targeted register information.

Example Results

- Results from this example are presented below. 'browse source' on this page to see this - working example code set out. + Results from this example are presented below. + See the full working example.

@@ -134,4 +166,4 @@ sparqlQueryJson(query, endpoint, myCallback);
#set($extraJS="querying-example.js") -#parse("structure/_footer.vm") \ No newline at end of file +#parse("structure/_footer.vm") diff --git a/ldregistry/templates/structure/_footer.vm b/ldregistry/templates/structure/_footer.vm index 05c1576..2e26c71 100644 --- a/ldregistry/templates/structure/_footer.vm +++ b/ldregistry/templates/structure/_footer.vm @@ -8,7 +8,10 @@
diff --git a/ldregistry/ui/assets/js/querying-example.js b/ldregistry/ui/assets/js/querying-example.js index 8d9cc37..678b80e 100644 --- a/ldregistry/ui/assets/js/querying-example.js +++ b/ldregistry/ui/assets/js/querying-example.js @@ -2,60 +2,72 @@ * Querying Example JavaScript used by the /ui/querying page. */ let endpoint = "/system/query"; -let query = "prefix version: \ - prefix reg: \ - select * where {\ - ?register a reg:Register; version:currentVersion ?regVer.} limit 10"; +let query = "PREFIX rdfs: \ + PREFIX reg: \ + PREFIX version: \ + SELECT ?regdef ?label WHERE {\ + ?item reg:register ;\ + version:currentVersion/reg:definition/reg:entity ?regdef ;\ + version:currentVersion ?itemVer .\ + ?regdef rdfs:label ?label . } LIMIT 10"; let divResults = document.getElementById("results"); function sparqlQueryJson(queryStr, endpoint, callback) { // Build the request URI let requestUri = endpoint + "?query=" + escape(queryStr) + "&output=json"; - // Get our HTTP request object. + // Get our HTTP request object if (window.XMLHttpRequest) { let xhr = new XMLHttpRequest(); xhr.open('GET', requestUri, true); - // Set up callback to get the response asynchronously. + // Set up callback to get the response asynchronously xhr.onreadystatechange = function () { if (xhr.readyState === 4) { if (xhr.status === 200) { // Do something with the results callback(xhr.responseText); } else { - // Some kind of error occurred. + // Some kind of error occurred alert("Sparql query error: " + xhr.status + " " + xhr.responseText); } } }; - // Send the query to the endpoint. + // Send the query to the endpoint xhr.send(); } else { alert("Your browser does not support XMLHttpRequest"); } } -// Define a callback function to receive the SPARQL JSON result. +// Define a callback function to receive the SPARQL JSON result function myCallback(str) { // Convert result to JSON let jsonObj = eval('(' + str + ')'); - // Build up a table of results. + // Build up a table of results let table = document.createElement("table"); table.className = "table table-striped table-bordered datatable dataTable"; + // Create table head + let tableHead = document.createElement("thead"); + table.appendChild(tableHead); + // Create column headers - let tableHeader = document.createElement("tr"); + let tableHeadRow = document.createElement("tr"); for (let dataColumn of jsonObj.head.vars) { let th = document.createElement("th"); th.appendChild(document.createTextNode(dataColumn)); - tableHeader.appendChild(th); + tableHeadRow.appendChild(th); } - table.appendChild(tableHeader); + tableHead.appendChild(tableHeadRow); + + // Create table body + let tableBody = document.createElement("tbody"); + table.appendChild(tableBody); // Create result rows for (let dataRow of jsonObj.results.bindings) { @@ -68,7 +80,7 @@ function myCallback(str) { tableRow.appendChild(td); } - table.appendChild(tableRow); + tableBody.appendChild(tableRow); } // Append the table to the results HTML container @@ -76,5 +88,5 @@ function myCallback(str) { divResults.appendChild(table); } -// Make the query. -sparqlQueryJson(query, endpoint, myCallback); \ No newline at end of file +// Make the query +sparqlQueryJson(query, endpoint, myCallback); diff --git a/ldregistry/ui/css/ui.css b/ldregistry/ui/css/ui.css index 1b65f91..b3f911f 100644 --- a/ldregistry/ui/css/ui.css +++ b/ldregistry/ui/css/ui.css @@ -7,11 +7,11 @@ body { } .table { - margin-bottom: 0em; + margin-bottom: 0; } table tr td table { - margin-bottom: 0em; + margin-bottom: 0; } .space-above { @@ -73,8 +73,8 @@ footer { } .formats dl { - margin-bottom: 0px; - margin-top: 0px; + margin-bottom: 0; + margin-top: 0; } .formats table tr td { @@ -98,7 +98,7 @@ footer { } .nav-compact { - margin-bottom: 0px; + margin-bottom: 0; } #registration-dialog { @@ -182,4 +182,4 @@ td.align-right { .hlist-child-box { padding-left: 40px; -} \ No newline at end of file +} From 968bc6d686e8b7b510fb5264e548ed691ccf2e2e Mon Sep 17 00:00:00 2001 From: der Date: Thu, 9 Mar 2023 13:59:15 +0000 Subject: [PATCH 03/44] Fix XSS vuln in create-redirect-page --- ldregistry/templates/actions/_set-status-dialog.vm | 1 + ldregistry/templates/actions/create-redirect-page.vm | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ldregistry/templates/actions/_set-status-dialog.vm b/ldregistry/templates/actions/_set-status-dialog.vm index 9d627bf..50a336c 100644 --- a/ldregistry/templates/actions/_set-status-dialog.vm +++ b/ldregistry/templates/actions/_set-status-dialog.vm @@ -15,6 +15,7 @@ } $.ajax(action,{ type : "POST", + contentType : "application/x-www-form-urlencoded; charset=UTF-8", success : function(data, status, xhr){ $("#status-dialog").modal("hide"); diff --git a/ldregistry/templates/actions/create-redirect-page.vm b/ldregistry/templates/actions/create-redirect-page.vm index d596f1b..1d3bcf2 100644 --- a/ldregistry/templates/actions/create-redirect-page.vm +++ b/ldregistry/templates/actions/create-redirect-page.vm @@ -9,7 +9,7 @@