📄 accounttag.java
字号:
/** * $Header: /home/coolserv/.cvs/coolserv/jive/source/taglib/com/coolservlets/forum/tags/AccountTag.java,v 1.6 2000/12/12 14:58:38 gnielsen Exp $ * $Revision: 1.6 $ * $Date: 2000/12/12 14:58:38 $ * * 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>account</b>, used to modify a 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" and the * user enters a password, they must also enter the password * a second time to confirm their password change. * <p> * Requires that the User be logged in to modify their account. * <p> * Can be nested inside the <b>admin</b> tag so that a user * can be modified using the permissions of the admin user. * <p> * The authorize tag must be used in the JSP prior to using this tag * so that JiveState and JiveRequest are initialized, and to verify * that a real user is logged in. * <p> * Uses the the following HTTP input parameters * <p><ul> * <li><b>modify</b> - name of submit button to use with HTML input form * <li><b>email</b> - users email address * <li><b>password</b> - new password * <li><b>confirm</b> - confirm password if changing to new password * <li><b>name</b> - users real name * <li><b>nameVisible</b> - check box returning "checked" if real name should be visible * <li><b>emailVisible</b> - check box returning "checked" if email address should be visible * </ul> * <p> * Plus any additional parameters as specified in jive.user.properties file. * If a property in jive.user.properties is named "password", that User * property is only changed if a user's password gets changed and they * are not a System, Forum, Group, or User Admin. * <p> * Sets one or more user errors if account modifications fail. * <p> * JSP Tag Lib Descriptor * <p><pre> * <name>account</name> * <tagclass>com.coolservlets.forum.tags.AccountTag</tagclass> * <bodycontent>JSP</bodycontent> * <info>Includes body of tag if account modifications are successful.</info> * <attribute> * <name>id</name> * <required>true</required> * <rtexprvalue>false</rtexprvalue> * </attribute> * <attribute> * <name>confirm</name> * <required>false</required> * <rtexprvalue>false</rtexprvalue> * </attribute> * </pre> * * @see AdminUserTag * @see TagPropertyManager * @see JiveProperty * @see GetJivePropertyTag * @see SetJivePropertyTag * @see JiveState * @see JiveRequest * @see ErrorTag * @see ErrorLoopTag * * @author Glenn Nielsen */public class AccountTag extends TagSupport implements JiveProperty{ private JiveState js = null; private JiveRequest jr = null; private User user = null; // Static user data, can't change username after account created. private String username = null; // Required input parameters private String email = null; // Optional input parameters private String nameVisible = null; private String emailVisible = null; private String password = null; private String confirm = null; private String name = 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; /** * Initializes data for account tag User data and modifies User account * if this is an HTML form submission. * * @throws JspException on system level error * * @return EVAL_BODY_INCLUDE */ 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 account tag could not get jive state."); } // Get the user request information jr = (JiveRequest)pageContext.getAttribute("jiveUserRequest", PageContext.REQUEST_SCOPE); if( jr == null ) { throw new JspException("Jive account tag could not get jive request."); } // If we are nested inside an admin tag, get user to administer try { AdminUserTag at = (AdminUserTag)this.findAncestorWithClass(this, Class.forName("com.coolservlets.forum.tags.AdminUserTag")); user = at.getUser(); } catch(Exception e) { } if( user == null ) { // Get the User data ProfileManager pm = jr.getProfileManager(); try { user = pm.getUser(js.getAuthorization().getUserID()); } catch( UserNotFoundException ex ) { throw new JspException("Jive account tag could not find user."); } } // Make sure user isn't anonymous if( user.isAnonymous() ) { throw new JspException("Jive account tag can not be used by an anonymous user."); } // Get user board name if( user.getUsername() == null ) throw new JspException("Jive account tag, user with id " + user.getID() + " has no name."); username = user.getUsername(); // Save the script variable so JSP author can access user data pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE); // Get the User data and any extended properties Enumeration enum = TagPropertyManager.getUserPropertyNames(); String tmp; String prop; ServletRequest req = pageContext.getRequest(); if( user.getEmail() != null ) email = user.getEmail(); if( user.getName() != null ) name = user.getName(); if( user.isEmailVisible() ) emailVisible = "checked"; if( user.isNameVisible() ) nameVisible = "checked"; // Get values of any extended user properties defined // in jive.user.properties while( enum.hasMoreElements() ) { prop = (String)enum.nextElement(); if( prop.startsWith( "required." ) ) { prop = prop.substring(9); if( (tmp = user.getProperty(prop)) != null ) { required.put(prop,tmp); } else { required.put(prop,""); } } else { if( (tmp = user.getProperty(prop)) != null ) { properties.put(prop,tmp); } else { properties.put(prop,""); } } } if( (tmp = req.getParameter("modify")) == null ) { // First time account info display, so continue on with rest of page return EVAL_BODY_INCLUDE; } // User has submitted a page requesting changes to their user data // Harvest the standard user data input parameters from page email = req.getParameter("email"); password = req.getParameter("password"); confirm = req.getParameter("confirm"); name = req.getParameter("name"); nameVisible = req.getParameter("nameVisible"); emailVisible = req.getParameter("emailVisible");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -