⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createtag.java

📁 这是学习Java必须读懂两套源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * Copyright (C) 2001 Yasna.com. All rights reserved.
 *
 * ===================================================================
 * The Apache Software License, Version 1.1
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. 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.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by
 *        Yasna.com (http://www.yasna.com)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Yazd" and "Yasna.com" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please
 *    contact yazd@yasna.com.
 *
 * 5. Products derived from this software may not be called "Yazd",
 *    nor may "Yazd" appear in their name, without prior written
 *    permission of Yasna.com.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 YASNA.COM OR
 * ITS 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.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of Yasna.com. For more information
 * on Yasna.com, please see <http://www.yasna.com>.
 */

/**
 * Copyright (C) 2000 CoolServlets.com. All rights reserved.
 *
 * ===================================================================
 * The Apache Software License, Version 1.1
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. 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.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by
 *        CoolServlets.com (http://www.coolservlets.com)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Jive" and "CoolServlets.com" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please
 *    contact webmaster@coolservlets.com.
 *
 * 5. Products derived from this software may not be called "Jive",
 *    nor may "Jive" appear in their name, without prior written
 *    permission of CoolServlets.com.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 COOLSERVLETS.COM OR
 * ITS 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.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of CoolServlets.com. For more information
 * on CoolServlets.com, please see <http://www.coolservlets.com>.
 */

package com.Yasna.forum.tags;

import java.util.*;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.http.*;
import com.Yasna.forum.*;
import com.Yasna.forum.tags.*;

/**
 * JSP Tag <b>create</b>, used to create a new Yazd User account.
 * <p>
 * Requires that attribute <b>id</b> be set to the name of a
 * script variable for later use in JSP to retrieve User data
 * using &lt;jsp:getProperty/&gt;.
 * <p>
 * If optional tag attribute <b>confirm</b>="true" users must also enter
 * the password a second time to confirm their password change.
 * <p>
 * If optional tag attribute <b>password</b>="true" users will have a
 * password generated for them automatically.
 * <p>
 * If optional tag attribute <b>login</b>="true" users will automatically
 * be logged in if account is created.
 * <p>
 * If the create succeeds, includes the body of the create tag and
 * user is authorized as if they had logged in.
 * <p>
 * The authorize tag must be used in the JSP prior to using this tag
 * so that YazdState and YazdRequest are initialized.
 * <p>
 * Uses the the following HTTP input parameters
 * <p><ul>
 * <li><b>create</b> - name of submit button to use with HTML input form
 * <li><b>email</b> - users email address
 * <li><b>username</b> - users username (userid)
 * <li><b>password</b> - password
 * <li><b>confirm</b> - confirm password
 * <li><b>name</b> - users real name
 * <li><b>nameVisible</b> - check box returning a value if real name should be visi
ble
 * <li><b>emailVisible</b> - check box returning a value if email address should be
 visible
 * </ul>
 * <p>
 * Plus any additional parameters as specified in yazd.user.properties file.
 * <p>
 * Sets one or more user errors if account creation fail.
 * <p>
 * JSP Tag Lib Descriptor
 * <p><pre>
 * &lt;name&gt;create&lt;/name&gt;
 * &lt;tagclass&gt;com.Yasna.forum.tags.CreateTag&lt;/tagclass&gt;
 * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
 * &lt;info&gt;Includes body of tag if create is successful.&lt;/info&gt;
 *   &lt;attribute&gt;
 *     &lt;name&gt;id&lt;/name&gt;
 *     &lt;required&gt;true&lt;/required&gt;
 *     &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;
 *   &lt;/attribute&gt;
 *   &lt;attribute&gt;
 *     &lt;name&gt;confirm&lt;/name&gt;
 *     &lt;required&gt;false&lt;/required&gt;
 *     &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;
 *   &lt;/attribute&gt;
 *   &lt;attribute&gt;
 *     &lt;name&gt;password&lt;/name&gt;
 *     &lt;required&gt;false&lt;/required&gt;
 *     &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;
 *   &lt;/attribute&gt;
 *   &lt;attribute&gt;
 *     &lt;name&gt;login&lt;/name&gt;
 *     &lt;required&gt;false&lt;/required&gt;
 *     &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;
 *   &lt;/attribute&gt;
 * </pre>
 *
 * @see AuthorizeTag
 * @see TagPropertyManager
 * @see YazdProperty
 * @see GetYazdPropertyTag
 * @see SetYazdPropertyTag
 * @see YazdState
 * @see YazdRequest
 *
 * @see ErrorTag
 * @see ErrorLoopTag
 *
 * @author Glenn Nielsen
 */

public class CreateTag extends TagSupport implements YazdProperty
{
  private Authorization auth = null;
  private YazdState js = null;
  private YazdRequest jr = null;
  private User user = null;
  // Required input Parameters
  private String email = null;
  private String username = null;
  private String password = null;
  // Optional input parameters
  private String confirm = null;
  private String name = null;
  private String nameVisible = null;
  private String emailVisible = null;
  // Extended properties of User as configured in yazd.user.properties
  private Map properties = new HashMap();
  // Required extended properties of User as configured in yazd.user.properties
  private Map required = new HashMap();
  // Flag that we must confirm password if user is setting new password
  // Set by the account tag confirm attribute
  private boolean confirm_password = false;
  // Flag that password will be generated for user
  // Set by the account tag password attribute
  private boolean generate_password = false;
  // Flag that logs in user if account created
  // Set by the account tag login attribute
  private boolean auto_login = false;
  // Flag indicating that account was created
  private boolean created = false;

  /**
   * Creates User account if this is an HTML form submission.
   *
   * @throws JspException on system level error
   *
   * @return <b>SKIP_BODY</b> if a create form was not submitted or create account failed, <b>EVAL_BODY_INCLUDE</b> if account creation succeeded
   */

  public final int doStartTag() throws JspException
  {
    boolean extended_required = true;

    // Get the user state information
    js = (YazdState)pageContext.getAttribute("yazdUserState",
		PageContext.SESSION_SCOPE);
    if( js == null ) {
      throw new JspException("Yazd create tag could not get yazd state.");
    }

    // Get the user request information
    jr = (YazdRequest)pageContext.getAttribute("yazdUserRequest",
                PageContext.REQUEST_SCOPE);
    if( js == null ) {
      throw new JspException("Yazd create tag could not get yazd request.");
    }

    // Save the script variable so JSP author can access user data
    pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE);

    // Get names and default values for any extended user properties defined
    // in yazd.user.properties
    ServletRequest req = pageContext.getRequest();
    Enumeration enum = TagPropertyManager.getUserPropertyNames();
    String tmp;
    String prop;
    String propname;
    while( enum.hasMoreElements() ) {
      prop = (String)enum.nextElement();
      // Set the default value
      if( prop.startsWith( "required." ) ) {
        propname = prop.substring(9);
        required.put(propname,TagPropertyManager.getUserProperty(prop));
      } else {
        properties.put(prop,TagPropertyManager.getUserProperty(prop));
      }
    }

    // See if this is a form submission
    tmp = req.getParameter("create");
    if( tmp == null || tmp.length() == 0 ) {
      // User didn't submit a form, and we are done initializing data
      // Skip body of create tag since account hasn't been created yet
      return SKIP_BODY;
    }

    // User has submitted a page requesting an account be created

    // Harvest the standard user data input parameters from page
    email = req.getParameter("email");
    username = req.getParameter("username");
    password = req.getParameter("password");
    confirm = req.getParameter("confirm");
    name = req.getParameter("name");
    nameVisible = req.getParameter("nameVisible");

⌨️ 快捷键说明

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