Skip to content

Commit 8c9a491

Browse files
committed
Fixed URIResource check
Fixed `ValidatingModelProvider::mboxHashStmt` not to hash when the mbox value is not a URI Make `$object-metadata` optional Fix exclusion of `spin:ConstraintViolation` bnode resources Filter out `spin:ConstraintViolation`s in `$resource` expression Defined `$types` Pass `$property-metadata` etc. to `bs2:RowForm` Moved `ldh:PostConstruct` call into `$block` context Restor `$enctype` expression Pass `$method` to `bs2:RowForm` Added SPIN vocab to client-side location mapping Restore `@use-when` Enabled `bs2:RowForm` overrides for the client-side Fix `$row-form` type again Fixed `$row-form` type Fixed element name Re-render the whole form after 422 response by applying the `bs2:RowForm` mode
1 parent 8e1e114 commit 8c9a491

File tree

6 files changed

+63
-66
lines changed

6 files changed

+63
-66
lines changed

src/main/java/com/atomgraph/linkeddatahub/server/io/ValidatingModelProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ public static Function<Model, Model> hashMboxes(MessageDigest messageDigest)
301301
*/
302302
public static Statement mboxHashStmt(Statement stmt, MessageDigest messageDigest)
303303
{
304+
if (!stmt.getObject().isURIResource()) return stmt; // don't hash if the mbox value is not a URI
305+
304306
try (InputStream is = new ByteArrayInputStream(stmt.getResource().getURI().getBytes(StandardCharsets.UTF_8));
305307
DigestInputStream dis = new DigestInputStream(is, messageDigest))
306308
{

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/form.xsl

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ WHERE
380380
<xsl:variable name="object-uris" select="distinct-values($resource/*/@rdf:resource[not(key('resources', .))])" as="xs:string*"/>
381381
<xsl:variable name="query-string" select="$object-metadata-query || ' VALUES $this { ' || string-join(for $uri in $object-uris return '&lt;' || $uri || '&gt;', ' ') || ' }'" as="xs:string"/>
382382
<xsl:variable name="request-uri" select="ac:build-uri(resolve-uri('sparql', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as="xs:anyURI"/>
383-
<xsl:variable name="object-metadata" select="document($request-uri)" as="document-node()"/>
383+
<xsl:variable name="object-metadata" select="if (doc-available($request-uri)) then document($request-uri) else ()" as="document-node()?"/>
384384
<xsl:message>
385385
$object-uris: <xsl:value-of select="$object-uris"/>
386386
$object-metadata: <xsl:value-of select="serialize($object-metadata)"/>
@@ -587,7 +587,6 @@ WHERE
587587
<xsl:variable name="id" select="ixsl:get($form, 'id')" as="xs:string"/>
588588
<xsl:variable name="action" select="ixsl:get($form, 'action')" as="xs:anyURI"/>
589589
<xsl:variable name="enctype" select="ixsl:get($form, 'enctype')" as="xs:string"/>
590-
<!-- <xsl:variable name="accept" select="'application/xhtml+xml'" as="xs:string"/>-->
591590
<xsl:variable name="about" select="$block/@about" as="xs:anyURI"/>
592591
<xsl:message>ldh:base-uri(.): <xsl:value-of select="ldh:base-uri(.)"/></xsl:message>
593592
<xsl:variable name="etag" select="ixsl:get(ixsl:get(ixsl:get(ixsl:window(), 'LinkedDataHub.contents'), '`' || ac:absolute-path(ldh:base-uri(.)) || '`'), 'etag')" as="xs:string"/>
@@ -770,56 +769,60 @@ WHERE
770769
</xsl:when>
771770
<!-- POST or PUT constraint violation response is 422 Unprocessable Entity, bad RDF syntax is 400 Bad Request -->
772771
<xsl:when test="?status = (400, 422) and starts-with(?media-type, 'application/rdf+xml')"> <!-- allow 'application/rdf+xml;charset=UTF-8' as well -->
772+
<xsl:variable name="forClass" select="$container/@typeof" as="xs:anyURI"/>
773+
<xsl:variable name="resource" select="key('resources-by-type', $forClass, ?body)[not(key('predicates-by-object', @rdf:nodeID)[not(../rdf:type/@rdf:resource = '&spin;ConstraintViolation')])]" as="element()"/>
774+
<!-- TO-DO: refactor to use asynchronous HTTP requests -->
775+
<xsl:variable name="types" select="distinct-values($resource/rdf:type/@rdf:resource)" as="xs:anyURI*"/>
776+
<xsl:variable name="property-uris" select="distinct-values($resource/*/concat(namespace-uri(), local-name()))" as="xs:string*"/>
777+
<xsl:variable name="query-string" select="'DESCRIBE $Type VALUES $Type { ' || string-join(for $uri in $property-uris return '&lt;' || $uri || '&gt;', ' ') || ' }'" as="xs:string"/>
778+
<xsl:variable name="request-uri" select="ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as="xs:anyURI"/>
779+
<xsl:variable name="property-metadata" select="document($request-uri)" as="document-node()"/>
780+
781+
<xsl:variable name="query-string" select="$constructor-query || ' VALUES $Type { ' || string-join(for $type in $types return '&lt;' || $type || '&gt;', ' ') || ' }'" as="xs:string"/>
782+
<xsl:variable name="request-uri" select="ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/sparql-results+xml' })" as="xs:anyURI"/>
783+
<xsl:variable name="constructors" select="if (exists($types)) then document($request-uri) else ()" as="document-node()?"/>
784+
785+
<xsl:message>
786+
ConstraintViolation $constructors: <xsl:value-of select="serialize($constructors)"/>
787+
</xsl:message>
788+
789+
<xsl:variable name="query-string" select="$constraint-query || ' VALUES $Type { ' || string-join(for $type in $types return '&lt;' || $type || '&gt;', ' ') || ' }'" as="xs:string"/>
790+
<xsl:variable name="request-uri" select="ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/sparql-results+xml' })" as="xs:anyURI"/>
791+
<xsl:variable name="constraints" select="if (exists($types)) then document($request-uri) else ()" as="document-node()?"/>
773792

774-
<xsl:variable name="body" select="?body" as="document-node()"/>
775-
<!-- iterate each form fieldset as resource -->
776-
<xsl:for-each select="$form/fieldset">
777-
<!-- guard against multiple subject URI/bnode values as there can be nested fieldsets -->
778-
<xsl:variable name="resource-uri" select="(.//input[@name = 'su'])[1]/ixsl:get(., 'value')" as="xs:anyURI?"/>
779-
<xsl:variable name="resource-bnode" select="(.//input[@name = 'sb'])[1]/ixsl:get(., 'value')" as="xs:string?"/>
780-
<xsl:message>
781-
$resource-uri: <xsl:value-of select="$resource-uri"/>
782-
$resource-bnode: <xsl:value-of select="$resource-bnode"/>
783-
</xsl:message>
784-
<!-- select violations specific to this resource -->
785-
<!-- TO-DO: key('violations-by-value', $resources//*/@rdf:resource, ?body) -->
786-
<xsl:variable name="violations" select="key('violations-by-root', ($resource-uri, $resource-bnode), $body) | key('violations-by-focus-node', ($resource-uri, $resource-bnode), $body)" as="element()*"/>
787-
<xsl:message>$violations: <xsl:value-of select="serialize($violations)"/></xsl:message>
788-
789-
<!-- iterate control groups as properties -->
790-
<xsl:for-each select="./div[contains-token(@class, 'control-group')][input[@name = 'pu']]">
791-
<xsl:variable name="predicate" select="input[@name = 'pu']/ixsl:get(., 'value')" as="xs:anyURI"/>
792-
793-
<xsl:choose>
794-
<!-- if there are SPIN or SHACL violations specific to the predicate of this control group, set error class on the group -->
795-
<!-- TO-DO: @rdf:resource = $violations/ldh:violationValue -->
796-
<xsl:when test="$violations[spin:violationPath/@rdf:resource = $predicate or sh:resultPath/@rdf:resource = $predicate]">
797-
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'error', true() ])[current-date() lt xs:date('2000-01-01')]"/>
798-
</xsl:when>
799-
<!-- otherwise, remove the error class -->
800-
<xsl:otherwise>
801-
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'error', false() ])[current-date() lt xs:date('2000-01-01')]"/>
802-
</xsl:otherwise>
803-
</xsl:choose>
804-
</xsl:for-each>
805-
806-
<xsl:for-each select="./div[contains-token(@class, 'violations')]">
807-
<xsl:choose>
808-
<!-- render violations if they exist for this resource -->
809-
<xsl:when test="exists($violations)">
810-
<xsl:result-document href="?." method="ixsl:replace-content">
811-
<xsl:apply-templates select="$violations" mode="bs2:Violation"/>
812-
</xsl:result-document>
813-
<ixsl:set-style name="display" select="'block'"/>
814-
</xsl:when>
815-
<!-- hide any previous violations if this resource now has none -->
816-
<xsl:otherwise>
817-
<ixsl:set-style name="display" select="'none'"/>
818-
</xsl:otherwise>
819-
</xsl:choose>
820-
</xsl:for-each>
821-
</xsl:for-each>
793+
<xsl:variable name="query-string" select="$shape-query || ' VALUES $Type { ' || string-join(for $type in $types return '&lt;' || $type || '&gt;', ' ') || ' }'" as="xs:string"/>
794+
<xsl:variable name="request-uri" select="ac:build-uri(resolve-uri('ns', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as="xs:anyURI"/>
795+
<xsl:variable name="shapes" select="document($request-uri)" as="document-node()"/>
796+
797+
<xsl:variable name="object-uris" select="distinct-values($resource/*/@rdf:resource[not(key('resources', .))])" as="xs:string*"/>
798+
<xsl:variable name="query-string" select="$object-metadata-query || ' VALUES $this { ' || string-join(for $uri in $object-uris return '&lt;' || $uri || '&gt;', ' ') || ' }'" as="xs:string"/>
799+
<xsl:variable name="request-uri" select="ac:build-uri(resolve-uri('sparql', $ldt:base), map{ 'query': $query-string, 'accept': 'application/rdf+xml' })" as="xs:anyURI"/>
800+
<xsl:variable name="object-metadata" select="if (doc-available($request-uri)) then document($request-uri) else ()" as="document-node()?"/>
801+
<xsl:message>
802+
$object-uris: <xsl:value-of select="$object-uris"/>
803+
$object-metadata: <xsl:value-of select="serialize($object-metadata)"/>
804+
</xsl:message>
805+
806+
<xsl:variable name="row-form" as="node()*">
807+
<xsl:apply-templates select="$resource" mode="bs2:RowForm">
808+
<xsl:with-param name="method" select="$form/@method"/>
809+
<!-- <xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>-->
810+
<xsl:with-param name="property-metadata" select="$property-metadata" tunnel="yes"/>
811+
<xsl:with-param name="constructors" select="$constructors" tunnel="yes"/>
812+
<xsl:with-param name="constraints" select="$constraints" tunnel="yes"/>
813+
<xsl:with-param name="shapes" select="$shapes" tunnel="yes"/>
814+
<xsl:with-param name="object-metadata" select="$object-metadata" tunnel="yes"/>
815+
</xsl:apply-templates>
816+
</xsl:variable>
822817

