@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 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); }
/** {@inheritDoc} */ public Map<String, Object> getContext(String scope) { return context.getContext(scope); }
tilesRequest.getContext("request").put(ServletRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
/** * Returns the map with custom definitions for the current request. * * @param request The current request. * @return A map that connects a definition name to a definition. */ @SuppressWarnings("unchecked") private Map<String, Definition> getDefinitions( Request request) { return (Map<String, Definition>) request.getContext("request") .get(definitionsAttributeName); }
@Override public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) { Request request = (Request) target; String scope = (String) name; if (scope.endsWith("Scope")) { String scopeName = scope.substring(0, scope.length() - SCOPE_SUFFIX_LENGTH); return request.getContext(scopeName); } return null; }
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); }
/** * Returns a map of type "definition name -> definition" and, if it has not * been defined before, creates one. * * @param request The current request. * @return A map that connects a definition name to a definition. */ @SuppressWarnings("unchecked") private Map<String, Definition> getOrCreateDefinitions( Request request) { Map<String, Definition> definitions = (Map<String, Definition>) request.getContext("request").get(definitionsAttributeName); if (definitions == null) { definitions = new HashMap<String, Definition>(); request.getContext("request") .put(definitionsAttributeName, definitions); } return definitions; }
/** * Sets the current container to use in web pages. * * @param request The request to use. * @param container The container to use as the current container. * @since 2.1.0 */ public static void setCurrentContainer(Request request, TilesContainer container) { if (container != null) { request.getContext("request").put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container); } else { throw new NullPointerException("The container cannot be null"); } }
/** {@inheritDoc} */ @Override public Object getValue(ELContext context, Object base, Object property) { if (base != null) { return null; } Object retValue = null; String propertyString = (String) property; if (property instanceof String && propertyString.endsWith("Scope")) { Request request = (Request) context .getContext(Request.class); retValue = request.getContext(propertyString.substring(0, propertyString.length() - SUFFIX_LENGTH)); } if (retValue != null) { context.setPropertyResolved(true); } return retValue; }
@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); }
/** * Returns the current compose stack, or creates a new one if not present. * * @param request The request. * @return The compose stack. * @since 3.0.0 */ @SuppressWarnings("unchecked") public static Deque<Object> getComposeStack(Request request) { Map<String, Object> requestScope = request.getContext("request"); Deque<Object> composeStack = (Deque<Object>) requestScope .get(COMPOSE_STACK_ATTRIBUTE_NAME); if (composeStack == null) { composeStack = new LinkedList<Object>(); requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack); } return composeStack; } }
@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; }
@Override public void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name, Object value) { Request request = (Request) target; String attributeName = (String) name; String[] availableScopes = request.getAvailableScopes().toArray(new String[0]); for (String scopeName : availableScopes) { Map<String, Object> scope = request.getContext(scopeName); if (scope.containsKey(attributeName)) { scope.put(attributeName, value); return; } } if (availableScopes.length > 0) { request.getContext(availableScopes[0]).put(attributeName, value); } }
/** {@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; } }
protected Map<String,Object> buildScope(Request request) { Map<String,Object> scope = new HashMap<String,Object>(); List<String> availableScopes = request.getAvailableScopes(); for (int i = availableScopes.size() -1; i >= 0; --i) { scope.putAll(request.getContext(availableScopes.get(i))); } return scope; }
@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; }
@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)"; }
/** * 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} */ @Override public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) { List<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>(); Request request = (Request) context .getContext(Request.class); for (String scope : request.getAvailableScopes()) { collectBeanInfo(request.getContext(scope), list); } return list.iterator(); }