Class PrefixDeclarations
java.lang.Object
org.eclipse.rdf4j.sparqlbuilder.core.QueryElementCollection<Prefix>
org.eclipse.rdf4j.sparqlbuilder.core.StandardQueryElementCollection<Prefix>
org.eclipse.rdf4j.sparqlbuilder.core.PrefixDeclarations
- All Implemented Interfaces:
QueryElement
A collection of SPARQL Prefix declarations
- See Also:
-
Field Summary
Fields inherited from class QueryElementCollection
elements -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd prefix declarations to this collectionprivate PrefixfindMatchingPrefix(String queryString, int pos) Returns the longest prefix that is found starting at positionposin thequeryStringprivate intfindNextRelevantIndex(String queryString, int lastPos, boolean isInsideString) private intfindNextWhitespace(String continuation) private Stringprivate booleanisContinuationALocalName(String continuation) private booleanisDoubleQuote(String queryString, int pos) private booleanisEscapeChar(String queryString, int pos) private booleanisMultilineQuote(String queryString, int pos) private booleanisOpeningAngledBracket(String queryString, int pos) replacePrefixesInQuery(String queryString) Replaces all occurrences of all declared namespaces with their prefix labels in the specified query string.Methods inherited from class StandardQueryElementCollection
getQueryString, printBodyIfEmpty, printNameIfEmpty, resetWrapperMethod, setOperatorName, setOperatorName, setWrapperMethodMethods inherited from class QueryElementCollection
addElements, addElements, isEmpty
-
Constructor Details
-
PrefixDeclarations
public PrefixDeclarations()
-
-
Method Details
-
addPrefix
Add prefix declarations to this collection- Parameters:
prefixes- the prefixes- Returns:
- this
-
replacePrefixesInQuery
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
-
isMultilineQuote
-
isEscapeChar
-
isDoubleQuote
-
findNextRelevantIndex
-
findMatchingPrefix
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
-
findNextWhitespace
-
getIRIStringFromPrefix
-