com.ajaxjs.web.ServletHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajaxjs-web Show documentation
Show all versions of ajaxjs-web Show documentation
AJAXJS Web aims to full-stack, not only the server-side framework, but also integrates the front-end library. It's written in HTML5 + Java, a successor to the JVM platform, efficient, secure, stable, cross-platform and many other advantages, but it abandoned the traditional enterprise architecture brought about by the large and bloated, emphasizing the lightweight, and fast, very suitable for the Internet fast application.
package com.ajaxjs.web;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.servlet.FilterConfig;
import javax.servlet.ServletConfig;
public class ServletHelper {
/**
* 遍历注解的配置,需要什么类,收集起来,放到一个 hash 之中, Servlet 或 Filter 通用
* @param getInitParameterNames
* @param getValue
* @return
*/
private static Map initParams2map(Supplier> getInitParameterNames,
Function getValue) {
Map map = new HashMap<>();
Enumeration initParams = getInitParameterNames.get();
while (initParams.hasMoreElements()) {
String key = initParams.nextElement();
String value = getValue.apply(key);
map.put(key, value);
}
return map;
}
/**
*
* @param config
* @return
*/
public static Map initFilterConfig2Map(FilterConfig config) {
return initParams2map(() -> config.getInitParameterNames(), key -> config.getInitParameter(key));
}
/**
*
* @param config
* @return
*/
public static Map initServletConfig2Map(ServletConfig config) {
return initParams2map(() -> config.getInitParameterNames(), key -> config.getInitParameter(key));
}
}