org.apache.velocity.tools.generic.EscapeTool Java Examples
The following examples show how to use
org.apache.velocity.tools.generic.EscapeTool.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenericToolsTests.java From velocity-tools with Apache License 2.0 | 6 votes |
public @Test void testEscapeTool() { EscapeTool escapeTool = (EscapeTool)toolbox.get("esc"); assertNotNull(escapeTool); assertEquals("${esc.d}foo ${esc.h}bar()",escapeTool.velocity("$foo #bar()")); /* propertyKey */ assertEquals("\\ C\\:\\\\Program\\ Files",escapeTool.propertyKey(" C:\\Program Files")); /* propertyValue */ assertEquals("\\ C\\:\\\\Program Files",escapeTool.propertyValue(" C:\\Program Files")); /* java */ assertEquals("\\uFFFF\\b\\n\\t\\f\\r\\\"\\\\",escapeTool.java("\uFFFF\b\n\t\f\r\"\\")); /* javascript */ assertEquals("\\uFFFF\\b\\n\\t\\f\\r\\\"\\'\\\\",escapeTool.javascript("\uFFFF\b\n\t\f\r\"'\\")); /* html */ assertEquals(""&<> ",escapeTool.html("\"&<>"+(char)160)); /* url */ assertEquals("%40%2F%3F%3D+%26",escapeTool.url("@/?= &")); /* sql */ assertEquals("''",escapeTool.sql("'")); /* xml */ assertEquals(""&<>",escapeTool.html("\"&<>")); /* unicode */ assertEquals("\uf00b", escapeTool.unicode("f00b")); assertEquals("\u1010", escapeTool.unicode("\\u1010")); assertEquals("\u1111", escapeTool.unicode(1111)); }
Example #2
Source File: ChartEngineUtil.java From Knowage-Server with GNU Affero General Public License v3.0 | 4 votes |
/** * We are sending additional information about the web application from which we call the VM. This boolean will tell us if we are coming from the Highcharts * Export web application. The value of "exportWebApp" input parameter contains this boolean. This information is useful when we have drilldown, i.e. more * than one category for the Highcharts chart (BAR, LINE). * * @author Danilo Ristovski (danristo, [email protected]) */ public static VelocityContext loadVelocityContext(String jsonToConvert, String jsonData, boolean exportWebApp, String documentLabel, IEngUserProfile profile) { VelocityContext velocityContext = new VelocityContext(); Map<String, Object> mapTemplate = null; Map<String, Object> mapData = null; try { velocityContext.put("datasettransformer", new DataSetTransformer()); velocityContext.put("ChartEngineUtil", ChartEngineUtil.class); velocityContext.put(Integer.class.getSimpleName(), Integer.class); velocityContext.put("escapeTool", new EscapeTool()); if (jsonToConvert != null) { mapTemplate = convertJsonToMap(jsonToConvert, true); velocityContext.put("chart", mapTemplate.get("chart") != null ? mapTemplate.get("chart") : mapTemplate.get("CHART")); } if (jsonData != null) { mapData = convertJsonToMap(jsonData, false); velocityContext.put("data", mapData); } ICrossNavigationDAO crossDao = DAOFactory.getCrossNavigationDAO(); crossDao.setUserProfile(profile); if (crossDao.documentIsCrossable(documentLabel)) { velocityContext.internalPut("crossNavigation", true); } else { velocityContext.internalPut("crossNavigation", ""); } /** * We are sending additional information about the web application from which we call the VM. This boolean will tell us if we are coming from the * Highcharts Export web application. The value of "exportWebApp" input parameter contains this boolean. This information is useful when we have * drilldown, i.e. more than one category for the Highcharts chart (BAR, LINE). * * @author Danilo Ristovski (danristo, [email protected]) */ velocityContext.put("exportWebApp", exportWebApp); } catch (IOException e) { logger.error("Error in template to be converted: " + jsonToConvert, e); } return velocityContext; }
Example #3
Source File: EmailSenderImp.java From swellrt with Apache License 2.0 | 3 votes |
@Override public String getTemplateMessage(Template template, String messageBundleName, Map<String, Object> params, Locale locale) { Map<String, Object> ctx = new HashMap<String, Object>(); if (locale == null) { locale = Locale.getDefault(); } ctx.put("locale", locale); ctx.put(ResourceTool.BUNDLES_KEY, getDecoupledBundleName(messageBundleName)); ctx.put(CustomResourceTool.CLASS_LOADER_KEY, propertyClassloader); Context context = manager.createContext(ctx); Iterator<Map.Entry<String, Object>> it = params.entrySet().iterator(); while (it.hasNext()) { Entry<String, Object> p = it.next(); context.put(p.getKey(), p.getValue()); } context.put("esc", new EscapeTool()); StringWriter sw = new StringWriter(); template.merge(context, sw); sw.flush(); return sw.toString(); }