Package jodd.servlet.tag

Source Code of jodd.servlet.tag.UnsetTag

// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.servlet.tag;

import javax.servlet.jsp.tagext.SimpleTagSupport;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.http.HttpServletRequest;

/**
* Removes attribute from the scope.
*/
public class UnsetTag extends SimpleTagSupport {

  protected String name;
  private static final String SCOPE_APPLICATION = "application";
  private static final String SCOPE_SESSION = "session";
  private static final String SCOPE_REQUEST = "request";
  private static final String SCOPE_PAGE = "page";

  public void setName(String name) {
    this.name = name;
  }

  protected String scope;

  public void setScope(String scope) {
    this.scope = scope;
  }

  @Override
  public void doTag() throws JspException {
    PageContext pageContext = (PageContext) getJspContext();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    String scopeValue = scope != null ? scope.toLowerCase() : SCOPE_PAGE;
    if (scopeValue.equals(SCOPE_APPLICATION)) {
            request.getSession().getServletContext().removeAttribute(name);
        } else if (scopeValue.equals(SCOPE_SESSION)) {
            request.getSession().removeAttribute(name);
        } else if (scopeValue.equals(SCOPE_REQUEST)) {
            request.removeAttribute(name);
        } else if (scopeValue.equals(SCOPE_PAGE)) {
            pageContext.removeAttribute(name);
        } else {
      throw new JspException("Invalid scope: " + scope);
        }
  }
}
TOP

Related Classes of jodd.servlet.tag.UnsetTag

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.