/** * A partial implementation of URI Template expansion * as specified by the <a href="http://bitworking.org/projects/URI-Templates/spec/draft-gregorio-uritemplate-03.html">URI template specification</a>. * <p/> * The only operation implemented as of today is "Var Substitution". If an expansion template for another operation (join, neg, opt, etc) is found, * an {@link UnsupportedOperationException} will be thrown. * <p/> * See {@link #varSubstitution(String, Object[], java.util.Map)} * * @param uriTemplate the URI template * @param nameValuePairs a Map of <name, value>. Null values are allowed. * @return a copy of uri template in which substitutions have been made (if possible) * @throws URIException if the default protocol charset is not supported * @throws UnsupportedOperationException if the operation is not supported. Currently only var substitution is supported. * @see #varSubstitution(String, Object[], java.util.Map) */ public static String expand(String uriTemplate, Map<String, String> nameValuePairs) throws URIException, UnsupportedOperationException { return expand(uriTemplate, nameValuePairs, false); }
return URITemplate.expandLazily(uriTemplate, pairs); } else { return URITemplate.expand(uriTemplate, pairs);
/** * Same as {@link #expand(String, java.util.Map)} but preserve an expansion template if the corresponding variable * is not defined in the {@code nameValuePairs} map (i.e. map.contains(var)==false). * <br/>Meaning that a template may be returned. * <br/> If a default value exists for the undefined value, it will be used to replace the expansion pattern. * <p/> * <strong>Beware that this behavior deviates from the URI Template specification.</strong> * <p/> * For instance: * <br/>Given the following template variable names and values: * <ul> * <li>bar = java</li> * <li>foo undefined * </ul> * <p/>The following expansion templates will be expanded as shown if {@code preserveUndefinedVar} is true: * <br/>http://example.com/{bar} * <br/>http://example.com/java * <br/> * <br/>{foo=a_default_value} * <br/>a_default_value * <br/> * <br/>http://example.com/{bar}/{foo} * <br/>http://example.com/java/{foo} * * @see #expand(String, java.util.Map) */ public static String expandLazily(String uriTemplate, Map<String, String> nameValuePairs) throws URIException, UnsupportedOperationException { return expand(uriTemplate, nameValuePairs, true); }
/** * Simply build a map from nameValuePairs and pass it to {@link #expand(String, java.util.Map)} * * @param nameValuePairs an array containing of name, value, name, value, and so on. Null values are allowed. * @see # expand (String, java.util.Map) */ public static String expand(String uriTemplate, String... nameValuePairs) throws URIException, UnsupportedOperationException { return expand(uriTemplate, toMap(nameValuePairs)); }