Skip to content

Commit

Permalink
Changed offset/limit order in UriBuilders
Browse files Browse the repository at this point in the history
Improved checks in gc:query-string()
gc:PaginationMode?
  • Loading branch information
Martynas committed Mar 18, 2014
1 parent 0a509ac commit 40e2eb9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
16 changes: 8 additions & 8 deletions src/main/java/org/graphity/processor/model/ResourceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ public RDFNode getRestrictionHasValue(OntClass ontClass, Property property)
public UriBuilder getPageUriBuilder()
{
UriBuilder uriBuilder = getUriBuilder().
queryParam("limit", getLimit()).
queryParam("offset", getOffset());
queryParam("offset", getOffset()).
queryParam("limit", getLimit());
if (getOrderBy() != null) uriBuilder.queryParam("order-by", getOrderBy());
if (getDesc()) uriBuilder.queryParam("desc", getDesc());

Expand All @@ -889,9 +889,9 @@ public UriBuilder getPageUriBuilder()
public UriBuilder getPreviousUriBuilder()
{
UriBuilder uriBuilder = getUriBuilder().
queryParam("limit", getLimit()).
queryParam("offset", getOffset() - getLimit());
if (getOrderBy() != null) uriBuilder.queryParam("order-by", getOrderBy());
queryParam("offset", getOffset() - getLimit()).
queryParam("limit", getLimit());
if (getOrderBy() != null) uriBuilder.queryParam("order-by", getOrderBy());
if (getDesc()) uriBuilder.queryParam("desc", getDesc());

return uriBuilder;
Expand All @@ -905,9 +905,9 @@ public UriBuilder getPreviousUriBuilder()
public UriBuilder getNextUriBuilder()
{
UriBuilder uriBuilder = getUriBuilder().
queryParam("limit", getLimit()).
queryParam("offset", getOffset() + getLimit());
if (getOrderBy() != null) uriBuilder.queryParam("order-by", getOrderBy());
queryParam("offset", getOffset() + getLimit()).
queryParam("limit", getLimit());
if (getOrderBy() != null) uriBuilder.queryParam("order-by", getOrderBy());
if (getDesc()) uriBuilder.queryParam("desc", getDesc());

return uriBuilder;
Expand Down
18 changes: 9 additions & 9 deletions src/main/webapp/static/org/graphity/client/xsl/functions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ exclude-result-prefixes="#all">
<xsl:param name="mode" as="xs:anyURI?"/>

<xsl:variable name="query-string">
<xsl:text>limit=</xsl:text><xsl:value-of select="$limit"/><xsl:text>&amp;</xsl:text>
<xsl:text>offset=</xsl:text><xsl:value-of select="$offset"/><xsl:text>&amp;</xsl:text>
<xsl:if test="$order-by">order-by=<xsl:value-of select="encode-for-uri($order-by)"/>&amp;</xsl:if>
<xsl:if test="not(empty($offset))">offset=<xsl:value-of select="$offset"/>&amp;</xsl:if>
<xsl:if test="not(empty($limit))">limit=<xsl:value-of select="$limit"/>&amp;</xsl:if>
<xsl:if test="not(empty($order-by))">order-by=<xsl:value-of select="encode-for-uri($order-by)"/>&amp;</xsl:if>
<xsl:if test="$desc">desc=true&amp;</xsl:if>
<xsl:if test="$mode">mode=<xsl:value-of select="encode-for-uri($mode)"/>&amp;</xsl:if>
<xsl:if test="not(empty($mode))">mode=<xsl:value-of select="encode-for-uri($mode)"/>&amp;</xsl:if>
</xsl:variable>

<xsl:if test="string-length($query-string) &gt; 1">
Expand All @@ -208,8 +208,8 @@ exclude-result-prefixes="#all">
<xsl:param name="mode" as="xs:anyURI?"/>

<xsl:variable name="query-string">
<xsl:if test="$uri">uri=<xsl:value-of select="encode-for-uri($uri)"/>&amp;</xsl:if>
<xsl:if test="$mode">mode=<xsl:value-of select="encode-for-uri($mode)"/>&amp;</xsl:if>
<xsl:if test="not(empty($uri))">uri=<xsl:value-of select="encode-for-uri($uri)"/>&amp;</xsl:if>
<xsl:if test="not(empty($mode))">mode=<xsl:value-of select="encode-for-uri($mode)"/>&amp;</xsl:if>
</xsl:variable>

<xsl:if test="string-length($query-string) &gt; 1">
Expand All @@ -223,9 +223,9 @@ exclude-result-prefixes="#all">
<xsl:param name="accept" as="xs:string?"/>

<xsl:variable name="query-string">
<xsl:if test="$endpoint-uri">endpoint-uri=<xsl:value-of select="encode-for-uri($endpoint-uri)"/>&amp;</xsl:if>
<xsl:if test="$query">query=<xsl:value-of select="encode-for-uri($query)"/>&amp;</xsl:if>
<xsl:if test="$accept">accept=<xsl:value-of select="encode-for-uri($accept)"/>&amp;</xsl:if>
<xsl:if test="not(empty($endpoint-uri))">endpoint-uri=<xsl:value-of select="encode-for-uri($endpoint-uri)"/>&amp;</xsl:if>
<xsl:if test="not(empty($query))">query=<xsl:value-of select="encode-for-uri($query)"/>&amp;</xsl:if>
<xsl:if test="not(empty($accept))">accept=<xsl:value-of select="encode-for-uri($accept)"/>&amp;</xsl:if>
</xsl:variable>

<xsl:if test="string-length($query-string) &gt; 1">
Expand Down
28 changes: 11 additions & 17 deletions src/main/webapp/static/org/graphity/client/xsl/layout.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ exclude-result-prefixes="#all">
<xsl:otherwise>
<xsl:apply-templates select="key('resources', $absolute-path)"/>

<!-- page resource -->
<xsl:apply-templates select="key('resources-by-page-of', $absolute-path)" mode="gc:PaginationMode"/>
<xsl:apply-templates select="." mode="gc:PaginationMode"/>

<!-- apply all other URI resources -->
<xsl:variable name="secondary-resources" select="*[not(@rdf:about = $absolute-path)][not(. is key('resources-by-page-of', $absolute-path))][not(key('predicates-by-object', @rdf:nodeID))]"/>
Expand All @@ -368,8 +367,7 @@ exclude-result-prefixes="#all">
</xsl:apply-templates>
</xsl:if>

<!-- page resource -->
<xsl:apply-templates select="key('resources-by-page-of', $absolute-path)" mode="gc:PaginationMode"/>
<xsl:apply-templates select="." mode="gc:PaginationMode"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Expand Down Expand Up @@ -572,9 +570,11 @@ exclude-result-prefixes="#all">
</xsl:template>

<xsl:template match="rdf:type[@rdf:resource]" mode="gc:TypeListMode" priority="1">
<li>
<!--
<li>
<xsl:apply-templates select="@rdf:resource" mode="gc:InlineMode"/>
</li>
-->
</xsl:template>

<!-- PROPERTY LIST MODE -->
Expand Down Expand Up @@ -692,16 +692,14 @@ exclude-result-prefixes="#all">

<xsl:apply-templates select="." mode="gc:ModeSelectMode"/>

<!-- page resource -->
<xsl:apply-templates select="key('resources-by-page-of', $absolute-path)" mode="gc:PaginationMode"/>
<xsl:apply-templates select="." mode="gc:PaginationMode"/>

<!-- all resources that are not recursive blank nodes, except page -->
<xsl:apply-templates select="*[not(@rdf:about = $absolute-path)][not(. is key('resources-by-page-of', $absolute-path))][not(key('predicates-by-object', @rdf:nodeID))]" mode="#current">
<xsl:sort select="gc:label(.)" lang="{$lang}"/>
</xsl:apply-templates>

<!-- page resource -->
<xsl:apply-templates select="key('resources-by-page-of', $absolute-path)" mode="gc:PaginationMode"/>
<xsl:apply-templates select="." mode="gc:PaginationMode"/>
</xsl:template>

<xsl:template match="*[*][@rdf:about] | *[*][@rdf:nodeID]" mode="gc:ListMode">
Expand Down Expand Up @@ -735,8 +733,7 @@ exclude-result-prefixes="#all">

<xsl:apply-templates select="." mode="gc:ModeSelectMode"/>

<!-- page resource -->
<xsl:apply-templates select="key('resources-by-page-of', $absolute-path)" mode="gc:PaginationMode"/>
<xsl:apply-templates select="." mode="gc:PaginationMode"/>

<!-- SELECTed resources = everything except container, page, and non-root blank nodes -->
<xsl:variable name="selected-resources" select="*[not(@rdf:about = $absolute-path)][not(. is key('resources-by-page-of', $absolute-path))][not(key('predicates-by-object', @rdf:nodeID))]"/>
Expand Down Expand Up @@ -765,8 +762,7 @@ exclude-result-prefixes="#all">
</tbody>
</table>

<!-- page resource -->
<xsl:apply-templates select="key('resources-by-page-of', $absolute-path)" mode="gc:PaginationMode"/>
<xsl:apply-templates select="." mode="gc:PaginationMode"/>
</xsl:template>

<xsl:template match="*[*][@rdf:about] | *[*][@rdf:nodeID]" mode="gc:TableMode">
Expand Down Expand Up @@ -807,8 +803,7 @@ exclude-result-prefixes="#all">

<xsl:apply-templates select="." mode="gc:ModeSelectMode"/>

<!-- page resource -->
<xsl:apply-templates select="key('resources-by-page-of', $absolute-path)" mode="gc:PaginationMode"/>
<xsl:apply-templates select="." mode="gc:PaginationMode"/>

<ul class="thumbnails">
<xsl:variable name="thumbnail-items" as="element()*">
Expand All @@ -828,8 +823,7 @@ exclude-result-prefixes="#all">
</xsl:for-each-group>
</ul>

<!-- page resource -->
<xsl:apply-templates select="key('resources-by-page-of', $absolute-path)" mode="gc:PaginationMode"/>
<xsl:apply-templates select="." mode="gc:PaginationMode"/>
</xsl:template>

<xsl:template match="*[*][@rdf:about] | *[*][@rdf:nodeID]" mode="gc:ThumbnailMode">
Expand Down

0 comments on commit 40e2eb9

Please sign in to comment.