Class PrefixDeclarations
- java.lang.Object
-
- org.eclipse.rdf4j.sparqlbuilder.core.QueryElementCollection<T>
-
- org.eclipse.rdf4j.sparqlbuilder.core.StandardQueryElementCollection<Prefix>
-
- org.eclipse.rdf4j.sparqlbuilder.core.PrefixDeclarations
-
- All Implemented Interfaces:
QueryElement
public class PrefixDeclarations extends StandardQueryElementCollection<Prefix>
A collection of SPARQL Prefix declarations- See Also:
- SPARQL Prefix
-
-
Field Summary
-
Fields inherited from class org.eclipse.rdf4j.sparqlbuilder.core.QueryElementCollection
elements
-
-
Constructor Summary
Constructors Constructor Description PrefixDeclarations()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PrefixDeclarationsaddPrefix(Prefix... prefixes)Add prefix declarations to this collectionprivate PrefixfindMatchingPrefix(java.lang.String queryString, int pos)Returns the longest prefix that is found starting at positionposin thequeryStringprivate intfindNextRelevantIndex(java.lang.String queryString, int lastPos, boolean isInsideString)private intfindNextWhitespace(java.lang.String continuation)private java.lang.StringgetIRIStringFromPrefix(Prefix p)private booleanisContinuationALocalName(java.lang.String continuation)private booleanisDoubleQuote(java.lang.String queryString, int pos)private booleanisEscapeChar(java.lang.String queryString, int pos)private booleanisMultilineQuote(java.lang.String queryString, int pos)private booleanisOpeningAngledBracket(java.lang.String queryString, int pos)java.lang.StringreplacePrefixesInQuery(java.lang.String queryString)Replaces all occurrences of all declared namespaces with their prefix labels in the specified query string.-
Methods inherited from class org.eclipse.rdf4j.sparqlbuilder.core.StandardQueryElementCollection
getQueryString, printBodyIfEmpty, printNameIfEmpty, resetWrapperMethod, setOperatorName, setOperatorName, setWrapperMethod
-
Methods inherited from class org.eclipse.rdf4j.sparqlbuilder.core.QueryElementCollection
addElements, addElements, isEmpty
-
-
-
-
Method Detail
-
addPrefix
public PrefixDeclarations addPrefix(Prefix... prefixes)
Add prefix declarations to this collection- Parameters:
prefixes- the prefixes- Returns:
- this
-
replacePrefixesInQuery
public java.lang.String replacePrefixesInQuery(java.lang.String queryString)
Replaces all occurrences of all declared namespaces with their prefix labels in the specified query string.For example, if the
foaf:prefix is declared withPrefixDeclarations, the querySELECT ?name WHERE { ?x <http://xmlns.com/foaf/0.1/name> ?name . }is transformed to
SELECT ?name WHERE { ?x foaf:name ?name . }Rules applied:
- The longest matching namespace wins (if one namespace is a substring of another)
- No replacement if the namespace occurs in a string, i.e., within
"or''' - Only replace if the continuation of the match is a local name (
- Parameters:
queryString- the query string- Returns:
- the query string, namespaces replaced with prefix label
-
isOpeningAngledBracket
private boolean isOpeningAngledBracket(java.lang.String queryString, int pos)
-
isMultilineQuote
private boolean isMultilineQuote(java.lang.String queryString, int pos)
-
isEscapeChar
private boolean isEscapeChar(java.lang.String queryString, int pos)
-
isDoubleQuote
private boolean isDoubleQuote(java.lang.String queryString, int pos)
-
findNextRelevantIndex
private int findNextRelevantIndex(java.lang.String queryString, int lastPos, boolean isInsideString)
-
findMatchingPrefix
private Prefix findMatchingPrefix(java.lang.String queryString, int pos)
Returns the longest prefix that is found starting at positionposin thequeryString- Parameters:
queryString- the query stringpos- the position at which to start looking- Returns:
- the longest prefixIri that matches fully (no tie-break for duplicates)
-
isContinuationALocalName
private boolean isContinuationALocalName(java.lang.String continuation)
-
findNextWhitespace
private int findNextWhitespace(java.lang.String continuation)
-
getIRIStringFromPrefix
private java.lang.String getIRIStringFromPrefix(Prefix p)
-
-