//# 0 errors, 38 messages
//#
/*
    //#securitytokentag.java:1:1: class: net.sourceforge.pebble.web.tagext.SecurityTokenTag
    //#securitytokentag.java:1:1: method: net.sourceforge.pebble.web.tagext.SecurityTokenTag.net.sourceforge.pebble.web.tagext.SecurityTokenTag__static_init
 * Copyright (c) 2003-2005, Simon Brown
 * 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 Pebble 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.sourceforge.pebble.web.tagext;

import net.sourceforge.pebble.web.security.SecurityTokenValidator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;

/**
 * Tag that writes the security token as a hidden input parameter to the request
 * @author James Roper
 */
public class SecurityTokenTag extends TagSupport {
    //#securitytokentag.java:45: method: void net.sourceforge.pebble.web.tagext.SecurityTokenTag.net.sourceforge.pebble.web.tagext.SecurityTokenTag()
    //#input(void net.sourceforge.pebble.web.tagext.SecurityTokenTag()): this
    //#securitytokentag.java:45: end of method: void net.sourceforge.pebble.web.tagext.SecurityTokenTag.net.sourceforge.pebble.web.tagext.SecurityTokenTag()

  /** true if we're rendering for a query */
  private boolean query;

  @Override
  public int doStartTag() throws JspException {
    JspWriter out = pageContext.getOut();
    //#securitytokentag.java:52: method: int net.sourceforge.pebble.web.tagext.SecurityTokenTag.doStartTag()
    //#input(int doStartTag()): this
    //#input(int doStartTag()): this.pageContext
    //#input(int doStartTag()): this.query
    //#output(int doStartTag()): return_value
    //#pre[2] (int doStartTag()): this.pageContext != null
    //#pre[3] (int doStartTag()): (soft) init'ed(this.query)
    //#presumption(int doStartTag()): java.io.Writer:append(...)@57 != null
    //#presumption(int doStartTag()): java.io.Writer:append(...)@60 != null
    //#presumption(int doStartTag()): javax.servlet.jsp.JspWriter:append(...)@57 != null
    //#presumption(int doStartTag()): javax.servlet.jsp.JspWriter:append(...)@59 != null
    //#presumption(int doStartTag()): javax.servlet.jsp.JspWriter:append(...)@60 != null
    //#presumption(int doStartTag()): javax.servlet.jsp.PageContext:getOut(...)@52 != null
    //#presumption(int doStartTag()): javax.servlet.jsp.PageContext:getRequest(...)@53 != null
    //#post(int doStartTag()): return_value == 0
    //#test_vector(int doStartTag()): this.query: {0}, {1}
    //#test_vector(int doStartTag()): javax.servlet.ServletRequest:getAttribute(...)@53: Addr_Set{null}, Inverse{null}
    String token = (String) pageContext.getRequest().getAttribute(SecurityTokenValidator.PEBBLE_SECURITY_TOKEN_PARAMETER);
    if (token != null) {
      try {
        if (query) {
          out.append(SecurityTokenValidator.PEBBLE_SECURITY_TOKEN_PARAMETER).append("=").append(token);
        } else {
          out.append("<input type=\"hidden\" name=\"").append(SecurityTokenValidator.PEBBLE_SECURITY_TOKEN_PARAMETER);
          out.append("\" value=\"").append(token).append("\"/>");
        }
      } catch (IOException ioe) {
        throw new JspException(ioe);
      }
    }
    return SKIP_BODY;
    //#securitytokentag.java:66: end of method: int net.sourceforge.pebble.web.tagext.SecurityTokenTag.doStartTag()
  }

  public void setQuery(boolean query) {
    this.query = query;
    //#securitytokentag.java:70: method: void net.sourceforge.pebble.web.tagext.SecurityTokenTag.setQuery(bool)
    //#input(void setQuery(bool)): query
    //#input(void setQuery(bool)): this
    //#output(void setQuery(bool)): this.query
    //#post(void setQuery(bool)): this.query == query
    //#post(void setQuery(bool)): init'ed(this.query)
  }
    //#securitytokentag.java:71: end of method: void net.sourceforge.pebble.web.tagext.SecurityTokenTag.setQuery(bool)
}
    //#output(net.sourceforge.pebble.web.tagext.SecurityTokenTag__static_init): __Descendant_Table[net/sourceforge/pebble/web/tagext/SecurityTokenTag]
    //#output(net.sourceforge.pebble.web.tagext.SecurityTokenTag__static_init): __Dispatch_Table.doStartTag()I
    //#output(net.sourceforge.pebble.web.tagext.SecurityTokenTag__static_init): __Dispatch_Table.setQuery(Z)V
    //#post(net.sourceforge.pebble.web.tagext.SecurityTokenTag__static_init): __Descendant_Table[net/sourceforge/pebble/web/tagext/SecurityTokenTag] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.tagext.SecurityTokenTag__static_init): __Dispatch_Table.doStartTag()I == &doStartTag
    //#post(net.sourceforge.pebble.web.tagext.SecurityTokenTag__static_init): __Dispatch_Table.setQuery(Z)V == &setQuery
    //#securitytokentag.java:: end of method: net.sourceforge.pebble.web.tagext.SecurityTokenTag.net.sourceforge.pebble.web.tagext.SecurityTokenTag__static_init
    //#securitytokentag.java:: end of class: net.sourceforge.pebble.web.tagext.SecurityTokenTag
