/** * Constructor that directly takes the keys/values as parameters. * * @param data The initial data, with alternating keys/values. */ public SoyMapData(Object... data) { this(); put(data); }
/** * Constructor that directly takes the keys/values as parameters. * * @param data The initial data, with alternating keys/values. */ public SoyMapData(Object... data) { this(); put(data); }
/** * Constructor that directly takes the keys/values as parameters. * @param data The initial data, with alternating keys/values. */ public SoyMapData(Object... data) { this(); put(data); }
private void appendId(final SoyMapData root, final HttpSession session) { if (session.getId() != null) { root.put(prefix + "id", session.getId()); } }
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { final String headerName = (String) e.nextElement(); final String requestHeader = request.getHeader(headerName); if (requestHeader != null) { root.put(prefix + headerName, requestHeader); } } }
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { for (final Enumeration e = request.getParameterNames(); e.hasMoreElements();) { final String paramName = (String) e.nextElement(); final String parameter = request.getParameter(paramName); if (parameter != null) { root.put("_request.parameter." + paramName, parameter); } } }
private void appendMaxInactiveInterval(final SoyMapData root, final HttpSession session) { root.put(prefix + "maxInactiveInterval", session.getMaxInactiveInterval()); }
private void appendLastAccessedTime(final SoyMapData root, final HttpSession session) { root.put(prefix + "lastAccessedTime", DateFormat.getDateTimeInstance().format(new Date(session.getLastAccessedTime()))); }
private void appendCreationTime(final SoyMapData root, final HttpSession session) { root.put(prefix + "creationTime", DateFormat.getDateTimeInstance().format(new Date(session.getCreationTime()))); }
public <K, V> SoyMapData convertToSoyMapData(Map<K, V> map) { SoyMapData soyMapData = new SoyMapData(); for (Map.Entry<K, V> entry : map.entrySet()) { String key = entry.getKey().toString(); Object value = entry.getValue(); Object soyValue = convertObject(value); soyMapData.put(key, soyValue); } return soyMapData; }
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { if (request.getCookies() == null) { logger.debug("no cookies!"); return; } for (final Cookie cookie : request.getCookies()) { if (StringUtils.hasLength(cookie.getName())) { final String keyPrefix = prefix + cookie.getName(); root.put(keyPrefix + ".name", cookie.getName()); if (StringUtils.hasLength(cookie.getValue())) { root.put(keyPrefix + ".value", cookie.getValue()); } if (StringUtils.hasLength(cookie.getComment())) { root.put(keyPrefix + ".comment", cookie.getComment()); } if (StringUtils.hasLength(cookie.getDomain())) { root.put(keyPrefix + ".domain", cookie.getDomain()); } root.put(keyPrefix + ".maxAge", cookie.getMaxAge()); if (StringUtils.hasLength(cookie.getPath())) { root.put(keyPrefix + ".path", cookie.getPath()); } root.put(keyPrefix + ".version", cookie.getVersion()); root.put(keyPrefix + ".secure", cookie.getSecure()); } } }
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, SoyMapData root) { if (servletContext.getContextPath() != null) { root.put(prefix + "contextPath", servletContext.getContextPath()); } root.put(prefix + "minorVersion", servletContext.getMinorVersion()); root.put(prefix + "majorVersion", servletContext.getMajorVersion()); if (servletContext.getServletContextName() != null) { root.put(prefix + "servletContextName", servletContext.getServletContextName()); } if (servletContext.getServerInfo() != null) { root.put(prefix + "serverInfo", servletContext.getServerInfo()); } for (final Enumeration<String> e = servletContext.getInitParameterNames(); e.hasMoreElements();) { final String paramName = e.nextElement(); final String paramValue = servletContext.getInitParameter(paramName); if (paramValue != null) { root.put(prefix + "parameter." + paramName, paramValue); } } }
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { final WebApplicationContext context = getWebApplicationContext(); if (context.getApplicationName() != null) { root.put(prefix + "applicationName", context.getApplicationName()); } if (context.getDisplayName() != null) { root.put(prefix + "displayName", context.getDisplayName()); } root.put(prefix + "startUp", DateFormat.getDateTimeInstance().format(new Date(context.getStartupDate()))); if (context.getId() != null) { root.put(prefix + "id", context.getId()); } }
@Override public void resolveData(final HttpServletRequest request, final HttpServletResponse response, final Map<String, ? extends Object> model, final SoyMapData root) { final RequestContext requestContext = new RequestContext(request, response, servletContext, (Map<String, Object>) model); if (requestContext.getContextPath() != null) { root.put(prefix + "contextPath", requestContext.getContextPath()); } if (requestContext.getPathToServlet() != null) { root.put(prefix + "pathToServlet", requestContext.getPathToServlet()); } if (requestContext.getQueryString() != null) { root.put(prefix + "queryString", requestContext.getQueryString()); } if (requestContext.getRequestUri() != null) { root.put(prefix + "requestUri", requestContext.getRequestUri()); } if (requestContext.getLocale() != null) { root.put(prefix + "locale", requestContext.getLocale().toString()); } }
/** * Private helper for {@code asMap()} to add a map (or submap) to the combined map data. * @param combinedMapData The combined map data that we're building. * @param keyPrefix The key prefix if adding a submap (or empty string if adding one of the * top-level maps: the base data or the augmented data). * @param map The map of data to add. */ private static void addMapDataHelper( SoyMapData combinedMapData, String keyPrefix, Map<String, SoyData> map) { for (Map.Entry<String, SoyData> entry : map.entrySet()) { String key = entry.getKey(); SoyData value = entry.getValue(); if (value instanceof SoyMapData) { addMapDataHelper(combinedMapData, keyPrefix + key + ".", ((SoyMapData) value).asMap()); } else if (value instanceof SoyListData) { addListDataHelper(combinedMapData, keyPrefix + key + ".", ((SoyListData) value).asList()); } else { combinedMapData.put(keyPrefix + key, value); } } }
/** * Private helper for {@code asMap()} to add a sublist to the combined map data. * @param combinedMapData The combined map data that we're building. * @param keyPrefix The key prefix for this sublist. * @param list The list of data to add. */ private static void addListDataHelper( SoyMapData combinedMapData, String keyPrefix, List<SoyData> list) { for (int i = 0; i < list.size(); ++i) { SoyData el = list.get(i); if (el instanceof SoyMapData) { addMapDataHelper(combinedMapData, keyPrefix + i + ".", ((SoyMapData) el).asMap()); } else if (el instanceof SoyListData) { addListDataHelper(combinedMapData, keyPrefix + i + ".", ((SoyListData) el).asList()); } else { combinedMapData.put(keyPrefix + i, el); } } }