org.apache.tiles.request.Request.getContext()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(566)

本文整理了Java中org.apache.tiles.request.Request.getContext方法的一些代码示例,展示了Request.getContext的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getContext方法的具体详情如下:
包路径:org.apache.tiles.request.Request
类名称:Request
方法名:getContext

Request.getContext介绍

[英]Returns a context map, given the scope name. This method always return a map for all the scope names returned by getAvailableScopes(). That map may be writable, or immutable, depending on the implementation.
[中]返回给定作用域名称的上下文映射。此方法始终为getAvailableScopes()返回的所有作用域名称返回一个映射。该映射可能是可写的,也可能是不可变的,具体取决于实现。

代码示例

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public ViewPreparer getPreparer(String name, Request context) {
  3. WebApplicationContext webApplicationContext = (WebApplicationContext) context.getContext("request").get(
  4. DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  5. if (webApplicationContext == null) {
  6. webApplicationContext = (WebApplicationContext) context.getContext("application").get(
  7. WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  8. if (webApplicationContext == null) {
  9. throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
  10. }
  11. }
  12. return getPreparer(name, webApplicationContext);
  13. }

代码示例来源:origin: org.springframework/spring-webmvc

  1. @Override
  2. public ViewPreparer getPreparer(String name, Request context) {
  3. WebApplicationContext webApplicationContext = (WebApplicationContext) context.getContext("request").get(
  4. DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  5. if (webApplicationContext == null) {
  6. webApplicationContext = (WebApplicationContext) context.getContext("application").get(
  7. WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  8. if (webApplicationContext == null) {
  9. throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
  10. }
  11. }
  12. return getPreparer(name, webApplicationContext);
  13. }

代码示例来源:origin: org.apache.tiles/tiles-request-api

  1. /** {@inheritDoc} */
  2. public Map<String, Object> getContext(String scope) {
  3. return context.getContext(scope);
  4. }

代码示例来源:origin: org.springframework.webflow/spring-webflow

  1. tilesRequest.getContext("request").put(ServletRequest.FORCE_INCLUDE_ATTRIBUTE_NAME, true);

代码示例来源:origin: org.apache.tiles/tiles-core

  1. /**
  2. * Returns the map with custom definitions for the current request.
  3. *
  4. * @param request The current request.
  5. * @return A map that connects a definition name to a definition.
  6. */
  7. @SuppressWarnings("unchecked")
  8. private Map<String, Definition> getDefinitions(
  9. Request request) {
  10. return (Map<String, Definition>) request.getContext("request")
  11. .get(definitionsAttributeName);
  12. }

代码示例来源:origin: org.apache.tiles/tiles-ognl

  1. @Override
  2. public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) {
  3. Request request = (Request) target;
  4. String scope = (String) name;
  5. if (scope.endsWith("Scope")) {
  6. String scopeName = scope.substring(0, scope.length() - SCOPE_SUFFIX_LENGTH);
  7. return request.getContext(scopeName);
  8. }
  9. return null;
  10. }

代码示例来源:origin: spring-projects/spring-framework-issues

  1. public ViewPreparer getPreparer(String name, Request context) {
  2. WebApplicationContext webApplicationContext = (WebApplicationContext) context.getContext("request").get(
  3. DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  4. if (webApplicationContext == null) {
  5. webApplicationContext = (WebApplicationContext) context.getContext("application").get(
  6. WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  7. if (webApplicationContext == null) {
  8. throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
  9. }
  10. }
  11. return getPreparer(name, webApplicationContext);
  12. }

代码示例来源:origin: org.apache.tiles/tiles-core

  1. /**
  2. * Returns a map of type "definition name -> definition" and, if it has not
  3. * been defined before, creates one.
  4. *
  5. * @param request The current request.
  6. * @return A map that connects a definition name to a definition.
  7. */
  8. @SuppressWarnings("unchecked")
  9. private Map<String, Definition> getOrCreateDefinitions(
  10. Request request) {
  11. Map<String, Definition> definitions =
  12. (Map<String, Definition>) request.getContext("request").get(definitionsAttributeName);
  13. if (definitions == null) {
  14. definitions = new HashMap<String, Definition>();
  15. request.getContext("request")
  16. .put(definitionsAttributeName, definitions);
  17. }
  18. return definitions;
  19. }

代码示例来源:origin: org.apache.tiles/tiles-api

  1. /**
  2. * Sets the current container to use in web pages.
  3. *
  4. * @param request The request to use.
  5. * @param container The container to use as the current container.
  6. * @since 2.1.0
  7. */
  8. public static void setCurrentContainer(Request request,
  9. TilesContainer container) {
  10. if (container != null) {
  11. request.getContext("request").put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
  12. } else {
  13. throw new NullPointerException("The container cannot be null");
  14. }
  15. }

代码示例来源:origin: org.apache.tiles/tiles-el

  1. /** {@inheritDoc} */
  2. @Override
  3. public Object getValue(ELContext context, Object base, Object property) {
  4. if (base != null) {
  5. return null;
  6. }
  7. Object retValue = null;
  8. String propertyString = (String) property;
  9. if (property instanceof String && propertyString.endsWith("Scope")) {
  10. Request request = (Request) context
  11. .getContext(Request.class);
  12. retValue = request.getContext(propertyString.substring(0,
  13. propertyString.length() - SUFFIX_LENGTH));
  14. }
  15. if (retValue != null) {
  16. context.setPropertyResolved(true);
  17. }
  18. return retValue;
  19. }

代码示例来源:origin: apache/servicemix-bundles

  1. @Override
  2. public ViewPreparer getPreparer(String name, Request context) {
  3. WebApplicationContext webApplicationContext = (WebApplicationContext) context.getContext("request").get(
  4. DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  5. if (webApplicationContext == null) {
  6. webApplicationContext = (WebApplicationContext) context.getContext("application").get(
  7. WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
  8. if (webApplicationContext == null) {
  9. throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?");
  10. }
  11. }
  12. return getPreparer(name, webApplicationContext);
  13. }

代码示例来源:origin: org.apache.tiles/tiles-template

  1. /**
  2. * Returns the current compose stack, or creates a new one if not present.
  3. *
  4. * @param request The request.
  5. * @return The compose stack.
  6. * @since 3.0.0
  7. */
  8. @SuppressWarnings("unchecked")
  9. public static Deque<Object> getComposeStack(Request request) {
  10. Map<String, Object> requestScope = request.getContext("request");
  11. Deque<Object> composeStack = (Deque<Object>) requestScope
  12. .get(COMPOSE_STACK_ATTRIBUTE_NAME);
  13. if (composeStack == null) {
  14. composeStack = new LinkedList<Object>();
  15. requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack);
  16. }
  17. return composeStack;
  18. }
  19. }

代码示例来源:origin: org.apache.tiles/tiles-ognl

  1. @Override
  2. public Object getProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name) {
  3. Request request = (Request) target;
  4. String attributeName = (String) name;
  5. for (String scopeName : request.getAvailableScopes()) {
  6. Map<String, Object> scope = request.getContext(scopeName);
  7. if (scope.containsKey(attributeName)) {
  8. return scope.get(attributeName);
  9. }
  10. }
  11. return null;
  12. }

代码示例来源:origin: org.apache.tiles/tiles-ognl

  1. @Override
  2. public void setProperty(@SuppressWarnings("rawtypes") Map context, Object target, Object name,
  3. Object value) {
  4. Request request = (Request) target;
  5. String attributeName = (String) name;
  6. String[] availableScopes = request.getAvailableScopes().toArray(new String[0]);
  7. for (String scopeName : availableScopes) {
  8. Map<String, Object> scope = request.getContext(scopeName);
  9. if (scope.containsKey(attributeName)) {
  10. scope.put(attributeName, value);
  11. return;
  12. }
  13. }
  14. if (availableScopes.length > 0) {
  15. request.getContext(availableScopes[0]).put(attributeName, value);
  16. }
  17. }

代码示例来源:origin: org.apache.tiles/tiles-core

  1. /** {@inheritDoc} */
  2. public Locale resolveLocale(Request request) {
  3. Locale retValue = null;
  4. Map<String, Object> session = request.getContext("session");
  5. if (session != null) {
  6. retValue = (Locale) session.get(DefaultLocaleResolver.LOCALE_KEY);
  7. }
  8. if (retValue == null) {
  9. retValue = request.getRequestLocale();
  10. }
  11. return retValue;
  12. }
  13. }

代码示例来源:origin: org.apache.tiles/tiles-request-mustache

  1. protected Map<String,Object> buildScope(Request request) {
  2. Map<String,Object> scope = new HashMap<String,Object>();
  3. List<String> availableScopes = request.getAvailableScopes();
  4. for (int i = availableScopes.size() -1; i >= 0; --i) {
  5. scope.putAll(request.getContext(availableScopes.get(i)));
  6. }
  7. return scope;
  8. }

代码示例来源:origin: org.apache.tiles/tiles-ognl

  1. @Override
  2. public String getSourceAccessor(OgnlContext context, Object target,
  3. Object index) {
  4. Request request = (Request) target;
  5. String attributeName = (String) index;
  6. for (String scopeName : request.getAvailableScopes()) {
  7. Map<String, Object> scope = request.getContext(scopeName);
  8. if (scope.containsKey(attributeName)) {
  9. return ".getContext(\"" + scopeName + "\").get(index)";
  10. }
  11. }
  12. return null;
  13. }

代码示例来源:origin: org.apache.tiles/tiles-ognl

  1. @Override
  2. public String getSourceSetter(OgnlContext context, Object target,
  3. Object index) {
  4. Request request = (Request) target;
  5. String attributeName = (String) index;
  6. String[] availableScopes = request.getAvailableScopes().toArray(new String[0]);
  7. for (String scopeName : availableScopes) {
  8. Map<String, Object> scope = request.getContext(scopeName);
  9. if (scope.containsKey(attributeName)) {
  10. return ".getContext(\"" + scopeName + "\").put(index, target)";
  11. }
  12. }
  13. return ".getContext(\"" + availableScopes[0] + "\").put(index, target)";
  14. }

代码示例来源:origin: org.apache.tiles/tiles-api

  1. /**
  2. * Returns the current container that has been set, or the default one.
  3. *
  4. * @param request The request to use.
  5. * @return The current Tiles container to use in web pages.
  6. * @since 2.1.0
  7. */
  8. public static TilesContainer getCurrentContainer(Request request) {
  9. ApplicationContext context = request.getApplicationContext();
  10. Map<String, Object> requestScope = request.getContext("request");
  11. TilesContainer container = (TilesContainer) requestScope.get(CURRENT_CONTAINER_ATTRIBUTE_NAME);
  12. if (container == null) {
  13. container = getContainer(context);
  14. requestScope.put(CURRENT_CONTAINER_ATTRIBUTE_NAME, container);
  15. }
  16. return container;
  17. }
  18. }

代码示例来源:origin: org.apache.tiles/tiles-el

  1. /** {@inheritDoc} */
  2. @Override
  3. public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
  4. Object base) {
  5. List<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>();
  6. Request request = (Request) context
  7. .getContext(Request.class);
  8. for (String scope : request.getAvailableScopes()) {
  9. collectBeanInfo(request.getContext(scope), list);
  10. }
  11. return list.iterator();
  12. }

相关文章