818+
<xsl:for-each select="$block">
819+
<xsl:result-document href="?." method="ixsl:replace-content">
820+
<xsl:copy-of select="$row-form/*"/>
821+
</xsl:result-document>
822+
823+
<xsl:apply-templates select="." mode="ldh:PostConstruct"/>
824+
</xsl:for-each>
825+
823826
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
824827
</xsl:when>
825828
<!-- error response -->

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/document.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ extension-element-prefixes="ixsl"
207207
</xsl:if>
208208
</xsl:template>
209209

210-
<!-- BLOCK -->
210+
<!-- ROW -->
211211

212212
<xsl:template match="rdf:RDF" mode="bs2:Row">
213213
<xsl:param name="create-resource" select="true()" as="xs:boolean"/>

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/layout.xsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ exclude-result-prefixes="#all">
124124
<xsl:map-entry key="resolve-uri(ac:document-uri(xs:anyURI('&def;')), $ac:contextUri)" select="ac:build-uri($ldt:base, map{ 'uri': string(ac:document-uri(xs:anyURI('&def;'))), 'accept': 'application/rdf+xml' })"/>
125125
<xsl:map-entry key="resolve-uri(ac:document-uri(xs:anyURI('&dh;')), $ac:contextUri)" select="ac:build-uri($ldt:base, map{ 'uri': string(ac:document-uri(xs:anyURI('&dh;'))), 'accept': 'application/rdf+xml' })"/>
126126
<xsl:map-entry key="resolve-uri(ac:document-uri(xs:anyURI('&sp;')), $ac:contextUri)" select="ac:build-uri($ldt:base, map{ 'uri': string(ac:document-uri(xs:anyURI('&sp;'))), 'accept': 'application/rdf+xml' })"/>
127+
<xsl:map-entry key="resolve-uri(ac:document-uri(xs:anyURI('&spin;')), $ac:contextUri)" select="ac:build-uri($ldt:base, map{ 'uri': string(ac:document-uri(xs:anyURI('&spin;'))), 'accept': 'application/rdf+xml' })"/>
127128
<xsl:map-entry key="resolve-uri(ac:document-uri(xs:anyURI('&rdf;')), $ac:contextUri)" select="ac:build-uri($ldt:base, map{ 'uri': string(ac:document-uri(xs:anyURI('&rdf;'))), 'accept': 'application/rdf+xml' })"/>
128129
<xsl:map-entry key="resolve-uri(ac:document-uri(xs:anyURI('&rdfs;')), $ac:contextUri)" select="ac:build-uri($ldt:base, map{ 'uri': string(ac:document-uri(xs:anyURI('&rdfs;'))), 'accept': 'application/rdf+xml' })"/>
129130
<xsl:map-entry key="resolve-uri(ac:document-uri(xs:anyURI('&owl;')), $ac:contextUri)" select="ac:build-uri($ldt:base, map{ 'uri': string(ac:document-uri(xs:anyURI('&owl;'))), 'accept': 'application/rdf+xml' })"/>

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/resource.xsl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,6 @@ extension-element-prefixes="ixsl"
930930
<xsl:param name="id" select="concat('constructor-', generate-id())" as="xs:string?"/>
931931
<xsl:param name="with-label" select="false()" as="xs:boolean"/>
932932
<xsl:param name="base-uri" select="ac:absolute-path(ldh:base-uri(.))" as="xs:anyURI" tunnel="yes"/>
933-
<!-- <xsl:variable name="forShape" select="@rdf:about" as="xs:anyURI"/>-->
934933

