@Test public void testURLEncodeWithDefault() throws Exception { URLEncodeFunction f = new URLEncodeFunction(); List<Expression> params = Arrays.asList(filterFactory.literal("Value With Spaces")); f.setParameters(params); assertEquals("Value%20With%20Spaces", f.evaluate(null)); }
@Override public Object evaluate(Object feature) { String stringToBeEncoded; try { stringToBeEncoded = getExpression(0).evaluate(feature, String.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - expected type String"); } Boolean formUrlEncode = Boolean.FALSE; if (params.size() == 2) { try { formUrlEncode = getExpression(1).evaluate(feature, Boolean.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #1 - expected type Boolean"); } } try { String encoded = URLEncoder.encode(stringToBeEncoded, "utf-8"); if (!formUrlEncode.booleanValue()) { encoded = encoded.replaceAll("\\+", "%20"); } return encoded; } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - " + e.getMessage()); } }
URLEncodeFunction extends FunctionExpressionImpl { @Override public Object evaluate(Object feature) { String stringToBeEncoded; try { stringToBeEncoded = getExpression(0).evaluate(feature, String.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - expected type String"); } Boolean formUrlEncode = Boolean.FALSE; if (params.size() == 2) { try { formUrlEncode = getExpression(1).evaluate(feature, Boolean.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #1 - expected type Boolean"); } } try { String encoded = URLEncoder.encode(stringToBeEncoded, "utf-8"); if (!formUrlEncode.booleanValue()) { encoded = encoded.replaceAll("\\+", "%20"); } return encoded; } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - " + e.getMessage()); } } }
URLEncodeFunction extends FunctionExpressionImpl { @Override public Object evaluate(Object feature) { String stringToBeEncoded; try { stringToBeEncoded = getExpression(0).evaluate(feature, String.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - expected type String"); } Boolean formUrlEncode = Boolean.FALSE; if (params.size() == 2) { try { formUrlEncode = getExpression(1).evaluate(feature, Boolean.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #1 - expected type Boolean"); } } try { String encoded = URLEncoder.encode(stringToBeEncoded, "utf-8"); if (!formUrlEncode.booleanValue()) { encoded = encoded.replaceAll("\\+", "%20"); } return encoded; } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - " + e.getMessage()); } } URLEncodeFunction(); }
URLEncodeFunction extends FunctionExpressionImpl { @Override public Object evaluate(Object feature) { String stringToBeEncoded; try { stringToBeEncoded = getExpression(0).evaluate(feature, String.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - expected type String"); } Boolean formUrlEncode = Boolean.FALSE; if (params.size() == 2) { try { formUrlEncode = getExpression(1).evaluate(feature, Boolean.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #1 - expected type Boolean"); } } try { String encoded = URLEncoder.encode(stringToBeEncoded, "utf-8"); if (!formUrlEncode.booleanValue()) { encoded = encoded.replaceAll("\\+", "%20"); } return encoded; } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - " + e.getMessage()); } } URLEncodeFunction(); @Override Object evaluate(Object feature); }
URLEncodeFunction extends FunctionExpressionImpl { @Override public Object evaluate(Object feature) { String stringToBeEncoded; try { stringToBeEncoded = getExpression(0).evaluate(feature, String.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - expected type String"); } Boolean formUrlEncode = Boolean.FALSE; if (params.size() == 2) { try { formUrlEncode = getExpression(1).evaluate(feature, Boolean.class); } catch (Exception e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #1 - expected type Boolean"); } } try { String encoded = URLEncoder.encode(stringToBeEncoded, "utf-8"); if (!formUrlEncode.booleanValue()) { encoded = encoded.replaceAll("\\+", "%20"); } return encoded; } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException( "Filter Function problem for function strURLEncode argument #0 - " + e.getMessage()); } } URLEncodeFunction(); @Override Object evaluate(Object feature); static FunctionName NAME; }