@ -59,7 +59,6 @@ public final class RequestTemplate implements Serializable {
private boolean decodeSlash = true ;
private boolean decodeSlash = true ;
public RequestTemplate ( ) {
public RequestTemplate ( ) {
}
}
/* Copy constructor. Use this when making templates. */
/* Copy constructor. Use this when making templates. */
@ -127,9 +126,19 @@ public final class RequestTemplate implements Serializable {
for ( char c : template . toCharArray ( ) ) {
for ( char c : template . toCharArray ( ) ) {
switch ( c ) {
switch ( c ) {
case '{' :
case '{' :
if ( inVar ) {
// '{{' is an escape: write the brace and don't interpret as a variable
builder . append ( "{" ) ;
inVar = false ;
break ;
}
inVar = true ;
inVar = true ;
break ;
break ;
case '}' :
case '}' :
if ( ! inVar ) { // then write the brace literally
builder . append ( '}' ) ;
break ;
}
inVar = false ;
inVar = false ;
String key = var . toString ( ) ;
String key = var . toString ( ) ;
Object value = variables . get ( var . toString ( ) ) ;
Object value = variables . get ( var . toString ( ) ) ;
@ -208,13 +217,11 @@ public final class RequestTemplate implements Serializable {
}
}
url = new StringBuilder ( resolvedUrl ) ;
url = new StringBuilder ( resolvedUrl ) ;
Map < String , Collection < String > >
Map < String , Collection < String > > resolvedHeaders = new LinkedHashMap < String , Collection < String > > ( ) ;
resolvedHeaders =
new LinkedHashMap < String , Collection < String > > ( ) ;
for ( String field : headers . keySet ( ) ) {
for ( String field : headers . keySet ( ) ) {
Collection < String > resolvedValues = new ArrayList < String > ( ) ;
Collection < String > resolvedValues = new ArrayList < String > ( ) ;
for ( String value : valuesOrEmpty ( headers , field ) ) {
for ( String value : valuesOrEmpty ( headers , field ) ) {
String resolved = urlDecode ( expand ( value , encoded ) ) ;
String resolved = expand ( value , un encoded) ;
resolvedValues . add ( resolved ) ;
resolvedValues . add ( resolved ) ;
}
}
resolvedHeaders . put ( field , resolvedValues ) ;
resolvedHeaders . put ( field , resolvedValues ) ;
@ -283,7 +290,7 @@ public final class RequestTemplate implements Serializable {
}
}
/ * *
/ * *
* Replaces queries with the specified { @code configKey } with url decoded { @code values } supplied .
* Replaces queries with the specified { @code name } with url decoded { @code values } supplied .
* < br > When the { @code value } is { @code null } , all queries with the { @code configKey } are
* < br > When the { @code value } is { @code null } , all queries with the { @code configKey } are
* removed . < br > < br > < br > < b > relationship to JAXRS 2 . 0 < / b > < br > < br > Like { @code WebTarget . query } ,
* removed . < br > < br > < br > < b > relationship to JAXRS 2 . 0 < / b > < br > < br > Like { @code WebTarget . query } ,
* except the values can be templatized . < br > ex . < br >
* except the values can be templatized . < br > ex . < br >
@ -291,29 +298,29 @@ public final class RequestTemplate implements Serializable {
* template . query ( & quot ; Signature & quot ; , & quot ; { signature } & quot ; ) ;
* template . query ( & quot ; Signature & quot ; , & quot ; { signature } & quot ; ) ;
* < / pre >
* < / pre >
*
*
* @param configKey the configKey of the query
* @param name the name of the query
* @param values can be a single null to imply removing all values . Else no values are expected
* @param values can be a single null to imply removing all values . Else no values are expected
* to be null .
* to be null .
* @see # queries ( )
* @see # queries ( )
* /
* /
public RequestTemplate query ( String configKey , String . . . values ) {
public RequestTemplate query ( String name , String . . . values ) {
queries . remove ( checkNotNull ( configKey , "configKey ") ) ;
queries . remove ( checkNotNull ( name , "name ") ) ;
if ( values ! = null & & values . length > 0 & & values [ 0 ] ! = null ) {
if ( values ! = null & & values . length > 0 & & values [ 0 ] ! = null ) {
ArrayList < String > encoded = new ArrayList < String > ( ) ;
ArrayList < String > encoded = new ArrayList < String > ( ) ;
for ( String value : values ) {
for ( String value : values ) {
encoded . add ( encodeIfNotVariable ( value ) ) ;
encoded . add ( encodeIfNotVariable ( value ) ) ;
}
}
this . queries . put ( encodeIfNotVariable ( configKey ) , encoded ) ;
this . queries . put ( encodeIfNotVariable ( name ) , encoded ) ;
}
}
return this ;
return this ;
}
}
/* @see #query(String, String...) */
/* @see #query(String, String...) */
public RequestTemplate query ( String configKey , Iterable < String > values ) {
public RequestTemplate query ( String name , Iterable < String > values ) {
if ( values ! = null ) {
if ( values ! = null ) {
return query ( configKey , toArray ( values , String . class ) ) ;
return query ( name , toArray ( values , String . class ) ) ;
}
}
return query ( configKey , ( String [ ] ) null ) ;
return query ( name , ( String [ ] ) null ) ;
}
}
private String encodeIfNotVariable ( String in ) {
private String encodeIfNotVariable ( String in ) {