org.eclipse.rdf4j.query.parser.sparql

## Class SPARQLQueries

- java.lang.Object
- - org.eclipse.rdf4j.query.parser.sparql.SPARQLQueries

- Direct Known Subclasses:
    SPARQLUtil

      public class SPARQLQueries
      extends Object

  Utility functions for working with SPARQL query strings.
  Author:
    Jeen Broekstra

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SPARQLQueries()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `escape(String s)` Escape the supplied string with backslashes for any special characters, so it can be used as a string literal value in a SPARQL query.
    `static String` | `getPrefixClauses(Iterable<Namespace> namespaces)` Creates a string representing of the supplied `namespaces` as SPARQL prefix declarations.
    `static String` | `unescape(String s)` Un-escapes a backslash-escaped SPARQL literal value string.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SPARQLQueries

          public SPARQLQueries()

  - ### Method Detail

    - #### getPrefixClauses

          public static String getPrefixClauses(Iterable<Namespace> namespaces)

      Creates a string representing of the supplied `namespaces` as SPARQL prefix declarations. This can be used when composing a SPARQL query string in code, for example:

           String query = SPARQLQueries.getPrefixClauses(connection.getNamespaces()) + "SELECT * WHERE { ?s ex:myprop ?o }";

      Parameters:
        `namespaces` - one or more `Namespace` objects.
      Returns:
        one or more SPARQL prefix declarations (each separated by a newline), as a String.
      Since:
        3.6.0

    - #### escape

          public static String escape(String s)

      Escape the supplied string with backslashes for any special characters, so it can be used as a string literal value in a SPARQL query.
      Since:
        3.6.0
      See Also:
        `https://www.w3.org/TR/sparql11-query/#grammarEscapes`

    - #### unescape

          public static String unescape(String s)

      Un-escapes a backslash-escaped SPARQL literal value string. Any recognized \-escape sequences are substituted with their un-escaped value.
      Parameters:
        `s` - An SPARQL literal string with backslash escapes.
      Returns:
        The un-escaped string.
      Throws:
        `IllegalArgumentException` - If the supplied string is not a correctly escaped SPARQL string.
      Since:
        3.6.0
      See Also:
        `https://www.w3.org/TR/sparql11-query/#grammarEscapes`

Copyright © 2015-2021 Eclipse Foundation. All Rights Reserved.