@Override public ViewPreparer getPreparer(String name, Request context) { WebApplicationContext webApplicationContext = (WebApplicationContext) context.getContext("request").get( DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (webApplicationContext == null) { webApplicationContext = (WebApplicationContext) context.getContext("application").get( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (webApplicationContext == null) { throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?"); } } return getPreparer(name, webApplicationContext); }
@Override public String getSourceAccessor(OgnlContext context, Object target, Object index) { Request request = (Request) target; String attributeName = (String) index; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return ".getContext(\"" + scopeName + "\").get(index)"; } } return null; }
ApplicationContext tilesAppContext = tilesRequest.getApplicationContext(); BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesAppContext); tilesRequest.getContext("request").put(ServletRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
/** {@inheritDoc} */ public Locale resolveLocale(Request request) { Locale retValue = null; Map<String, Object> session = request.getContext("session"); if (session != null) { retValue = (Locale) session.get(DefaultLocaleResolver.LOCALE_KEY); } if (retValue == null) { retValue = request.getRequestLocale(); } return retValue; } }
/** {@inheritDoc} */ public ApplicationContext getNestedObject(Request obj) { return obj.getApplicationContext(); } }
/** {@inheritDoc} */ public Writer getWriter() throws IOException { return context.getWriter(); }
/** {@inheritDoc} */ public List<String> getAvailableScopes() { return context.getAvailableScopes(); } }
@Override public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { Request request = (Request) target; String attributeName = (String) name; for (String scopeName : request.getAvailableScopes()) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return scope.get(attributeName); } } return null; }
/** * Returns the current container that has been set, or the default one. * * @param request The request to use. * @return The current Tiles container to use in web pages. * @since 2.1.0 */ public static TilesContainer getCurrentContainer(Request request) { ApplicationContext context = request.getApplicationContext(); Map<String, Object> requestScope = request.getContext("request"); TilesContainer container = (TilesContainer) requestScope.get(CURRENT_CONTAINER_ATTRIBUTE_NAME); if (container == null) { container = getContainer(context); requestScope.put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container); } return container; } }
/** {@inheritDoc} */ public ApplicationContext getApplicationContext() { return context.getApplicationContext(); }
/** {@inheritDoc} */ @Override public void render(String value, Request request) throws IOException { char[] array = value.toCharArray(); char[] newArray = new char[array.length]; for (int i = 0; i < array.length; i++) { newArray[array.length - i - 1] = array[i]; } request.getWriter().write(String.valueOf(newArray)); }
/** {@inheritDoc} */ @Override public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { if (base != null) { List<FeatureDescriptor> retValue = Collections.emptyList(); return retValue.iterator(); } List<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>(); Request request = (Request) context .getContext(Request.class); for (String scope : request.getAvailableScopes()) { FeatureDescriptor descriptor = new FeatureDescriptor(); descriptor.setDisplayName(scope + "Scope"); descriptor.setExpert(false); descriptor.setHidden(false); descriptor.setName(scope + "Scope"); descriptor.setPreferred(true); descriptor.setShortDescription(""); descriptor.setValue("type", Map.class); descriptor.setValue("resolvableAtDesignTime", Boolean.FALSE); list.add(descriptor); } return list.iterator(); }
/** {@inheritDoc} */ public Map<String, String> getParam() { return context.getParam(); }
@Override public ViewPreparer getPreparer(String name, Request context) { WebApplicationContext webApplicationContext = (WebApplicationContext) context.getContext("request").get( DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (webApplicationContext == null) { webApplicationContext = (WebApplicationContext) context.getContext("application").get( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (webApplicationContext == null) { throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?"); } } return getPreparer(name, webApplicationContext); }
@Override public String getSourceSetter(OgnlContext context, Object target, Object index) { Request request = (Request) target; String attributeName = (String) index; String[] availableScopes = request.getAvailableScopes().toArray(new String[0]); for (String scopeName : availableScopes) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { return ".getContext(\"" + scopeName + "\").put(index, target)"; } } return ".getContext(\"" + availableScopes[0] + "\").put(index, target)"; }
/** * Sets the current container to use in web pages. * * @param request The request to use. * @param key The key under which the container is stored. * @since 2.1.0 */ public static void setCurrentContainer(Request request, String key) { ApplicationContext applicationContext = request.getApplicationContext(); TilesContainer container = getContainer(applicationContext, key); if (container != null) { request.getContext("request").put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container); } else { throw new NoSuchContainerException("The container with the key '" + key + "' cannot be found"); } }
/** {@inheritDoc} */ public Object evaluate(String expression, Request request) { ELContextImpl context = new ELContextImpl(resolver); context.putContext(Request.class, request); context.putContext(ApplicationContext.class, request.getApplicationContext()); ValueExpression valueExpression = expressionFactory .createValueExpression(context, expression, Object.class); return valueExpression.getValue(context); } }
/** {@inheritDoc} */ @Override public void render(String value, Request request) throws IOException { if (value == null) { throw new CannotRenderException("Cannot render a null string"); } request.getWriter().write(value); }
/** {@inheritDoc} */ public Map<String, Object> getContext(String scope) { return context.getContext(scope); }