- All Implemented Interfaces:
org.apache.jena.shared.PrefixMapping
A Parameterized SPARQL String is a SPARQL query/update into which values may be injected.
Injecting Values
Values may be injected in several ways:
- By treating a variable in the SPARQL string as a parameter
- Using JDBC style positional parameters
- Appending values directly to the command text being built
Variable Parameters
Any variable in the command may have a value injected to it, injecting a value replaces all usages of that variable in the command i.e. substitutes the variable for a constant, injection is done by textual substitution.
Positional Parameters
You can use JDBC style positional parameters if you prefer, a JDBC style
parameter is a single ? followed by whitespace or certain punctuation
characters (currently ; , .). Positional parameters have a unique
index which reflects the order in which they appear in the string. Positional
parameters use a zero based index.
Buffer Usage
Additionally you may use this purely as a StringBuilder replacement
for creating queries since it provides a large variety of convenience methods
for appending things either as-is or as nodes (which causes appropriate
formatting to be applied).
Intended Usage
The intended usage of this is where using a QuerySolutionMap as
initial bindings is either inappropriate or not possible e.g.
- Generating query/update strings in code without lots of error prone and messy string concatenation
- Preparing a query/update for remote execution
- Where you do not want to simply say some variable should have a certain value but rather wish to insert constants into the query/update in place of variables
- Defending against SPARQL injection when creating a query/update using some external input, see SPARQL Injection notes for limitations.
- Provide a more convenient way to prepend common prefixes to your query
This class is useful for preparing both queries and updates hence the generic
name as it provides programmatic ways to replace variables in the query with
constants and to add prefix and base declarations. A Query or
UpdateRequest can be created using the asQuery() and
asUpdate() methods assuming the command an instance represents is
actually valid as a query/update.
Warnings
- Note that this class does not in any way check that your command is
syntactically correct until such time as you try and parse it as a
QueryorUpdateRequest. - Also note that injection is done purely based on textual replacement, it does not understand or respect variable scope in any way. For example if your command text contains sub queries you should ensure that variables within the sub query which you don't want replaced have distinct names from those in the outer query you do want replaced (or vice versa)
SPARQL Injection Notes
While this class was in part designed to prevent SPARQL injection it is by no means foolproof because it works purely at the textual level. The current version of the code addresses some possible attack vectors that the developers have identified, but we do not claim to be sufficiently devious to have thought of and prevented every possible attack vector.
Therefore we strongly recommend that users concerned about SPARQL Injection attacks perform their own validation on provided parameters and test their use of this class themselves prior to its use in any security conscious deployment. We also recommend that users do not use easily guess-able variable names for their parameters as these can allow a chained injection attack though generally speaking the code should prevent these.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.jena.shared.PrefixMapping
org.apache.jena.shared.PrefixMapping.Factory, org.apache.jena.shared.PrefixMapping.IllegalPrefixException, org.apache.jena.shared.PrefixMapping.JenaLockedException -
Field Summary
Fields inherited from interface org.apache.jena.shared.PrefixMapping
Extended, Standard -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new parameterized string with an empty command textParameterizedSparqlString(String command) Creates a new parameterized stringParameterizedSparqlString(String command, String base) Creates a new parameterized stringParameterizedSparqlString(String command, String base, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringParameterizedSparqlString(String command, QuerySolutionMap map) Creates a new parameterized stringParameterizedSparqlString(String command, QuerySolutionMap map, String base) Creates a new parameterized stringParameterizedSparqlString(String command, QuerySolutionMap map, String base, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringParameterizedSparqlString(String command, QuerySolutionMap map, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringParameterizedSparqlString(String command, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringCreates a new parameterized stringParameterizedSparqlString(QuerySolutionMap map, org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized stringParameterizedSparqlString(org.apache.jena.shared.PrefixMapping prefixes) Creates a new parameterized string -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(boolean b) Appends a boolean as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(boolean)methodvoidappend(char c) Appends a character as-is to the existing command text, to ensure correct formatting when used as a constant consider using one of theappendLiteral()methodsvoidappend(double d) Appends a double as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(double)methodvoidappend(float f) Appends a float as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(float)methodvoidappend(int i) Appends an integer as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(int)methodvoidappend(long l) Appends a long as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(long)methodvoidAppends an object as-is to the existing command text, to ensure correct formatting when used as a constant consider converting into a more specific type and using the appropriateappendLiteral(),appendIri()orappendNodemethodsvoidAppends some text as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(String)orappendIri(String)method as appropriatevoidAppends a URI to the command text as a constant using appropriate formattingvoidappendIri(org.apache.jena.irix.IRIx iri) Appends an IRI to the command text as a constant using appropriate formattingvoidappendLiteral(boolean b) Appends a boolean to the command text as a constant using appropriate formattingvoidappendLiteral(double d) Appends a double to the command text as a constant using appropriate formattingvoidappendLiteral(float f) Appends a float to the command text as a constant using appropriate formattingvoidappendLiteral(int i) Appends an integer to the command text as a constant using appropriate formattingvoidappendLiteral(long l) Appends a long to the command text as a constant using appropriate formattingvoidappendLiteral(String value) Appends a simple literal as a constant using appropriate formattingvoidappendLiteral(String value, String lang) Appends a literal with a lexical value and language to the command text as a constant using appropriate formattingvoidappendLiteral(String value, String lang, String direction) Appends a literal with a lexical value, language and base direction to the command text as a constant using appropriate formattingvoidappendLiteral(String value, org.apache.jena.datatypes.RDFDatatype datatype) Appends a Typed Literal to the command text as a constant using appropriate formattingvoidAppends a date time to the command text as a constant using appropriate formattingvoidappendNode(org.apache.jena.graph.Node n) Appends a Node to the command text as a constant using appropriate formattingvoidappendNode(org.apache.jena.rdf.model.RDFNode n) Appends a Node to the command text as a constant using appropriate formattingasQuery()Attempts to take the command text with parameters injected from thetoString()method and parse it as aQueryAttempts to take the command text with parameters injected from thetoString()method and parse it as aQueryusing the givenSyntaxsyntaxasUpdate()Attempts to take the command text with parameters injected from thetoString()method and parse it as aUpdateRequestAttempts to take the command text with parameters injected from thetoString()method and parse it as aUpdateRequestusing the givenSyntaxorg.apache.jena.shared.PrefixMappingvoidclearParam(int index) Clears the value for a positional parametervoidclearParam(String var) Clears the value for a variable or values parameter so the given variable will not * have a value injectedvoidClears all values for variable, values and positional parameterscopy()Makes a full copy of this parameterized stringcopy(boolean copyParams) Makes a copy of the command text, base URI and prefix mapping and optionally copies parameter valuescopy(boolean copyParams, boolean copyBase, boolean copyPrefixes) Makes a copy of the command text and optionally copies other aspectsexpandPrefix(String prefixed) Gets the Base URI which will be prepended to a queryGets the basic Command TextGets the eligible positional parameters i.e. detected positional parameters that may be set in the command string as it currently standsgetNsPrefixURI(String prefix) getNsURIPrefix(String uri) org.apache.jena.graph.NodegetParam(int index) Gets the current value for a positional parameterorg.apache.jena.graph.NodeGets the current value for a variable parameterGets the map of currently set positional parameters, this will be an unmodifiable mapGets the syntax used for parsing when callingasQuery()orasUpdate()Gets the map of currently set variable parameters, this will be an unmodifiable mapgetVars()Gets the variable names which are currently treated as variable parameters (i.e. have values set for them)booleanorg.apache.jena.shared.PrefixMappinglock()intorg.apache.jena.shared.PrefixMappingremoveNsPrefix(String prefix) booleansamePrefixMappingAs(org.apache.jena.shared.PrefixMapping other) voidsetBaseUri(String base) Sets the Base URI which will be prepended to the query/updatevoidsetCommandText(String command) Sets the command text, overwriting any existing command text.voidSets a positional parameter to an IRIvoidSets a positional parameter to an IRIvoidsetIri(int index, org.apache.jena.irix.IRIx iri) Sets a positional parameter to an IRIvoidSets a variable parameter to an IRIvoidSets a variable parameter to an IRIvoidSets a variable parameter to an IRIvoidsetLiteral(int index, boolean value) Sets a positional parameter to a boolean literalvoidsetLiteral(int index, double d) Sets a positional parameter to a double literalvoidsetLiteral(int index, float f) Sets a positional parameter to a float literalvoidsetLiteral(int index, int i) Sets a positional parameter to an integer literalvoidsetLiteral(int index, long l) Sets a positional parameter to an integer literalvoidsetLiteral(int index, String value) Sets a positional parameter to a literalvoidsetLiteral(int index, String value, String lang) Sets a positional parameter to a literal with a languagevoidsetLiteral(int index, String value, String lang, String baseDirection) Sets a positional parameter to a literal with a language and base directionvoidsetLiteral(int index, String value, org.apache.jena.datatypes.RDFDatatype datatype) Sets a positional parameter to a typed literalvoidsetLiteral(int index, Calendar dt) Sets a positional parameter to a date time literalvoidsetLiteral(int index, org.apache.jena.rdf.model.Literal lit) Sets a positional parameter to a LiteralvoidsetLiteral(String var, boolean value) Sets a variable parameter to a boolean literalvoidsetLiteral(String var, double d) Sets a variable parameter to a double literalvoidsetLiteral(String var, float f) Sets a variable parameter to a float literalvoidsetLiteral(String var, int i) Sets a variable parameter to an integer literalvoidsetLiteral(String var, long l) Sets a variable parameter to an integer literalvoidsetLiteral(String var, String value) Sets a variable parameter to a literalvoidsetLiteral(String var, String value, String lang) Sets a variable parameter to a literal with a languagevoidsetLiteral(String var, String value, String lang, String baseDirection) Sets a variable parameter to a literal with a languagevoidsetLiteral(String var, String value, org.apache.jena.datatypes.RDFDatatype datatype) Sets a variable parameter to a typed literalvoidsetLiteral(String var, Calendar dt) Sets a variable parameter to a date time literalvoidsetLiteral(String var, org.apache.jena.rdf.model.Literal lit) Sets a variable parameter to a Literalorg.apache.jena.shared.PrefixMappingsetNsPrefix(String prefix, String uri) org.apache.jena.shared.PrefixMappingsetNsPrefixes(Map<String, String> map) org.apache.jena.shared.PrefixMappingsetNsPrefixes(org.apache.jena.shared.PrefixMapping other) voidsetParam(int index, org.apache.jena.graph.Node n) Sets a Positional ParametervoidsetParam(int index, org.apache.jena.rdf.model.RDFNode n) Sets a positional parametervoidSets a variable parametervoidSets a variable parametervoidSets the ParametersvoidsetRowValues(String valueName, Collection<List<? extends org.apache.jena.rdf.model.RDFNode>> rowItems) Allocate multiple lists of variables to a single VALUES valueName.
Using "valuesName" with list(list(prop_A, obj_A), list(prop_B, obj_B)) on query "VALUES (?voidSets the syntax used for parsing when callingasQuery()orasUpdate()voidsetValues(String valueName, Collection<? extends org.apache.jena.rdf.model.RDFNode> items) Assign a VALUES valueName with a multiple items.
Can be used to assign multiple values to a single variable or single value to multiple variables (if using a List) in the SPARQL query.
See setRowValues to assign multiple values to multiple variables.
Using "valueName" with list(prop_A, obj_A) on query "VALUES (?voidAssign a VALUES valueName with a single item.
Using "valueName" with Literal obj_A on query "VALUES ?voidsetValues(Map<String, Collection<? extends org.apache.jena.rdf.model.RDFNode>> itemsMap) Sets a map of VALUES valueNames and their items.
Can be used to assign multiple values to a single variable or single value to multiple variables (if using a List) in the SPARQL query.
See setRowValues to assign multiple values to multiple variables.toString()This method is where the actual work happens, the original command text is always preserved, and we just generate a temporary command string by prepending the defined Base URI and namespace prefixes at the start of the command and injecting the set parameters into a copy of that base command string and return the resulting command.org.apache.jena.rdf.model.RDFNodeundef()Gets a specialRDFNodevalue that can be used with the varioussetValues(Map)-like methods to inject theUNDEFkeyword into a parameterisedVALUESclause.org.apache.jena.shared.PrefixMappingwithDefaultMappings(org.apache.jena.shared.PrefixMapping map)
-
Constructor Details
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
command- Raw Command Textmap- Initial Parameters to injectbase- Base URI
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
command- Raw Command Textmap- Initial Parameters to inject
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
command- Raw Command Textbase- Base URI
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
command- Raw Command Text
-
ParameterizedSparqlString
Creates a new parameterized string- Parameters:
map- Initial Parameters to inject
-
ParameterizedSparqlString
public ParameterizedSparqlString()Creates a new parameterized string with an empty command text
-
Method Details
-
getSyntax
Gets the syntax used for parsing when callingasQuery()orasUpdate()- Returns:
- Syntax
-
setSyntax
Sets the syntax used for parsing when callingasQuery()orasUpdate()- Parameters:
syntax- Syntax
-
setCommandText
Sets the command text, overwriting any existing command text. If you want to append to the command text use one of theappend(String),appendIri(String),appendLiteral(String)orappendNode(Node)methods instead- Parameters:
command- Command Text
-
append
Appends some text as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(String)orappendIri(String)method as appropriate- Parameters:
text- Text to append
-
append
public void append(char c) Appends a character as-is to the existing command text, to ensure correct formatting when used as a constant consider using one of theappendLiteral()methods- Parameters:
c- Character to append
-
append
public void append(boolean b) Appends a boolean as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(boolean)method- Parameters:
b- Boolean to append
-
append
public void append(double d) Appends a double as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(double)method- Parameters:
d- Double to append
-
append
public void append(float f) Appends a float as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(float)method- Parameters:
f- Float to append
-
append
public void append(int i) Appends an integer as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(int)method- Parameters:
i- Integer to append
-
append
public void append(long l) Appends a long as-is to the existing command text, to ensure correct formatting when used as a constant consider using theappendLiteral(long)method- Parameters:
l- Long to append
-
append
Appends an object as-is to the existing command text, to ensure correct formatting when used as a constant consider converting into a more specific type and using the appropriateappendLiteral(),appendIri()orappendNodemethods- Parameters:
obj- Object to append
-
appendNode
public void appendNode(org.apache.jena.graph.Node n) Appends a Node to the command text as a constant using appropriate formatting- Parameters:
n- Node to append
-
appendNode
public void appendNode(org.apache.jena.rdf.model.RDFNode n) Appends a Node to the command text as a constant using appropriate formatting- Parameters:
n- Node to append
-
appendIri
Appends a URI to the command text as a constant using appropriate formatting- Parameters:
uri- URI to append
-
appendIri
public void appendIri(org.apache.jena.irix.IRIx iri) Appends an IRI to the command text as a constant using appropriate formatting- Parameters:
iri- IRI to append
-
appendLiteral
Appends a simple literal as a constant using appropriate formatting- Parameters:
value- Lexical Value
-
appendLiteral
Appends a literal with a lexical value and language to the command text as a constant using appropriate formatting- Parameters:
value- Lexical Valuelang- Language
-
appendLiteral
Appends a literal with a lexical value, language and base direction to the command text as a constant using appropriate formatting- Parameters:
value- Lexical Valuelang- Languagedirection- Base direction
-
appendLiteral
Appends a Typed Literal to the command text as a constant using appropriate formatting- Parameters:
value- Lexical Valuedatatype- Datatype
-
appendLiteral
public void appendLiteral(boolean b) Appends a boolean to the command text as a constant using appropriate formatting- Parameters:
b- Boolean to append
-
appendLiteral
public void appendLiteral(int i) Appends an integer to the command text as a constant using appropriate formatting- Parameters:
i- Integer to append
-
appendLiteral
public void appendLiteral(long l) Appends a long to the command text as a constant using appropriate formatting- Parameters:
l- Long to append
-
appendLiteral
public void appendLiteral(float f) Appends a float to the command text as a constant using appropriate formatting- Parameters:
f- Float to append
-
appendLiteral
public void appendLiteral(double d) Appends a double to the command text as a constant using appropriate formatting- Parameters:
d- Double to append
-
appendLiteral
Appends a date time to the command text as a constant using appropriate formatting- Parameters:
dt- Date Time to append
-
getCommandText
Gets the basic Command TextNote: This will not reflect any injected parameters, to see the command with injected parameters invoke the
toString()method- Returns:
- Command Text
-
setBaseUri
Sets the Base URI which will be prepended to the query/update- Parameters:
base- Base URI
-
getBaseUri
Gets the Base URI which will be prepended to a query- Returns:
- Base URI
-
undef
public org.apache.jena.rdf.model.RDFNode undef()Gets a specialRDFNodevalue that can be used with the varioussetValues(Map)-like methods to inject theUNDEFkeyword into a parameterisedVALUESclause.- Returns:
- Special undefined node value
-
setParams
Sets the Parameters- Parameters:
map- Parameters
-
setParam
public void setParam(int index, org.apache.jena.graph.Node n) Sets a Positional ParameterSetting a parameter to null is equivalent to calling
clearParam(int)for the given variable- Parameters:
index- Positional Indexn- Node
-
setParam
Sets a variable parameterSetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variablen- Value
-
setParam
public void setParam(int index, org.apache.jena.rdf.model.RDFNode n) Sets a positional parameterSetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
index- Positional Indexn- Node
-
setParam
Sets a variable parameterSetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variablen- Value
-
setIri
Sets a positional parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(int)for the given index- Parameters:
index- Positional Indexiri- IRI
-
setIri
Sets a variable parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variableiri- IRI
-
setIri
public void setIri(int index, org.apache.jena.irix.IRIx iri) Sets a positional parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(int)for the given index- Parameters:
index- Positional Indexiri- IRI
-
setIri
Sets a variable parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variableiri- IRI
-
setIri
Sets a positional parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(int)for the given index- Parameters:
index- Positional Indexurl- URL
-
setIri
Sets a variable parameter to an IRISetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variableurl- URL used as IRI
-
setLiteral
public void setLiteral(int index, org.apache.jena.rdf.model.Literal lit) Sets a positional parameter to a LiteralSetting a parameter to null is equivalent to calling
clearParam(int)for the given index- Parameters:
index- Positional Indexlit- Value
-
setLiteral
Sets a variable parameter to a LiteralSetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variablelit- Value
-
setLiteral
Sets a positional parameter to a literalSetting a parameter to null is equivalent to calling
clearParam(int)for the given index- Parameters:
index- Positional Indexvalue- Lexical Value
-
setLiteral
Sets a variable parameter to a literalSetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variablevalue- Lexical Value
-
setLiteral
Sets a positional parameter to a literal with a languageSetting a parameter to null is equivalent to calling
clearParam(int)for the given index- Parameters:
index- Positional indexvalue- Lexical Valuelang- Language
-
setLiteral
Sets a variable parameter to a literal with a languageSetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variablevalue- Lexical Valuelang- LanguagebaseDirection- Base direction
-
setLiteral
Sets a positional parameter to a literal with a language and base directionSetting a parameter to null is equivalent to calling
clearParam(int)for the given index- Parameters:
index- Positional indexvalue- Lexical Valuelang- LanguagebaseDirection- Base direction
-
setLiteral
Sets a variable parameter to a literal with a languageSetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variablevalue- Lexical Valuelang- Language
-
setLiteral
Sets a positional parameter to a typed literalSetting a parameter to null is equivalent to calling
clearParam(int)for the given index- Parameters:
index- Positional Indexvalue- Lexical Valuedatatype- Datatype
-
setLiteral
Sets a variable parameter to a typed literalSetting a parameter to null is equivalent to calling
clearParam(String)for the given variable- Parameters:
var- Variablevalue- Lexical Valuedatatype- Datatype
-
setLiteral
public void setLiteral(int index, boolean value) Sets a positional parameter to a boolean literal- Parameters:
index- Positional Indexvalue- boolean
-
setLiteral
Sets a variable parameter to a boolean literal- Parameters:
var- Variablevalue- boolean
-
setLiteral
public void setLiteral(int index, int i) Sets a positional parameter to an integer literal- Parameters:
index- Positional Indexi- Integer Value
-
setLiteral
Sets a variable parameter to an integer literal- Parameters:
var- Variablei- Integer Value
-
setLiteral
public void setLiteral(int index, long l) Sets a positional parameter to an integer literal- Parameters:
index- Positional Indexl- Integer Value
-
setLiteral
Sets a variable parameter to an integer literal- Parameters:
var- Variablel- Integer Value
-
setLiteral
public void setLiteral(int index, float f) Sets a positional parameter to a float literal- Parameters:
index- Positional Indexf- Float value
-
setLiteral
Sets a variable parameter to a float literal- Parameters:
var- Variablef- Float value
-
setLiteral
public void setLiteral(int index, double d) Sets a positional parameter to a double literal- Parameters:
index- Positional Indexd- Double value
-
setLiteral
Sets a variable parameter to a double literal- Parameters:
var- Variabled- Double value
-
setLiteral
Sets a positional parameter to a date time literal- Parameters:
index- Positional Indexdt- Date Time value
-
setLiteral
Sets a variable parameter to a date time literal- Parameters:
var- Variabledt- Date Time value
-
getParam
Gets the current value for a variable parameter- Parameters:
var- Variable- Returns:
- Current value or null if not set
-
getParam
public org.apache.jena.graph.Node getParam(int index) Gets the current value for a positional parameter- Parameters:
index- Positional Index- Returns:
- Current value or null if not set
-
getVars
Gets the variable names which are currently treated as variable parameters (i.e. have values set for them)- Returns:
- Iterator of variable names
-
getVariableParameters
Gets the map of currently set variable parameters, this will be an unmodifiable map- Returns:
- Map of variable names and values
-
getPositionalParameters
Gets the map of currently set positional parameters, this will be an unmodifiable map- Returns:
- Map of positional indexes and values
-
getEligiblePositionalParameters
Gets the eligible positional parameters i.e. detected positional parameters that may be set in the command string as it currently stands- Returns:
- Iterator of eligible positional parameters
-
clearParam
Clears the value for a variable or values parameter so the given variable will not * have a value injected- Parameters:
var- Variable
-
clearParam
public void clearParam(int index) Clears the value for a positional parameter- Parameters:
index- Positional Index
-
clearParams
public void clearParams()Clears all values for variable, values and positional parameters -
toString
This method is where the actual work happens, the original command text is always preserved, and we just generate a temporary command string by prepending the defined Base URI and namespace prefixes at the start of the command and injecting the set parameters into a copy of that base command string and return the resulting command.
This class makes no guarantees about the validity of the returned string for use as a SPARQL Query or Update, for example if a variable parameter was injected which was mentioned in the SELECT variables list you'd have a syntax error when you try to parse the query. If you run into issues like this try using a mixture of variable and positional parameters.
- Overrides:
toStringin classObject- Throws:
ARQException- May be thrown if the code detects a SPARQL Injection vulnerability because of the interaction of the command string and the injected variables
-
asQuery
Attempts to take the command text with parameters injected from thetoString()method and parse it as aQuery- Returns:
- Query if the command text is a valid SPARQL query
- Throws:
QueryException- Thrown if the command text does not parse
-
asQuery
Attempts to take the command text with parameters injected from thetoString()method and parse it as aQueryusing the givenSyntaxsyntax- Returns:
- Query if the command text is a valid SPARQL query
- Throws:
QueryException- Thrown if the command text does not parse
-
asUpdate
Attempts to take the command text with parameters injected from thetoString()method and parse it as aUpdateRequest- Returns:
- Update if the command text is a valid SPARQL Update request (one/more update commands)
-
asUpdate
Attempts to take the command text with parameters injected from thetoString()method and parse it as aUpdateRequestusing the givenSyntax- Returns:
- Update if the command text is a valid SPARQL Update request (one/more update commands)
-
copy
Makes a full copy of this parameterized string- Returns:
- Copy of the string
-
copy
Makes a copy of the command text, base URI and prefix mapping and optionally copies parameter values- Parameters:
copyParams- Whether to copy parameters- Returns:
- Copy of the string
-
copy
Makes a copy of the command text and optionally copies other aspects- Parameters:
copyParams- Whether to copy parameterscopyBase- Whether to copy the Base URIcopyPrefixes- Whether to copy the prefix mappings- Returns:
- Copy of the string
-
setNsPrefix
- Specified by:
setNsPrefixin interfaceorg.apache.jena.shared.PrefixMapping
-
removeNsPrefix
- Specified by:
removeNsPrefixin interfaceorg.apache.jena.shared.PrefixMapping
-
clearNsPrefixMap
public org.apache.jena.shared.PrefixMapping clearNsPrefixMap()- Specified by:
clearNsPrefixMapin interfaceorg.apache.jena.shared.PrefixMapping
-
setNsPrefixes
- Specified by:
setNsPrefixesin interfaceorg.apache.jena.shared.PrefixMapping
-
getNsPrefixURI
- Specified by:
getNsPrefixURIin interfaceorg.apache.jena.shared.PrefixMapping
-
getNsURIPrefix
- Specified by:
getNsURIPrefixin interfaceorg.apache.jena.shared.PrefixMapping
-
getNsPrefixMap
- Specified by:
getNsPrefixMapin interfaceorg.apache.jena.shared.PrefixMapping
-
expandPrefix
- Specified by:
expandPrefixin interfaceorg.apache.jena.shared.PrefixMapping
-
shortForm
- Specified by:
shortFormin interfaceorg.apache.jena.shared.PrefixMapping
-
qnameFor
- Specified by:
qnameForin interfaceorg.apache.jena.shared.PrefixMapping
-
hasNoMappings
public boolean hasNoMappings()- Specified by:
hasNoMappingsin interfaceorg.apache.jena.shared.PrefixMapping
-
numPrefixes
public int numPrefixes()- Specified by:
numPrefixesin interfaceorg.apache.jena.shared.PrefixMapping
-
lock
public org.apache.jena.shared.PrefixMapping lock()- Specified by:
lockin interfaceorg.apache.jena.shared.PrefixMapping
-
setValues
public void setValues(String valueName, Collection<? extends org.apache.jena.rdf.model.RDFNode> items) Assign a VALUES valueName with a multiple items.
Can be used to assign multiple values to a single variable or single value to multiple variables (if using a List) in the SPARQL query.
See setRowValues to assign multiple values to multiple variables.
Using "valueName" with list(prop_A, obj_A) on query "VALUES (?p ?o) {?valueName}" * would produce "VALUES (?p ?o) {(prop_A obj_A)}".Note that if you want to inject the SPARQL keyword
UNDEFfor any of the values then you MUST use the specialundef()value in the items parameter as appropriate.- Parameters:
valueName-items-
-
setValues
Assign a VALUES valueName with a single item.
Using "valueName" with Literal obj_A on query "VALUES ?o {?valueName}" would produce * "VALUES ?o {obj_A}".Note that if you want to inject the SPARQL keyword
UNDEFfor the value then you MUST use the specialundef()value as the item parameter.- Parameters:
valueName-item-
-
setValues
Sets a map of VALUES valueNames and their items.
Can be used to assign multiple values to a single variable or single value to multiple variables (if using a List) in the SPARQL query.
See setRowValues to assign multiple values to multiple variables.Note that if you want to inject the SPARQL keyword
UNDEFfor any of the values then you MUST use the specialundef()value in the itemsMap parameter as appropriate.- Parameters:
itemsMap-
-
setRowValues
public void setRowValues(String valueName, Collection<List<? extends org.apache.jena.rdf.model.RDFNode>> rowItems) Allocate multiple lists of variables to a single VALUES valueName.
Using "valuesName" with list(list(prop_A, obj_A), list(prop_B, obj_B)) on query "VALUES (?p ?o) {?valuesName}" would produce "VALUES (?p ?o) {(prop_A obj_A) * (prop_B obj_B)}".Note that if you want to inject the SPARQL keyword
UNDEFfor any of the values then you MUST use the specialundef()value in the rowItems parameter as appropriate.- Parameters:
valueName-rowItems-
-