All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ajaxjs.web.ServletHelper Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.3.0
Show newest version
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));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy