@@ -35,8 +35,22 @@ public class QueryStringUtil {
3535 * @param queryString
3636 * @param bindings
3737 * @return the modified queryString
38+ * @deprecated since 2.3 use {@link #getTupleQueryString(String, BindingSet)}
3839 */
40+ @ Deprecated
3941 public static String getQueryString (String queryString , BindingSet bindings ) {
42+ return getTupleQueryString (queryString , bindings );
43+ }
44+
45+ /**
46+ * Retrieve a modified queryString into which all bindings of the given argument are replaced, with the
47+ * binding names included in the SELECT clause.
48+ *
49+ * @param queryString
50+ * @param bindings
51+ * @return the modified queryString
52+ */
53+ public static String getTupleQueryString (String queryString , BindingSet bindings ) {
4054 if (bindings .size () == 0 ) {
4155 return queryString ;
4256 }
@@ -61,6 +75,56 @@ public static String getQueryString(String queryString, BindingSet bindings) {
6175 return select + where ;
6276 }
6377
78+ /**
79+ * Retrieve a modified queryString into which all bindings of the given argument are replaced with their
80+ * value.
81+ *
82+ * @param queryString
83+ * @param bindings
84+ * @return the modified queryString
85+ */
86+ public static String getUpdateString (String queryString , BindingSet bindings ) {
87+ return getGraphQueryString (queryString , bindings );
88+ }
89+
90+ /**
91+ * Retrieve a modified queryString into which all bindings of the given argument are replaced with their
92+ * value.
93+ *
94+ * @param queryString
95+ * @param bindings
96+ * @return the modified queryString
97+ */
98+ public static String getBooleanQueryString (String queryString , BindingSet bindings ) {
99+ return getGraphQueryString (queryString , bindings );
100+ }
101+
102+ /**
103+ * Retrieve a modified queryString into which all bindings of the given argument are replaced with their
104+ * value.
105+ *
106+ * @param queryString
107+ * @param bindings
108+ * @return the modified queryString
109+ */
110+ public static String getGraphQueryString (String queryString , BindingSet bindings ) {
111+ if (bindings .size () == 0 ) {
112+ return queryString ;
113+ }
114+
115+ String qry = queryString ;
116+ for (String name : bindings .getBindingNames ()) {
117+ String replacement = getReplacement (bindings .getValue (name ));
118+ if (replacement != null ) {
119+ String pattern = "[\\ ?\\ $]" + name + "(?=\\ W)" ;
120+ // we use Matcher.quoteReplacement to make sure things like newlines
121+ // in literal values are preserved
122+ qry = qry .replaceAll (pattern , Matcher .quoteReplacement (replacement ));
123+ }
124+ }
125+ return qry ;
126+ }
127+
64128 private static String getReplacement (Value value ) {
65129 StringBuilder sb = new StringBuilder ();
66130 if (value instanceof IRI ) {
0 commit comments