935934
<button title="{@rdf:about}" data-for-shape="{@rdf:about}">
936935
<xsl:if test="$id">
@@ -1059,11 +1058,10 @@ extension-element-prefixes="ixsl"
10591058
<!-- ROW FORM -->
10601059

10611060
<!-- hide constraint violations and HTTP responses in the form - they are displayed as errors on the edited resources -->
1062-
<xsl:template match="*[rdf:type/@rdf:resource = ('&spin;ConstraintViolation', '&sh;ValidationResult', '&sh;ValidationReport', '&http;Response')]" mode="bs2:RowForm" priority="3" use-when="system-property('xsl:product-name') = 'SAXON'"/>
1061+
<xsl:template match="*[rdf:type/@rdf:resource = ('&spin;ConstraintViolation', '&sh;ValidationResult', '&sh;ValidationReport', '&http;Response')]" mode="bs2:RowForm" priority="3"/>
10631062

10641063
<!-- hide object blank nodes that only have a single rdf:type property from constructed models, unless the type is owl:NamedIndividual -->
10651064
<xsl:template match="*[@rdf:nodeID][$ac:method = 'GET'][key('predicates-by-object', @rdf:nodeID)][not(* except rdf:type or rdf:type/@rdf:resource = '&owl;NamedIndividual')]" mode="bs2:RowForm" priority="2" use-when="system-property('xsl:product-name') = 'SAXON'"/>
1066-
10671065
<!-- hide object blank nodes that only have a single rdf:type property from constructed models, unless the type is owl:NamedIndividual -->
10681066
<xsl:template match="*[@rdf:nodeID][key('predicates-by-object', @rdf:nodeID)][not(* except rdf:type or rdf:type/@rdf:resource = '&owl;NamedIndividual')]" mode="bs2:RowForm" priority="2" use-when="system-property('xsl:product-name') eq 'SaxonJS'"/>
10691067

@@ -1451,7 +1449,7 @@ extension-element-prefixes="ixsl"
14511449

14521450
<!-- VIOLATION -->
14531451

1454-
<xsl:template match="*[rdf:type/@rdf:resource = '&ldh;URISyntaxViolation']" mode="bs2:Violation" use-when="system-property('xsl:product-name') = 'SAXON'">
1452+
<xsl:template match="*[rdf:type/@rdf:resource = '&ldh;URISyntaxViolation']" mode="bs2:Violation">
14551453
<xsl:param name="class" select="'alert alert-error'" as="xs:string?"/>
14561454

14571455
<div>
@@ -1468,7 +1466,7 @@ extension-element-prefixes="ixsl"
14681466
</xsl:template>
14691467

14701468
<!-- take constraint labels from sitemap instead of response, if possible -->
1471-
<xsl:template match="*[rdf:type/@rdf:resource = '&spin;ConstraintViolation']" mode="bs2:Violation" use-when="system-property('xsl:product-name') = 'SAXON'">
1469+
<xsl:template match="*[rdf:type/@rdf:resource = '&spin;ConstraintViolation']" mode="bs2:Violation">
14721470
<xsl:param name="class" select="'alert alert-error'" as="xs:string?"/>
14731471

14741472
<div>
@@ -1486,7 +1484,7 @@ extension-element-prefixes="ixsl"
14861484
</div>
14871485
</xsl:template>
14881486

1489-
<xsl:template match="*[rdf:type/@rdf:resource = '&sh;ValidationResult']" mode="bs2:Violation" use-when="system-property('xsl:product-name') = 'SAXON'">
1487+
<xsl:template match="*[rdf:type/@rdf:resource = '&sh;ValidationResult']" mode="bs2:Violation">
14901488
<xsl:param name="class" select="'alert alert-error'" as="xs:string?"/>
14911489

14921490
<div>
@@ -1504,11 +1502,11 @@ extension-element-prefixes="ixsl"
15041502

15051503
<!-- EXCEPTION -->
15061504

1507-
<xsl:template match="*[*][@rdf:about] | *[*][@rdf:nodeID]" mode="bs2:Exception" use-when="system-property('xsl:product-name') = 'SAXON'"/>
1505+
<xsl:template match="*[*][@rdf:about] | *[*][@rdf:nodeID]" mode="bs2:Exception"/>
15081506

15091507
<!-- OBJECT -->
15101508

1511-
<xsl:template match="*[*][@rdf:about or @rdf:nodeID]" mode="bs2:Object" use-when="system-property('xsl:product-name') = 'SAXON'"/>
1509+
<xsl:template match="*[*][@rdf:about or @rdf:nodeID]" mode="bs2:Object"/>
15121510

15131511
<!-- ### SHARED BETWEEN SERVER AND CLIENT -->
15141512

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/client.xsl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,6 @@ WHERE
458458
</a>
459459
</xsl:template>
460460

461-
<!-- if document has a topic, show it as the typeahead value instead -->
462-
<!--
463-
<xsl:template match="*[*][key('resources', foaf:primaryTopic/@rdf:resource)]" mode="ldh:Typeahead">
464-
<xsl:apply-templates select="key('resources', foaf:primaryTopic/@rdf:resource)" mode="#current"/>
465-
</xsl:template>
466-
-->
467-
468461
<!-- classes for system container breadcrumbs -->
469462

470463
<xsl:template match="*[@rdf:about = map:keys($system-containers)]" mode="bs2:BreadCrumbListItem" priority="1">

0 commit comments

Comments
 (0)