webworkmockpagecontext.java

来自「jworks program」· Java 代码 · 共 74 行

JAVA
74
字号
/*
 * Copyright (c) 2002-2003 by OpenSymphony
 * All rights reserved.
 */
package org.softme.jworks.test.util;

import com.mockobjects.servlet.MockPageContext;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 14-Mar-2003
 * Time: 5:52:36 PM
 * To change this template use Options | File Templates.
 */
public class WebWorkMockPageContext extends MockPageContext {
    //~ Instance fields ////////////////////////////////////////////////////////

    private Map attributes = new HashMap();
    private ServletResponse response;

    //~ Methods ////////////////////////////////////////////////////////////////

    public void setAttribute(String s, Object o) {
        if ((s == null) || (o == null)) {
            throw new NullPointerException("PageContext does not accept null attributes");
        }

        this.attributes.put(s, o);
    }

    public Object getAttribute(String key) {
        return attributes.get(key);
    }

    public Object getAttributes(String key) {
        return this.attributes.get(key);
    }

    public void setResponse(ServletResponse response) {
        this.response = response;
    }

    public ServletResponse getResponse() {
        return response;
    }

    public HttpSession getSession() {
        HttpSession session = super.getSession();

        if (session == null) {
            session = ((HttpServletRequest) getRequest()).getSession();
        }

        return session;
    }

    public Object findAttribute(String s) {
        return attributes.get(s);
    }

    public void removeAttribute(String key) {
        this.attributes.remove(key);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?