AddUserAction.java :  » Portal » mypersonalizer » es » udc » mypersonalizer » admin » http » controller » actions » usermgnt » Java Open Source

Java Open Source » Portal » mypersonalizer 
mypersonalizer » es » udc » mypersonalizer » admin » http » controller » actions » usermgnt » AddUserAction.java
/*
 * $Header: /export/home/cvsroot/MyPersonalizerRepository/MyPersonalizer/Subsystems/Admin/Sources/es/udc/mypersonalizer/admin/http/controller/actions/usermgnt/AddUserAction.java,v 1.1.1.1 2004/03/25 12:08:38 fbellas Exp $
 * $Revision: 1.1.1.1 $
 * $Date: 2004/03/25 12:08:38 $
 *
 * =============================================================================
 *
 * Copyright (c) 2003, The MyPersonalizer Development Group
 * (http://www.tic.udc.es/~fbellas/mypersonalizer/index.html) at 
 * University Of A Coruna
 * 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 the University Of A Coruna 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 es.udc.mypersonalizer.admin.http.controller.actions.usermgnt;
    
import java.util.Random;
import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

import es.udc.mypersonalizer.kernel.conventions.
    ServiceConventions;
import es.udc.mypersonalizer.kernel.model.properties.Property;
import es.udc.mypersonalizer.kernel.model.properties.CompoundProperty;
import es.udc.mypersonalizer.kernel.model.properties.PropertyStructure;
import es.udc.mypersonalizer.kernel.controller.actions.
    DefaultAction;
import es.udc.mypersonalizer.admin.http.controller.actions.propertyeditor.
    interfaces.PropertyEditorControl;
import es.udc.mypersonalizer.admin.http.controller.actions.util.
    ControllerHelper;

/**
 * This action is the first step for adding a user. It starts the 
 * property editor to edit the new user registration information
 * property.
 *
 * @author  Abel Iago Toral Quiroga
 * @since 1.0
 */
public class AddUserAction extends DefaultAction {

    /** For random identifier generation. */
    /* Seed is current time */
    private static Random randomIdentifierGenerator = 
        new Random(Calendar.getInstance().getTime().getTime());
    
    protected ActionForward doExecute(ActionMapping mapping, ActionForm form, 
            HttpServletRequest request, HttpServletResponse response) 
            throws Exception {
    
        /* Generate a random identifier for user registration 
          information property */
        String randomIdentifier = 
            Long.toString(randomIdentifierGenerator.nextLong());
            
        /* Create an empty user registration information property */
        Property userProperty = createEmptyUserProperty();
            
        /* Attach property to session with its generated identifier */
        HttpSession session = request.getSession(true);
        session.setAttribute(randomIdentifier, userProperty);
            
        /* Let edit the empty property */
        String userRegistrationInformationServiceIdentifier =
            ServiceConventions.
                USER_REGISTRATION_INFORMATION_SERVICE_IDENTIFIER;
        return PropertyEditorControl.start(
                mapping,
                "usersTool.add",
                userRegistrationInformationServiceIdentifier,
                randomIdentifier);
    }
    
    /**
     * Creates an user registration information property with an empty value.
     * the property editor will be used to edit it.
     */
    private Property createEmptyUserProperty() 
        throws Exception {
    
        String serviceIdentifier = 
            ServiceConventions.
                USER_REGISTRATION_INFORMATION_SERVICE_IDENTIFIER;
        
        PropertyStructure propertyStructure = 
            ControllerHelper.createEmptyPropertyStructureValue(
                serviceIdentifier, "");
    
        /* Create the user property */
        PropertyStructure[] propertyValues = 
            new PropertyStructure[] { propertyStructure };
        return (new CompoundProperty(serviceIdentifier,
                                    propertyValues));
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.