ELHelper { public static ResourceExpression getExpressionFromEL(String el) { List<String> keys = ELHelper.getELKeys(el); if (keys != null) { ResourceExpression expr = new ResBeanExpression(); Object value = null; for (int i = 1; i < keys.size(); i++) { String key = keys.get(i); value = expr.get(key); if (value instanceof ResourceExpression) { expr = (ResourceExpression) value; } else if (value != null) { break; } } if (value instanceof ResourceExpression) { return (ResourceExpression)value; } } return null; }  static String getRealPathFromEL(String el); static ResourceExpression getExpressionFromEL(String el); static List<String> getELKeys(String el);  }
@Test public void testEL() { Assert.assertEquals("[res]", el("res")); Assert.assertEquals("[res]", el("${res}")); Assert.assertEquals("[res, js, local, sample_js]", el("${res.js.local.sample_js}")); Assert.assertEquals("[res, js, local, sample_js]", el("res.js.local.sample_js")); Assert.assertEquals("[res, js, local, /sample/sample.js]", el("${res.js.local[\"/sample/sample.js\"]}")); Assert.assertEquals("[res, js, local, /sample/sample.js]", el("${res.js.local['/sample/sample.js']}")); Assert.assertEquals("[res, js, local, /sam-ple/s.ample.js]", el("${res.js.local['/sam-ple/s.ample.js']}")); Assert.assertEquals(null, el("['res")); Assert.assertEquals(null, el("[\"res")); Assert.assertEquals("[res]", el("[\"res\"]")); Assert.assertEquals("[res]", el("['res']")); Assert.assertEquals("[d, d'test]", el("${d['d'test']}")); Assert.assertEquals("[res, js, local, /sample/sample.js]", el("${res.js.['local']['/sample/sample.js']}")); Assert.assertEquals("[res, js, local, /sample/sample.js]", el("${res.js.[\"local\"][\"/sample/sample.js\"]}")); Assert.assertEquals("[res, img, local, tabweb, src, img, subcategories-arrow.gif]", el("${res.img.local.tabweb.src.img[\"subcategories-arrow.gif\"]}")); Assert.assertEquals("[res, flash, local, flash2.swf, flash2_test_swf]", el("res.flash.local['flash2.swf'].flash2_test_swf")); Assert.assertEquals("[res, flash, local, flash2.swf, flash2_test_swf]", el("res.flash.local[\"flash2.swf\"].flash2_test_swf")); Assert.assertTrue(ELHelper.getExpressionFromEL("res.local.js.sample.sample_js") instanceof ResourceExpression); }