📄 createtag.java
字号:
/** * $Header: /home/coolserv/.cvs/coolserv/jive/source/taglib/com/coolservlets/forum/tags/CreateTag.java,v 1.6 2000/12/17 14:14:52 gnielsen Exp $ * $Revision: 1.6 $ * $Date: 2000/12/17 14:14:52 $ * * 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.coolservlets.forum.tags;import java.util.*;import javax.servlet.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;import javax.servlet.http.*;import com.coolservlets.forum.*;import com.coolservlets.forum.tags.*;/** * JSP Tag <b>create</b>, used to create a new Jive 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 <jsp:getProperty/>. * <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 JiveState and JiveRequest 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 visible * <li><b>emailVisible</b> - check box returning a value if email address should be visible * </ul> * <p> * Plus any additional parameters as specified in jive.user.properties file. * <p> * Sets one or more user errors if account creation fail. * <p> * JSP Tag Lib Descriptor * <p><pre> * <name>create</name> * <tagclass>com.coolservlets.forum.tags.CreateTag</tagclass> * <bodycontent>JSP</bodycontent> * <info>Includes body of tag if create is successful.</info> * <attribute> * <name>id</name> * <required>true</required> * <rtexprvalue>false</rtexprvalue> * </attribute> * <attribute> * <name>confirm</name> * <required>false</required> * <rtexprvalue>false</rtexprvalue> * </attribute> * <attribute> * <name>password</name> * <required>false</required> * <rtexprvalue>false</rtexprvalue> * </attribute> * <attribute> * <name>login</name> * <required>false</required> * <rtexprvalue>false</rtexprvalue> * </attribute> * </pre> * * @see AuthorizeTag * @see TagPropertyManager * @see JiveProperty * @see GetJivePropertyTag * @see SetJivePropertyTag * @see JiveState * @see JiveRequest * * @see ErrorTag * @see ErrorLoopTag * * @author Glenn Nielsen */public class CreateTag extends TagSupport implements JiveProperty{ private Authorization auth = null; private JiveState js = null; private JiveRequest 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 jive.user.properties private Map properties = new HashMap(); // Required extended properties of User as configured in jive.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 = (JiveState)pageContext.getAttribute("jiveUserState", PageContext.SESSION_SCOPE); if( js == null ) { throw new JspException("Jive create tag could not get jive state."); } // Get the user request information jr = (JiveRequest)pageContext.getAttribute("jiveUserRequest", PageContext.REQUEST_SCOPE); if( js == null ) { throw new JspException("Jive create tag could not get jive 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 jive.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"); emailVisible = req.getParameter("emailVisible"); // Harvest the input parameters for any required extended properties for( Iterator it=required.keySet().iterator(); it.hasNext(); ) { prop = (String)it.next(); if( (tmp = req.getParameter(prop)) != null && tmp.length() > 0 ) { required.put(prop,tmp); } else { required.put(prop,""); extended_required = false; } } // Harvest the input parameters for any optional extended properties for( Iterator it=properties.keySet().iterator(); it.hasNext(); ) { prop = (String)it.next(); if( (tmp = req.getParameter(prop)) != null ) { properties.put(prop,tmp); } } // Validate required fields, error string comes from jive.tag.properties if( email == null || email.length() == 0 || !extended_required || username == null || username.length() == 0 ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -