@Test public void testEscapeSolrQueryFunction() { final VariableResolverImpl resolver = new VariableResolverImpl(); ContextImpl context = new ContextImpl(null, resolver, null, Context.FULL_DUMP, Collections.EMPTY_MAP, null, null); resolver.context = context; Map m= new HashMap(); m.put("query","c:t"); resolver.addNamespace("dataimporter.functions", EvaluatorBag .getFunctionsNamespace(Collections.EMPTY_LIST, null)); resolver.addNamespace("e",m); String s = resolver .replaceTokens("${dataimporter.functions.escapeQueryChars(e.query)}"); org.junit.Assert.assertEquals("c\\:t", s); }
static Map<String, Object> getFunctionsNamespace(final List<Map<String, String>> fn, DocBuilder docBuilder) { final Map<String, Evaluator> evaluators = new HashMap<String, Evaluator>(); evaluators.put(DATE_FORMAT_EVALUATOR, getDateFormatEvaluator()); evaluators.put(SQL_ESCAPE_EVALUATOR, getSqlEscapingEvaluator()); evaluators.put(URL_ENCODE_EVALUATOR, getUrlEvaluator()); evaluators.put(ESCAPE_SOLR_QUERY_CHARS, getSolrQueryEscapingEvaluator()); SolrCore core = docBuilder == null ? null : docBuilder.dataImporter.getCore(); for (Map<String, String> map : fn) { try { evaluators.put(map.get(NAME), (Evaluator) loadClass(map.get(CLASS), core).newInstance()); } catch (Exception e) { wrapAndThrow(SEVERE, e, "Unable to instantiate evaluator: " + map.get(CLASS)); } } return new HashMap<String, Object>() { @Override public String get(Object key) { if (key == null) return null; Matcher m = FORMAT_METHOD.matcher((String) key); if (!m.find()) return null; String fname = m.group(1); Evaluator evaluator = evaluators.get(fname); if (evaluator == null) return null; VariableResolverImpl vri = VariableResolverImpl.CURRENT_VARIABLE_RESOLVER.get(); Context ctx = vri == null ? null : vri.context; return evaluator.evaluate(m.group(2), ctx); } }; }
EvaluatorBag { static Map<String, Object> getFunctionsNamespace(final List<Map<String, String>> fn, DocBuilder docBuilder) { final Map<String, Evaluator> evaluators = new HashMap<String, Evaluator>(); evaluators.put(DATE_FORMAT_EVALUATOR, getDateFormatEvaluator()); evaluators.put(SQL_ESCAPE_EVALUATOR, getSqlEscapingEvaluator()); evaluators.put(URL_ENCODE_EVALUATOR, getUrlEvaluator()); evaluators.put(ESCAPE_SOLR_QUERY_CHARS, getSolrQueryEscapingEvaluator()); SolrCore core = docBuilder == null ? null : docBuilder.dataImporter.getCore(); for (Map<String, String> map : fn) { try { evaluators.put(map.get(NAME), (Evaluator) loadClass(map.get(CLASS), core).newInstance()); } catch (Exception e) { wrapAndThrow(SEVERE, e, "Unable to instantiate evaluator: " + map.get(CLASS)); } } return new HashMap<String, Object>() { @Override public String get(Object key) { if (key == null) return null; Matcher m = FORMAT_METHOD.matcher((String) key); if (!m.find()) return null; String fname = m.group(1); Evaluator evaluator = evaluators.get(fname); if (evaluator == null) return null; VariableResolverImpl vri = VariableResolverImpl.CURRENT_VARIABLE_RESOLVER.get(); Context ctx = vri == null ? null : vri.context; return evaluator.evaluate(m.group(2), ctx); } }; } }
EvaluatorBag { static Map<String, Object> getFunctionsNamespace(final List<Map<String, String>> fn, DocBuilder docBuilder) { final Map<String, Evaluator> evaluators = new HashMap<String, Evaluator>(); evaluators.put(DATE_FORMAT_EVALUATOR, getDateFormatEvaluator()); evaluators.put(SQL_ESCAPE_EVALUATOR, getSqlEscapingEvaluator()); evaluators.put(URL_ENCODE_EVALUATOR, getUrlEvaluator()); evaluators.put(ESCAPE_SOLR_QUERY_CHARS, getSolrQueryEscapingEvaluator()); SolrCore core = docBuilder == null ? null : docBuilder.dataImporter.getCore(); for (Map<String, String> map : fn) { try { evaluators.put(map.get(NAME), (Evaluator) loadClass(map.get(CLASS), core).newInstance()); } catch (Exception e) { wrapAndThrow(SEVERE, e, "Unable to instantiate evaluator: " + map.get(CLASS)); } } return new HashMap<String, Object>() { @Override public String get(Object key) { if (key == null) return null; Matcher m = FORMAT_METHOD.matcher((String) key); if (!m.find()) return null; String fname = m.group(1); Evaluator evaluator = evaluators.get(fname); if (evaluator == null) return null; VariableResolverImpl vri = VariableResolverImpl.CURRENT_VARIABLE_RESOLVER.get(); Context ctx = vri == null ? null : vri.context; return evaluator.evaluate(m.group(2), ctx); } }; }  }
EvaluatorBag { static Map<String, Object> getFunctionsNamespace(final List<Map<String, String>> fn, DocBuilder docBuilder) { final Map<String, Evaluator> evaluators = new HashMap<String, Evaluator>(); evaluators.put(DATE_FORMAT_EVALUATOR, getDateFormatEvaluator()); evaluators.put(SQL_ESCAPE_EVALUATOR, getSqlEscapingEvaluator()); evaluators.put(URL_ENCODE_EVALUATOR, getUrlEvaluator()); evaluators.put(ESCAPE_SOLR_QUERY_CHARS, getSolrQueryEscapingEvaluator()); SolrCore core = docBuilder == null ? null : docBuilder.dataImporter.getCore(); for (Map<String, String> map : fn) { try { evaluators.put(map.get(NAME), (Evaluator) loadClass(map.get(CLASS), core).newInstance()); } catch (Exception e) { wrapAndThrow(SEVERE, e, "Unable to instantiate evaluator: " + map.get(CLASS)); } } return new HashMap<String, Object>() { @Override public String get(Object key) { if (key == null) return null; Matcher m = FORMAT_METHOD.matcher((String) key); if (!m.find()) return null; String fname = m.group(1); Evaluator evaluator = evaluators.get(fname); if (evaluator == null) return null; VariableResolverImpl vri = VariableResolverImpl.CURRENT_VARIABLE_RESOLVER.get(); Context ctx = vri == null ? null : vri.context; return evaluator.evaluate(m.group(2), ctx); } }; }  static Evaluator getSqlEscapingEvaluator(); static Evaluator getSolrQueryEscapingEvaluator(); static Evaluator getUrlEvaluator(); static Evaluator getDateFormatEvaluator(); static List parseParams(String expression, VariableResolver vr); }
EvaluatorBag { static Map<String, Object> getFunctionsNamespace(final List<Map<String, String>> fn, DocBuilder docBuilder) { final Map<String, Evaluator> evaluators = new HashMap<String, Evaluator>(); evaluators.put(DATE_FORMAT_EVALUATOR, getDateFormatEvaluator()); evaluators.put(SQL_ESCAPE_EVALUATOR, getSqlEscapingEvaluator()); evaluators.put(URL_ENCODE_EVALUATOR, getUrlEvaluator()); evaluators.put(ESCAPE_SOLR_QUERY_CHARS, getSolrQueryEscapingEvaluator()); SolrCore core = docBuilder == null ? null : docBuilder.dataImporter.getCore(); for (Map<String, String> map : fn) { try { evaluators.put(map.get(NAME), (Evaluator) loadClass(map.get(CLASS), core).newInstance()); } catch (Exception e) { wrapAndThrow(SEVERE, e, "Unable to instantiate evaluator: " + map.get(CLASS)); } } return new HashMap<String, Object>() { @Override public String get(Object key) { if (key == null) return null; Matcher m = FORMAT_METHOD.matcher((String) key); if (!m.find()) return null; String fname = m.group(1); Evaluator evaluator = evaluators.get(fname); if (evaluator == null) return null; VariableResolverImpl vri = VariableResolverImpl.CURRENT_VARIABLE_RESOLVER.get(); Context ctx = vri == null ? null : vri.context; return evaluator.evaluate(m.group(2), ctx); } }; }  static Evaluator getSqlEscapingEvaluator(); static Evaluator getSolrQueryEscapingEvaluator(); static Evaluator getUrlEvaluator(); static Evaluator getDateFormatEvaluator(); static List parseParams(String expression, VariableResolver vr); static final String DATE_FORMAT_EVALUATOR; static final String URL_ENCODE_EVALUATOR; static final String ESCAPE_SOLR_QUERY_CHARS; static final String SQL_ESCAPE_EVALUATOR; }