javax.servlet.ServletContext.getAttributeNames()方法的使用及代码示例

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

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

ServletContext.getAttributeNames介绍

[英]Returns an Enumeration containing the attribute names available within this servlet context. Use the #getAttributemethod with an attribute name to get the value of an attribute.
[中]返回一个Enumeration,其中包含此servlet上下文中可用的属性名称。使用带有属性名称的#getAttributemethod获取属性值。

代码示例

代码示例来源:origin: igniterealtime/Openfire

@Override
public Enumeration<String> getAttributeNames()
{
  return proxy.getAttributeNames();
}

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

@Override
protected Set<ConfigurableApplicationContext> findApplicationContexts() {
  Set<ConfigurableApplicationContext> contexts = new LinkedHashSet<>();
  Enumeration<String> attrNames = this.servletContext.getAttributeNames();
  while (attrNames.hasMoreElements()) {
    String attrName = attrNames.nextElement();
    Object attrValue = this.servletContext.getAttribute(attrName);
    if (attrValue instanceof ConfigurableApplicationContext) {
      contexts.add((ConfigurableApplicationContext) attrValue);
    }
  }
  return contexts;
}

代码示例来源:origin: thymeleaf/thymeleaf

@Override
public boolean isEmpty() {
  final Enumeration<String> attributeNames = this.servletContext.getAttributeNames();
  return !attributeNames.hasMoreElements();
}

代码示例来源:origin: org.freemarker/freemarker

public boolean isEmpty() {
  return !servletctx.getAttributeNames().hasMoreElements();
}

代码示例来源:origin: thymeleaf/thymeleaf

@Override
public int size() {
  int size = 0;
  final Enumeration<String> attributeNames = this.servletContext.getAttributeNames();
  while (attributeNames.hasMoreElements()) {
    attributeNames.nextElement();
    size++;
  }
  return size;
}

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

@Override
public Enumeration<String> getAttributeNamesInScope(int scope) {
  switch (scope) {
    case PAGE_SCOPE:
      return getAttributeNames();
    case REQUEST_SCOPE:
      return this.request.getAttributeNames();
    case SESSION_SCOPE:
      HttpSession session = this.request.getSession(false);
      return (session != null ? session.getAttributeNames() : Collections.emptyEnumeration());
    case APPLICATION_SCOPE:
      return this.servletContext.getAttributeNames();
    default:
      throw new IllegalArgumentException("Invalid scope: " + scope);
  }
}

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

/**
 * Find all ServletContext attributes which implement {@link DisposableBean}
 * and destroy them, removing all affected ServletContext attributes eventually.
 * @param sc the ServletContext to check
 */
static void cleanupAttributes(ServletContext sc) {
  Enumeration<String> attrNames = sc.getAttributeNames();
  while (attrNames.hasMoreElements()) {
    String attrName = attrNames.nextElement();
    if (attrName.startsWith("org.springframework.")) {
      Object attrValue = sc.getAttribute(attrName);
      if (attrValue instanceof DisposableBean) {
        try {
          ((DisposableBean) attrValue).destroy();
        }
        catch (Throwable ex) {
          logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex);
        }
      }
    }
  }
}

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

