org.nervousync.beans.servlet.request.RequestAttribute Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of utils-jdk11 Show documentation
Show all versions of utils-jdk11 Show documentation
Java utility collections, development by Nervousync Studio (NSYC)
/*
* Licensed to the Nervousync Studio (NSYC) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.nervousync.beans.servlet.request;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import jakarta.annotation.Nonnull;
import jakarta.servlet.http.HttpServletRequest;
/**
* Parsed request attributes from HttpServletRequest
* 从HttpServletRequest实例对象解析的属性信息
*
* @author Steven Wee [email protected]
* @version $Revision: 1.1.0 $ $Date: Aug 06, 2018 08:56:50 $
*/
public final class RequestAttribute {
/**
* Session ID of current request
* 当前请求的会话ID
*/
private final String sessionId;
/**
* Attributes map of current request
* 当前请求包含的属性映射
*/
private final Map attributeMap;
/**
* Constructor for RequestAttribute
*
* Parse given HttpServletRequest instance, read session id,
* all exists attributes and put attributes key-value map into field attributeMap
*
* RequestAttribute的构造方法
* 解析给定的HttpServletRequest实例对象,读取会话ID,将所有存在的属性键值对放入attributeMap
*
* @param request HttpServletRequest instance, must not be null
* HttpServletRequest实例对象,不允许为null
*/
public RequestAttribute(@Nonnull final HttpServletRequest request) {
this.sessionId = request.getSession().getId();
this.attributeMap = new HashMap<>();
Enumeration e = request.getAttributeNames();
while (e.hasMoreElements()) {
String name = e.nextElement();
this.attributeMap.put(name, request.getAttribute(name));
}
}
/**
* Getter method for Session ID
* 会话ID的Getter方法
*/
public String getSessionId() {
return sessionId;
}
/**
* Getter method for attribute map
* 属性键值映射表的Getter方法
*/
public Map getAttributeMap() {
return attributeMap;
}
}