@Override public void doTag() { PageContext pageContext = (PageContext) getJspContext(); URLCoder.Builder builder = URLCoder.build(baseUrl); for (int i = 0; i < attrs.size(); i += 2) { builder.queryParam(attrs.get(i), attrs.get(i + 1)); } if (var == null) { JspWriter out = pageContext.getOut(); try { out.print(builder.get()); } catch (IOException ioex) { // ignore } } else { pageContext.setAttribute(var, builder.get()); } } }
public Builder queryParam(final String name, final Object value) { return queryParam(name, value.toString()); }
/** * Creates URL builder with given path that can be optionally encoded. * Since most of the time path is valid and does not require to be encoded, * use this method to gain some performance. When encoding flag is turned off, * provided path is used without processing. * <p> * The purpose of builder is to help with query parameters. All other URI parts * should be set previously or after the URL is built. */ public static Builder build(final String path, final boolean encodePath) { return new Builder(path, encodePath, JoddCore.encoding); }
public Builder queryParam(final String name, final Object value) { return queryParam(name, value.toString()); }
@Test void testUrlBuilder() { assertEquals("http://jodd.org", URLCoder.build("http://jodd.org").get()); assertEquals("http://jodd.org?param=jodd%26java", URLCoder.build("http://jodd.org").queryParam("param", "jodd&java").get()); assertEquals("http://jodd.org?pa%20ram=jodd%2Bjava", URLCoder.build("http://jodd.org").queryParam("pa ram", "jodd+java").get()); assertEquals("/foo?foo=one&bar=two", URLCoder.build("/foo").queryParam("foo", "one").queryParam("bar", "two").get()); }
/** * Creates URL builder with given path that can be optionally encoded. * Since most of the time path is valid and does not require to be encoded, * use this method to gain some performance. When encoding flag is turned off, * provided path is used without processing. * <p> * The purpose of builder is to help with query parameters. All other URI parts * should be set previously or after the URL is built. */ public static Builder build(final String path, final boolean encodePath) { return new Builder(path, encodePath, JoddCore.encoding); }