WebApplicationContext wac = getWebApplicationContext(sc);
if (wac == null) {
  Enumeration<String> attrNames = sc.getAttributeNames();
  while (attrNames.hasMoreElements()) {
    String attrName = attrNames.nextElement();

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

@Override
protected Set<ConfigurableApplicationContext> findApplicationContexts() {
  Set<ConfigurableApplicationContext> contexts = new LinkedHashSet<>();
  Enumeration<String> attrNames = this.servletContext.getAttributeNames();
  while (attrNames.hasMoreElements()) {
    String attrName = attrNames.nextElement();
    Object attrValue = this.servletContext.getAttribute(attrName);
    if (attrValue instanceof ConfigurableApplicationContext) {
      contexts.add((ConfigurableApplicationContext) attrValue);
    }
  }
  return contexts;
}

代码示例来源:origin: thymeleaf/thymeleaf

@Override
public Set<String> keySet() {
  final Set<String> keySet = new LinkedHashSet<String>(5);
  final Enumeration<String> attributeNames = this.servletContext.getAttributeNames();
  while (attributeNames.hasMoreElements()) {
    keySet.add(attributeNames.nextElement());
  }
  return keySet;
}

代码示例来源:origin: jersey/jersey

/**
 * Extract context params from {@link ServletContext}.
 *
 * @param servletContext actual servlet context.
 * @return map representing current context parameters.
 */
public static Map<String, Object> getContextParams(final ServletContext servletContext) {
  final Map<String, Object> props = new HashMap<>();
  final Enumeration names = servletContext.getAttributeNames();
  while (names.hasMoreElements()) {
    final String name = (String) names.nextElement();
    props.put(name, servletContext.getAttribute(name));
  }
  return props;
}

代码示例来源:origin: nutzam/nutz

public static String dumpContextAttributes(ServletContext context) {
  StringBuilder sb = new StringBuilder();
  Enumeration<?> en = context.getAttributeNames();
  while (en.hasMoreElements()) {
    String name = (String) en.nextElement();
    sb.append("[" + name + "]: " + context.getAttribute(name) + '\n');
  }
  return sb.toString();
}

代码示例来源:origin: jersey/jersey

/**
 * Extract context params from {@link ServletContext}.
 *
 * @param servletContext actual servlet context.
 * @return map representing current context parameters.
 */
public static Map<String, Object> getContextParams(final ServletContext servletContext) {
  final Map<String, Object> props = new HashMap<>();
  final Enumeration names = servletContext.getAttributeNames();
  while (names.hasMoreElements()) {
    final String name = (String) names.nextElement();
    props.put(name, servletContext.getAttribute(name));
  }
  return props;
}

代码示例来源:origin: thymeleaf/thymeleaf

@Override
public Collection<Object> values() {
  final List<Object> values = new ArrayList<Object>(5);
  final Enumeration<String> attributeNames = this.servletContext.getAttributeNames();
  while (attributeNames.hasMoreElements()) {
    values.add(this.servletContext.getAttribute(attributeNames.nextElement()));
  }
  return values;
}

代码示例来源:origin: thymeleaf/thymeleaf

@Override
public Set<Map.Entry<String,Object>> entrySet() {
  final Set<Map.Entry<String,Object>> entrySet = new LinkedHashSet<Map.Entry<String, Object>>(5);
  final Enumeration<String> attributeNames = this.servletContext.getAttributeNames();
  while (attributeNames.hasMoreElements()) {
    final String key = attributeNames.nextElement();
    final Object value = this.servletContext.getAttribute(key);
    entrySet.add(new MapEntry(key, value));
  }
  return entrySet;
}

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

Map<String, Object> attributeMap = new HashMap<>();
if (servletContext != null) {
  Enumeration<?> attrNameEnum = servletContext.getAttributeNames();
  while (attrNameEnum.hasMoreElements()) {
    String attrName = (String) attrNameEnum.nextElement();

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

/**
 * Find all ServletContext attributes which implement {@link DisposableBean}
 * and destroy them, removing all affected ServletContext attributes eventually.
 * @param sc the ServletContext to check
 */
static void cleanupAttributes(ServletContext sc) {
  Enumeration<String> attrNames = sc.getAttributeNames();
  while (attrNames.hasMoreElements()) {
    String attrName = attrNames.nextElement();
    if (attrName.startsWith("org.springframework.")) {
      Object attrValue = sc.getAttribute(attrName);
      if (attrValue instanceof DisposableBean) {
        try {
          ((DisposableBean) attrValue).destroy();
        }
        catch (Throwable ex) {
          logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'", ex);
        }
      }
    }
  }
}

代码示例来源:origin: nutzam/nutz

public List<String> getAttributeNames() {
  return enum2list(this.getServletContext().getAttributeNames());
}

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

@Override
public Enumeration<String> getAttributeNamesInScope(int scope) {
  switch (scope) {
    case PAGE_SCOPE:
      return getAttributeNames();
    case REQUEST_SCOPE:
      return this.request.getAttributeNames();
    case SESSION_SCOPE:
      HttpSession session = this.request.getSession(false);
      return (session != null ? session.getAttributeNames() : Collections.emptyEnumeration());
    case APPLICATION_SCOPE:
      return this.servletContext.getAttributeNames();
    default:
      throw new IllegalArgumentException("Invalid scope: " + scope);
  }
}

代码示例来源:origin: oblac/jodd

@Override
public void inject(final ServletContext servletContext, final Targets targets) {
  instancesInjector.inject(servletContext, targets);
  final Enumeration<String> attributeNames = servletContext.getAttributeNames();
  while (attributeNames.hasMoreElements()) {
    final String attrName = attributeNames.nextElement();
    targets.forEachTargetAndIn(this, (target, in) -> {
      final String name = in.matchedName(attrName);
      if (name != null) {
        final Object attrValue = servletContext.getAttribute(attrName);
        target.writeValue(name, attrValue, true);
      }
    });
  }
}

相关文章

微信公众号

最新文章

更多

ServletContext类方法