📄 webflowdictionary.java
字号:
/*
* Copyright (c) 2003-2004, Alexander Greif
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Flow4J-Eclipse project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.orthanc.flow4j.runtime.web;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import net.orthanc.flow4j.runtime.FlowDictionary;
/**
* Class WebFlowDictionary TODO
* @author agreif
*
*/
public class WebFlowDictionary extends FlowDictionary {
/**
* Looks for a key in the following containers, in the following order:
* <ol>
* <li>flow dictionary</li>
* <li>HTTP request</li>
* <li>HTTP session, if one exist</li>
* </ol>
* If the dictionary contains no session, then tries to get the
* session from the request.
* @see net.orthanc.flow4j.runtime.FlowDictionary#containsKey(java.lang.String)
*/
public boolean extContainsKey(String key) {
if (containsKey(key))
return true;
HttpServletRequest request =
(HttpServletRequest) get(Flow4JRuntimeWebConsts
.DICT_KEY_SERVLET_REQUEST);
if (request.getParameterValues(key) != null)
return true;
HttpSession session =
(HttpSession) get(Flow4JRuntimeWebConsts.DICT_KEY_HTTP_SESSION);
if (session == null)
session = request.getSession(false);
if (session != null && session.getAttribute(key) != null)
return true;
return false;
}
/**
* Returns the value of the key in the following containers, in the following order:
* <ol>
* <li>flow dictionary</li>
* <li>HTTP request</li>
* <li>HTTP session, if one exist</li>
* </ol>
* If the dictionary contains no session, then tries to get the
* session from the request.
* @see net.orthanc.flow4j.runtime.FlowDictionary#get(java.lang.String)
*/
public Object extGet(String key)
throws ClassCastException, NullPointerException {
Object result;
result = get(key);
if (result != null)
return result;
HttpServletRequest request =
(HttpServletRequest) get(Flow4JRuntimeWebConsts
.DICT_KEY_SERVLET_REQUEST);
result = request.getParameterValues(key);
if (result != null)
return result;
HttpSession session =
(HttpSession) get(Flow4JRuntimeWebConsts.DICT_KEY_HTTP_SESSION);
if (session == null)
session = request.getSession(false);
if (session != null) {
result = session.getAttribute(key);
if (result != null)
return result;
}
return null;
}
/**
* Returns the Dictionary Contents.
*/
public String toString() {
StringBuffer buf = new StringBuffer(super.toString());
buf.append("Servlet request contents:\n");
HttpServletRequest request =
(HttpServletRequest) obj(Flow4JRuntimeWebConsts
.DICT_KEY_SERVLET_REQUEST);
for (Enumeration iter = request.getParameterNames();
iter.hasMoreElements();
) {
String key = (String) iter.nextElement();
String[] values = request.getParameterValues(key);
for (int i = 0; i < values.length; i++) {
buf.append(" ").append(key).append(" = ").append(
values[i]).append(
"\n");
}
}
buf.append("HTTP Session contents:\n");
HttpSession session =
(HttpSession) obj(Flow4JRuntimeWebConsts.DICT_KEY_HTTP_SESSION);
for (Enumeration iter = session.getAttributeNames();
iter.hasMoreElements();
) {
String key = (String) iter.nextElement();
Object value = session.getAttribute(key);
buf.append(" ").append(key).append(" = ").append(value).append(
"\n");
}
return buf.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -