Skip to content

Commit 6d248c5

Browse files
authored
Promise cleanup (#241)
* `bs2:ExternalBar` templates * External navbar templates * External nav bar promise * Getting rid of `ldh:DocumentLoaded` named template * `bs2:MediaTypeList` link fixes * Removed `bs2:ExternalBar` Removed `Link rel=ldt:base` support from `ResponseHeadersFilter` * `bs2:MediaTypeList` URI fix * Restored Save As button * Removed external navbar's client-side * Document subject slug fixes * Removed `ldh:DocumentLoaded` named template Tunneling `$action` params
1 parent fdb08b5 commit 6d248c5

15 files changed

Lines changed: 287 additions & 233 deletions

File tree

src/main/java/com/atomgraph/linkeddatahub/server/filter/response/ResponseHeadersFilter.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.atomgraph.linkeddatahub.apps.model.Application;
2424
import com.atomgraph.linkeddatahub.apps.model.Dataset;
2525
import com.atomgraph.linkeddatahub.model.auth.Agent;
26+
import com.atomgraph.linkeddatahub.server.model.impl.Dispatcher;
2627
import com.atomgraph.linkeddatahub.server.security.AuthorizationContext;
2728
import com.atomgraph.linkeddatahub.vocabulary.ACL;
2829
import java.io.IOException;
@@ -77,27 +78,17 @@ public void filter(ContainerRequestContext request, ContainerResponseContext res
7778
List<Object> linkValues = response.getHeaders().get(HttpHeaders.LINK);
7879
List<Link> links = parseLinkHeaderValues(linkValues);
7980

80-
// check whether Link rel=ldt:base is not already set. Link headers might be forwarded by ProxyResourceBase
81-
if (getLinksByRel(links, LDT.base.getURI()).isEmpty())
82-
{
83-
// add Link rel=ldt:base
84-
response.getHeaders().add(HttpHeaders.LINK, new Link(getApplication().getBaseURI(), LDT.base.getURI(), null));
81+
if (getLinksByRel(links, SD.endpoint.getURI()).isEmpty())
8582
// add Link rel=sd:endpoint.
8683
// TO-DO: The external SPARQL endpoint URL is different from the internal one currently specified as sd:endpoint in the context dataset
87-
response.getHeaders().add(HttpHeaders.LINK, new Link(request.getUriInfo().getBaseUriBuilder().path("sparql").build(), SD.endpoint.getURI(), null));
88-
// add Link rel=ldt:ontology, if the ontology URI is specified
89-
if (getApplication().getOntology() != null)
90-
response.getHeaders().add(HttpHeaders.LINK, new Link(URI.create(getApplication().getOntology().getURI()), LDT.ontology.getURI(), null));
91-
// add Link rel=ac:stylesheet, if the stylesheet URI is specified
92-
if (getApplication().getStylesheet() != null)
93-
response.getHeaders().add(HttpHeaders.LINK, new Link(URI.create(getApplication().getStylesheet().getURI()), AC.stylesheet.getURI(), null));
94-
}
95-
else
96-
{
97-
// add Link rel=sd:endpoint.
98-
if (getLinksByRel(links, SD.endpoint.getURI()).isEmpty() && getDataset().isPresent() && getDataset().get().getService() != null)
99-
response.getHeaders().add(HttpHeaders.LINK, new Link(URI.create(getDataset().get().getService().getSPARQLEndpoint().getURI()), SD.endpoint.getURI(), null));
100-
}
84+
response.getHeaders().add(HttpHeaders.LINK, new Link(request.getUriInfo().getBaseUriBuilder().path(Dispatcher.class, "getSPARQLEndpoint").build(), SD.endpoint.getURI(), null));
85+
86+
// add Link rel=ldt:ontology, if the ontology URI is specified
87+
if (getApplication().getOntology() != null)
88+
response.getHeaders().add(HttpHeaders.LINK, new Link(URI.create(getApplication().getOntology().getURI()), LDT.ontology.getURI(), null));
89+
// add Link rel=ac:stylesheet, if the stylesheet URI is specified
90+
if (getApplication().getStylesheet() != null)
91+
response.getHeaders().add(HttpHeaders.LINK, new Link(URI.create(getApplication().getStylesheet().getURI()), AC.stylesheet.getURI(), null));
10192

10293
if (response.getHeaders().get(HttpHeaders.LINK) != null)
10394
{

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/admin/acl/imports/acl.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ exclude-result-prefixes="#all">
6464

6565
<xsl:template match="*[rdf:type/@rdf:resource = '&lacl;AuthorizationRequest']" priority="1">
6666
<xsl:param name="method" select="'post'" as="xs:string"/>
67-
<xsl:param name="action" select="ldh:href(resolve-uri(ac:uuid() || '/', resolve-uri('acl/authorizations/', $ldt:base)), map{ '_method': 'PUT' })" as="xs:anyURI"/> <!-- create new authorization document -->
67+
<xsl:param name="action" select="ldh:href(resolve-uri(ac:uuid() || '/', resolve-uri('acl/authorizations/', $ldt:base)), map{ '_method': 'PUT' })" as="xs:anyURI" tunnel="yes"/> <!-- create new authorization document -->
6868
<xsl:param name="id" select="concat('form-', generate-id())" as="xs:string?"/>
6969
<xsl:param name="class" select="'form-horizontal'" as="xs:string?"/>
7070
<xsl:param name="accept-charset" select="'UTF-8'" as="xs:string?"/>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ exclude-result-prefixes="#all">
103103
<xsl:param name="id" select="concat('form-', generate-id())" as="xs:string?"/>
104104
<xsl:param name="class" select="'row-fluid'" as="xs:string?"/>
105105
<xsl:param name="method" select="'patch'" as="xs:string"/>
106-
<xsl:param name="action" select="ldh:href(ac:build-uri(ac:absolute-path(ldh:base-uri(.)), map{ '_method': 'PUT' }))" as="xs:anyURI"/>
106+
<xsl:param name="action" select="ldh:href(ac:build-uri(ac:absolute-path(ldh:base-uri(.)), map{ '_method': 'PUT' }))" as="xs:anyURI" tunnel="yes"/>
107107
<xsl:param name="enctype" select="'multipart/form-data'" as="xs:string?"/>
108108
<xsl:param name="create-resource" select="true()" as="xs:boolean"/>
109109
<!-- TO-DO: generate ontology classes from the OWL vocabulary -->
@@ -114,7 +114,7 @@ exclude-result-prefixes="#all">
114114
<xsl:with-param name="id" select="$id"/>
115115
<xsl:with-param name="class" select="$class"/>
116116
<xsl:with-param name="method" select="$method"/>
117-
<xsl:with-param name="action" select="$action"/>
117+
<xsl:with-param name="action" select="$action" tunnel="yes"/>
118118
<xsl:with-param name="enctype" select="$enctype"/>
119119
<xsl:with-param name="create-resource" select="$create-resource"/>
120120
<xsl:with-param name="classes" select="$classes"/>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ exclude-result-prefixes="#all">
7171
<xsl:apply-templates select="ldh:construct(map{ xs:anyURI('&foaf;Person'): $constructors//srx:result[srx:binding[@name = 'Type'] = '&foaf;Person']/srx:binding[@name = 'construct']/srx:literal/string() })" mode="bs2:RowForm">
7272
<xsl:with-param name="id" select="'form-signup'"/>
7373
<xsl:with-param name="method" select="'post'"/> <!-- don't use PATCH which is the default -->
74-
<xsl:with-param name="action" select="ac:absolute-path(base-uri($main-doc))"/>
74+
<xsl:with-param name="action" select="ac:absolute-path(base-uri($main-doc))" tunnel="yes"/>
7575
<xsl:with-param name="enctype" select="()"/> <!-- don't use 'multipart/form-data' which is the default -->
7676
<xsl:with-param name="create-resource" select="false()"/>
7777
<xsl:with-param name="base-uri" select="ac:absolute-path(base-uri($main-doc))" tunnel="yes"/> <!-- base-uri() is empty on constructed documents -->

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ exclude-result-prefixes="#all"
658658
<xsl:apply-templates select="$constructed-doc" mode="bs2:RowForm">
659659
<xsl:with-param name="about" select="()"/> <!-- don't set @about on the container until after the resource is saved -->
660660
<xsl:with-param name="method" select="$method"/>
661-
<xsl:with-param name="action" select="ldh:href($doc-uri, map{})" as="xs:anyURI"/>
661+
<xsl:with-param name="action" select="ldh:href($doc-uri, map{})" as="xs:anyURI" tunnel="yes"/>
662662
<xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>
663663
<xsl:with-param name="property-metadata" select="$property-metadata" tunnel="yes"/>
664664
<xsl:with-param name="constructor" select="$constructed-doc" tunnel="yes"/>

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ exclude-result-prefixes="#all"
107107

108108
<xsl:template match="*[@typeof = ('&sp;Ask', '&sp;Select', '&sp;Describe', '&sp;Construct')][descendant::*[@property = '&sp;text'][pre/text()]]" mode="ldh:RenderRow" as="function(item()?) as map(*)" priority="2 "> <!-- prioritize above block.xsl -->
109109
<xsl:param name="block" select="ancestor-or-self::div[contains-token(@class, 'block')][1]" as="element()"/>
110-
<xsl:param name="about" select="$block/@about" as="xs:anyURI"/>
111-
<xsl:param name="block-uri" select="$about" as="xs:anyURI"/>
112110
<xsl:param name="container" select="." as="element()"/>
113111
<xsl:param name="graph" select="descendant::*[@property = '&ldh;graph']/@resource" as="xs:anyURI?"/>
114112
<xsl:param name="mode" select="descendant::*[@property = '&ac;mode']/@resource" as="xs:anyURI?"/>
@@ -513,7 +511,7 @@ exclude-result-prefixes="#all"
513511

514512
<ixsl:set-style name="cursor" select="'progress'" object="ixsl:page()//body"/>
515513

516-
<!-- abort the previous request, if any -->
514+
<!-- abort the previous request, if any
517515
<xsl:if test="ixsl:contains(ixsl:get(ixsl:window(), 'LinkedDataHub'), 'request')">
518516
<xsl:message>Aborting HTTP request that has already been sent</xsl:message>
519517
<xsl:sequence select="ixsl:call(ixsl:get(ixsl:window(), 'LinkedDataHub.request'), 'abort', [])"/>
@@ -527,8 +525,22 @@ exclude-result-prefixes="#all"
527525
</ixsl:schedule-action>
528526
</xsl:variable>
529527
530-
<!-- store the new request object -->
531-
<ixsl:set-property name="request" select="$request" object="ixsl:get(ixsl:window(), 'LinkedDataHub')"/>
528+
store the new request object
529+
<ixsl:set-property name="request" select="$request" object="ixsl:get(ixsl:window(), 'LinkedDataHub')"/>-->
530+
531+
<xsl:variable name="request" select="map{ 'method': 'GET', 'href': $href, 'headers': map{ 'Accept': 'application/xhtml+xml' } }" as="map(*)"/>
532+
<xsl:variable name="context" select="
533+
map{
534+
'request': $request,
535+
'href': $href,
536+
'push-state': true()
537+
}" as="map(*)"/>
538+
<ixsl:promise select="
539+
ixsl:http-request($context('request'))
540+
=> ixsl:then(ldh:rethread-response($context, ?))
541+
=> ixsl:then(ldh:handle-response#1)
542+
=> ixsl:then(ldh:xhtml-document-loaded#1)
543+
" on-failure="ldh:promise-failure#1"/>
532544
</xsl:otherwise>
533545
</xsl:choose>
534546
</xsl:template>

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

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ WHERE
262262
<xsl:template match="div[@about]//button[contains-token(@class, 'btn-edit')][not(contains-token(@class, 'disabled'))]" mode="ixsl:onclick">
263263
<xsl:param name="block" select="ancestor::div[contains-token(@class, 'block')][1]" as="element()"/>
264264
<xsl:param name="about" select="$block/@about" as="xs:anyURI"/>
265-
<!-- <xsl:param name="graph" as="xs:anyURI?"/>-->
266265

267266
<xsl:sequence select="ixsl:call(ixsl:event(), 'preventDefault', [])"/>
268267
<ixsl:set-style name="cursor" select="'progress'" object="ixsl:page()//body"/>
@@ -328,7 +327,7 @@ WHERE
328327
<xsl:variable name="block" select="id($block-id, ixsl:page())" as="element()"/>
329328

330329
<!-- if the URI is external, dereference it through the proxy -->
331-
<xsl:variable name="request-uri" select="ldh:href(ac:absolute-path(ldh:base-uri(.)), map{})" as="xs:anyURI"/>
330+
<xsl:variable name="request-uri" select="ldh:href($about)" as="xs:anyURI"/>
332331
<xsl:variable name="request" select="map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/rdf+xml' } }" as="map(*)"/>
333332
<xsl:variable name="context" as="map(*)" select="
334333
map{
@@ -519,7 +518,7 @@ WHERE
519518
<xsl:apply-templates select="$document" mode="bs2:Form"> <!-- document level template -->
520519
<xsl:with-param name="about" select="()"/> <!-- don't set @about on the container until after the resource is saved -->
521520
<xsl:with-param name="method" select="$method"/>
522-
<xsl:with-param name="action" select="$action"/>
521+
<xsl:with-param name="action" select="$action" tunnel="yes"/>
523522
<xsl:with-param name="form-actions-class" select="'form-actions modal-footer'"/>
524523
<xsl:with-param name="classes" select="()"/>
525524
<xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>
@@ -980,31 +979,6 @@ WHERE
980979
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
981980
</xsl:for-each>
982981
</xsl:function>
983-
984-
<xsl:function name="ldh:modal-form-submit-success" ixsl:updating="yes">
985-
<xsl:param name="context" as="map(*)"/>
986-
<xsl:variable name="response" select="$context('response')" as="map(*)"/>
987-
988-
<xsl:message>ldh:modal-form-submit-success</xsl:message>
989-
990-
<xsl:for-each select="$response">
991-
<xsl:variable name="href" select="ac:absolute-path(xs:anyURI(ixsl:location()))" as="xs:anyURI"/> <!-- TO-DO: pass $context?base-uri -->
992-
<xsl:variable name="request" select="map{ 'method': 'GET', 'href': $href, 'headers': map{ 'Accept': 'application/xhtml+xml' } }" as="map(*)"/>
993-
<xsl:variable name="context" select="map:merge((
994-
$context,
995-
map{
996-
'request': $request,
997-
'href': $href
998-
}
999-
), map{ 'duplicates': 'use-last' })" as="map(*)"/>
1000-
<ixsl:promise select="
1001-
ixsl:http-request($context('request'))
1002-
=> ixsl:then(ldh:rethread-response($context, ?))
1003-
=> ixsl:then(ldh:handle-response#1)
1004-
=> ixsl:then(ldh:xhtml-document-loaded#1)
1005-
" on-failure="ldh:promise-failure#1"/>
1006-
</xsl:for-each>
1007-
</xsl:function>
1008982

1009983
<xsl:function name="ldh:form-submit-created" ixsl:updating="yes">
1010984
<xsl:param name="context" as="map(*)"/>
@@ -1018,7 +992,8 @@ WHERE
1018992
<xsl:variable name="context" as="map(*)" select="
1019993
map{
1020994
'request': $request,
1021-
'href': $href
995+
'href': $href,
996+
'push-state': true()
1022997
}"/>
1023998
<ixsl:promise select="
1024999
ixsl:http-request($context('request'))
@@ -1074,7 +1049,7 @@ WHERE
10741049
<xsl:apply-templates select="." mode="bs2:Form"> <!-- document level template -->
10751050
<xsl:with-param name="about" select="()"/> <!-- don't set @about on the container until after the resource is saved -->
10761051
<xsl:with-param name="method" select="$form/@method"/>
1077-
<xsl:with-param name="action" select="$form/@action" as="xs:anyURI"/>
1052+
<xsl:with-param name="action" select="$form/@action" as="xs:anyURI" tunnel="yes"/>
10781053
<xsl:with-param name="form-actions-class" select="'form-actions modal-footer'" as="xs:string?"/>
10791054
<xsl:with-param name="classes" select="()"/>
10801055
<xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>
@@ -1223,15 +1198,6 @@ WHERE
12231198
<xsl:variable name="constructed-doc" select="ldh:construct-forClass($forClass)" as="document-node()"/>
12241199
<xsl:variable name="doc-uri" select="resolve-uri(ac:uuid() || '/', ac:absolute-path(ldh:base-uri(.)))" as="xs:anyURI"/> <!-- build a relative URI for the child document -->
12251200
<xsl:variable name="this" select="$doc-uri" as="xs:anyURI"/>
1226-
<!-- set document URI instead of blank node -->
1227-
<xsl:variable name="constructed-doc" as="document-node()">
1228-
<xsl:document>
1229-
<xsl:apply-templates select="$constructed-doc" mode="ldh:SetResourceID">
1230-
<xsl:with-param name="forClass" select="$forClass" tunnel="yes"/>
1231-
<xsl:with-param name="about" select="$this" tunnel="yes"/>
1232-
</xsl:apply-templates>
1233-
</xsl:document>
1234-
</xsl:variable>
12351201
<xsl:variable name="classes" select="()" as="element()*"/>
12361202

12371203
<xsl:for-each select="$content-body">
@@ -1255,7 +1221,7 @@ WHERE
12551221
<xsl:apply-templates select="$constructed-doc" mode="bs2:Form"> <!-- document level template -->
12561222
<xsl:with-param name="about" select="()"/> <!-- don't set @about on the container until after the resource is saved -->
12571223
<xsl:with-param name="method" select="'put'"/>
1258-
<xsl:with-param name="action" select="ldh:href($doc-uri, map{})" as="xs:anyURI"/>
1224+
<xsl:with-param name="action" select="ldh:href($doc-uri)" as="xs:anyURI" tunnel="yes"/>
12591225
<xsl:with-param name="form-actions-class" select="'form-actions modal-footer'" as="xs:string?"/>
12601226
<xsl:with-param name="classes" select="$classes"/>
12611227
<xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>
@@ -1351,7 +1317,7 @@ WHERE
13511317
<xsl:apply-templates select="$constructed-doc" mode="bs2:RowForm">
13521318
<xsl:with-param name="about" select="()"/> <!-- don't set @about on the container until after the resource is saved -->
13531319
<xsl:with-param name="method" select="$method"/>
1354-
<xsl:with-param name="action" select="ldh:href($doc-uri, map{})" as="xs:anyURI"/>
1320+
<xsl:with-param name="action" select="ldh:href($doc-uri)" as="xs:anyURI" tunnel="yes"/>
13551321
<xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>
13561322
<xsl:with-param name="property-metadata" select="$property-metadata" tunnel="yes"/>
13571323
<xsl:with-param name="constructor" select="$constructed-doc" tunnel="yes"/>
@@ -1612,7 +1578,7 @@ WHERE
16121578

16131579
<xsl:apply-templates select="$resource" mode="bs2:Form">
16141580
<xsl:with-param name="method" select="'post'"/>
1615-
<xsl:with-param name="action" select="ldh:href($doc-uri, map{})" as="xs:anyURI"/>
1581+
<xsl:with-param name="action" select="ldh:href($doc-uri)" as="xs:anyURI" tunnel="yes"/>
16161582
<xsl:with-param name="classes" select="$classes"/>
16171583
<xsl:with-param name="type-metadata" select="$type-metadata" tunnel="yes"/>
16181584
<xsl:with-param name="property-metadata" select="$property-metadata" tunnel="yes"/>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ exclude-result-prefixes="#all"
5353
</xsl:choose>
5454
</xsl:function>
5555

56+
<xsl:function name="ldh:origin" as="xs:anyURI">
57+
<xsl:param name="uri" as="xs:anyURI"/>
58+
59+
<!-- no trailing slash -->
60+
<xsl:sequence select="xs:anyURI(replace($uri, '^(https?://[^/]+).*$', '$1'))"/>
61+
</xsl:function>
62+
5663
<xsl:function name="ldt:base" as="xs:anyURI">
57-
<xsl:sequence select="xs:anyURI(ixsl:get(ixsl:window(), 'LinkedDataHub.base'))"/>
64+
<xsl:sequence select="xs:anyURI(ldh:origin(xs:anyURI(ixsl:location())) || '/')"/>
5865
</xsl:function>
5966

6067
<xsl:function name="acl:mode" as="xs:anyURI*">

0 commit comments

Comments
 (0)