Package appl.Portal.Personalize.GUI

Source Code of appl.Portal.Personalize.GUI.PS_ApplicationPage$ErrVector

/*
*  This software and supporting documentation were developed by
*
*    Siemens Corporate Technology
*    Competence Center Knowledge Management and Business Transformation
*    D-81730 Munich, Germany
*
*    Authors (representing a really great team ;-) )
*            Stefan B. Augustin, Thorbj�rn Hansen, Manfred Langen
*
*  This software is Open Source under GNU General Public License (GPL).
*  Read the text of this license in LICENSE.TXT
*  or look at www.opensource.org/licenses/
*
*  Once more we emphasize, that:
*  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  WITHOUT ANY WARRANTY
*  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE OR
*  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR
*  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
*  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
*
*/


// PS_ApplicationPage

// Package
package appl.Portal.Personalize.GUI;

// Imports

// This application
import appl.Portal.Personalize.GUI.*;
import appl.Portal.Personalize.Servlet.*;
import appl.Subscribe.Utils.*;
import appl.Portal.Personalize.DB.*;

// KFM
import KFM.Exceptions.*;
import KFM.GUI.*;
import KFM.GUI.Templates.*;
import KFM.Converter;
import KFM.DB.*;
import KFM.DateTimeServices.*;
import KFM.HTML.FormInputChecker;
import KFM.Language;
import KFM.Smtp;


// JSDK classes
import javax.servlet.*;
import javax.servlet.http.*;

// Java packages
import java.io.*;
import java.util.*;

/** Application Page of PersonalizeSubscribe.
*
* <H2>Related classes</H2>
*
* <P>Cut&paste-source was `Subscribe_ApplicationPage�</P>
*
* @version 0.1 (2001-02-19)
*/
public class PS_ApplicationPage extends    ApplicationPage2
                                implements SubscribeServletInterface
{
    // ************************************************************
    // Constants
    // ************************************************************

    /** String constants for events (HTTP parameter `execute�). */
    private final static PS_Events mEvents = new PS_Events();

    /** String constants for HTTP parameters. */
    private final static PS_Params mParams = new PS_Params();

    /** String constants for HTTP "todo" parameters.
     * Empty. Ignore this class for now.
     */
    private final static PS_Todos mTodos = new PS_Todos();

    // ************************************************************
    // Variables
    // ************************************************************

    /** Servlet properties. */
    PS_Props mServletProps = null;

    /** Set to true after first initialization has been performed. */
    boolean mAlreadyPrepared = false;

    /** The event NEW is used for subscribing a new person (new view) and
     *  when the user enters erroneous information; so that he can correct it
     * (edit view).
     */
    boolean mIsEditView=true;

    //Attributes
    protected  Vector mErrors=null;

    // Template for the registration form
    PortalTemplate mTemplate;

    /** DB.
     *
     * Ask Gusti how this interacts with threading.
     */
    KFM_Database2 mDb;
    KFM_JdbcAdapter mDbA;
    PS_Db mPSDb;

    // ************************************************************
    // Methods
    // ************************************************************

    /** Initialize ApplicationPage.
     *
     * Currently, called by `PS_Servlet�.
     */
    public PS_ApplicationPage (
        PS_Props aServletProps,
        HttpServletRequest aReq)
    {
        // The documentation of `super�'s argument:
        //
        // param aBasicURL
        //   Will be used as command in every CGI call.
        //   Caller gets it from `getContextAndServletPath()�, something like `/kfm-servlet/Portal_Servlet�.
        super(KFM_HttpServletRequest.getContextAndServletPath(aReq), aServletProps);
        setClassName(this);
        mServletProps = aServletProps;
    }

    /** Handle all events.
     *
     * <P>`write� is called by `PS_Servlet.processRequest� to handle all HTTP requests, especially `doGet�
     * and `doPost�. It opens a connection to the DB.
     * Then it calls `prepareRequest�, `transformEvents� and `handleEvent�, which see.</P>
     *
     * @param aUs   The user state, always `null� in P.
     * @param aReq  The HTTP request, it contains the HTTP parameters.
     * @param aRes  The servlet response, it contains the output stream.
     */
    public void write (
        UserState aUs,
        HttpServletRequest aReq,
        HttpServletResponse aRes)
        throws java.io.IOException, KFMException
    {
        super.write(aUs, aReq, aRes);
    }

    /** "First write method": Do initializations.
     *
     * This method handles two kinds of initializations: <BR>
     * (1) Initializations that must be done just once when the servlet starts up,
     *     e.g. loading cached templates. <BR>
     * (2) Initializations that must be done for each event.
     *
     * @param aReq  The HTTP request, it contains the HTTP parameters.
     */
    protected void prepareRequest (
        AuthorizedUserState us,
        KFM_HttpServletRequest aReq)
        throws KFM_SQLException
    {
        // * Initialization - do only once

        if(! mAlreadyPrepared) {
            mDb = new KFM_Database2(
                mServletProps.Log2,
                mServletProps.JdbcDriver,
                mServletProps.JdbcConnectionURL,
                mServletProps.JdbcUser,
                mServletProps.JdbcPassword);

            mAlreadyPrepared = true;
        }

        // * Initialization - do everytime

        mDb.establishConnection("PersonalizeSubscribe");

        mDbA = new KFM_JdbcAdapter(mDb, mLog);
        mDbA.open();

        // Clear autocommit *after* opening the DB Adapter. Really!
        mDb.setAutoCommit(false); /*sic*/
        mPSDb = new PS_Db(mDbA, mLog, mServletProps);

        registerDb(cDbTypeOrdinary,
            mDb, mDbA, mPSDb);

    }
    /** "Second write method": Transform the events.
     *
     * @param aUs   The user state, always `null� in Ex3.
     * @param aReq  The HTTP request, it contains the HTTP parameters.
     */
     protected void transformEvents (
        AuthorizedUserState aUs,
        KFM_HttpServletRequest aReq)
        throws java.io.IOException, KFMException
    {
        //
        // * Set default values for missing required HTTP params
        //
        if(aReq.getParam(mParams.language).equals("")) {
            aReq.replaceParam(mParams.language, "de");
        }

        // in case of authtype=mad or SCD we want the nick in upper case
        String  tAuthType    = aReq.getParam(P_Params.MEMBERS_AUTHTYPE);
        String tNick = aReq.getParam(P_Params.MEMBERS_NICK);

        //
        // * The rules
        //
        // Always use `break lRules� to get out without executing any more rules.
        // I know it's not needed, you could do it with lot's of `else if�s and nested `if�s,
        // but I always get lost in that kind of code. -- ThH
        //
        lRules: {

            // ...

        } // End of `lRules� block.
    }

    /** "Third write method": Handle all events.
     *
     * <P>Consists of one huge <CODE>if</CODE> cascade that selects the event from `execute�.
     * If necessary, it first checks whether the event is allowed for the user in his current roles. Then it calls
     * the right `handle_*� method to do the work. Do not write any "working code"
     * here, put it in a separate `handle_*� method.</P>
     *
     * @param aUs   The user state, always `null� in P.
     * @param aReq  The HTTP request, it contains the HTTP parameters.
     * @param aRes  The servlet response, it contains the output stream.
     */
    protected void handleEvent (
        AuthorizedUserState aUs,
        KFM_HttpServletRequest aReq,
        HttpServletResponse aRes)
        throws java.io.IOException, KFMException, KFM_SQLException
    {
        // Prepare the HTTP response.
        aRes.setContentType(cTextHtml);
        PrintWriter tWriter = aRes.getWriter();

        // Get execute.
        String tExecute = aReq.getParam(mParams.EXECUTE);

        // get authtype
        String tAuthtype = aReq.getParam(P_Params.MEMBERS_AUTHTYPE);

        //
        // THE BIG IF
        //
        if (tExecute.equals(mEvents.PS_Person_Store)) {
            // check for errors in the registration form
            // this is only required for plain registration
            Vector tErrors=new ErrVector();
            if (tAuthtype.equals("plain")){
                tErrors = check(aReq);
            }
            if(tErrors.isEmpty()) {
                handle_PS_Person_Store(aReq, tWriter, aRes);
            } else {
                handle_PS_Person_New(aReq, tWriter, tErrors);
            }
        }else if (tExecute.equals(mEvents.statistic)) {
            handle_Statistic(aUs, aReq, tWriter);
        }else if (tExecute.equals(mEvents.PS_Person_New)) {
            handle_PS_Person_New(aReq, tWriter, /*tErrors*/ new Vector());
        }

        // * Nothing fitted

        else {
            handle_Default(aUs, aReq, tWriter);
        }

    }


    // ************************************************************
    // Handle methods
    // ************************************************************

    /** Default event.
     *
     * Currently never called!
     */
    void handle_Default (
        AuthorizedUserState aUs,
        KFM_HttpServletRequest aReq,
        PrintWriter aWriter)
        throws java.io.IOException, KFMException, KFM_SQLException
    {
        transactionReadOnly();

        String tText =
            "<HTML><HEAD></HEAD><BODY>"
            + "Try: execute='PS_Person_New' or 'PS_Person_Store'<BR>"
            + "</BODY></HTML>";
        aWriter.println(tText);
    }

    /** Subscribe a new person: form to enter user's information.
     *
     * <P>This event is also used when the user enters erroneous information,
     * so that he can correct his errors immediately.</P>
     *
     * @Param aReq
     * @Param aWriter
     * @Param errors  Errors occured.
     */
    public void handle_PS_Person_New (
        KFM_HttpServletRequest aReq,
        PrintWriter aWriter,
        Vector aErrors)
        throws IOException, KFM_SQLException
    {
        transactionReadOnly();

        // We must distinguish between aReq and tReq. -- ThH
        KFM_HttpServletRequest tReq = new KFM_HttpServletRequest(aReq);
        String tLanguage   = tReq.getParam(mParams.language);
        String tAuthType   = tReq.getParam(P_Params.MEMBERS_AUTHTYPE);
        String tNick       = tReq.getParam(P_Params.MEMBERS_NICK);
        String tTrylogin   = tReq.getParam("p_trylogin");
        String tRedirect   = tReq.getParam("p_redirect");
        String tExecute    = tReq.getParam("p_execute");
        String tSessionId  = tReq.getParam("sessionid");
        String tServer     = tReq.getParam("p_location"); // Not "server"!!!
        String tUtask      = tReq.getParam(SessionParam.UTASK);
        String tTcgid      = tReq.getParam(P_Params.MEMBERS_TCGID);
        String tEmail      = tReq.getParam("members_email");
        String tApdPers    = tReq.getParam("members_apd_persnr");
        String tMaident    = tReq.getParam("members_ma_ident");
        String tDN         = tReq.getParam("members_dn");
        String tFile       = tReq.getParam("file");

        // display error messages if a required HTTP parmeter is missing
        if (!_checkForMissingParams(tAuthType, P_Params.MEMBERS_AUTHTYPE, aWriter)){
            return;
        }


        // Create template
        mTemplate = new PortalTemplate(mServletProps.TemplateDir, "Person_New"+tAuthType,
                                       mServletProps.DefaultStylesheet, null);
        mTemplate.startWithLanguage(new Language(tLanguage));

        // Add errors.
        if(! aErrors.isEmpty()) {
            Enumeration enu = aErrors.elements();
            while(enu.hasMoreElements()) {
                String[] tmp = (String[]) enu.nextElement();
                addError(tmp[0], tmp[1]);
            }
        }

        // Add information
        // Fill input text fields
        Hashtable tMapping = PersonalizeDbConsts.getNameGUITypMapping();
        Hashtable tLen     = PersonalizeDbConsts.getNameLenMapping();
        for (Enumeration tKeys = tMapping.keys() ; tKeys.hasMoreElements() ;) {
            String tName = (String)tKeys.nextElement();
            String tParam = tReq.getParameter("members_"+tName); //�es, we want null for not existing parameters
            if ((tParam != null) && !tParam.equals("")){
                // insert value in registration form
                int tGuiType = ((Integer)tMapping.get(tName)).intValue();
                if (tGuiType == PersonalizeDbConsts.cGuiText){
                    mTemplate.replaceAllKfmTextInputField ("INPUT_members_"+tName, "members_"+tName, tParam, tLen.get(tName)+"", false);
                } else if (tGuiType == PersonalizeDbConsts.cGuiPassword){
                    mTemplate.replaceAllKfmInputPassword ("INPUT_members_"+tName, "members_"+tName, tParam, tLen.get(tName)+"", false);
                }
            }
        }

        // In case of SCD and PKI we could have the following scenario:
        // 1) user tries to login
        // 2) P_DBAuthorizedUserstate2 stores user data in user state
        // 3) Personalize Login/get event finds out that user is not registered
        //    in the database and calls PersonalizeSubscribe
        // 4) PersonalizeSubscribe adds profile in database and invokes Personalize
        //    with valid session id and utask
        // Since the STORE event is responsible for invoking the personalize servlet
        // we have to put nick, session and utask in the registration template
        // In addition tcgid, email, apdpersno and maident have to be written to the database
        mTemplate.replaceAllKfm("Nick",      tNick);
        mTemplate.replaceAllKfm("session",   tSessionId);
        mTemplate.replaceAllKfm("p_location",  tServer); // Not "server"!
        mTemplate.replaceAllKfm("utask",     tUtask);
        mTemplate.replaceAllKfm("tcgid",     tTcgid);
        mTemplate.replaceAllKfm("email",     tEmail);
        mTemplate.replaceAllKfm("apdpersno", tApdPers);
        mTemplate.replaceAllKfm("maident",   tMaident);
        mTemplate.replaceAllKfm("dn",        tDN);
        mTemplate.replaceAllKfm("p_execute", tExecute);
        mTemplate.replaceAllKfm("p_redirect",tRedirect);
        mTemplate.replaceAllKfm("file",      tFile);


        // Fill "enter password twice" text field
        String tParam = tReq.getParameter("members_password_2"); //�es, we want null for not existing parameters
        if ((tParam != null) && !tParam.equals("")){
        // insert value in registration form
            mTemplate.replaceAllKfmInputPassword ("INPUT_members_password_2", "members_password_2", tParam, "32", false);
        }


        // Fill language select box
        String tMemberLanguage = tReq.getParameter("members_language");
        if (tMemberLanguage != null){
            String [] tLangValues={"en", "de"};
            String [] tGermanLangTexts={"Englisch", "Deutsch"};
            String [] tEnglishLangTexts={"English", "German"};
            String[] tLangTexts = tLanguage.equals("de")
                ? tGermanLangTexts
                : tEnglishLangTexts;
            mTemplate.replaceAllKfmSelect ("Select_members_language", "members_language", tLangValues,
                                           tLangTexts, tMemberLanguage);
        }

        // Fill resolution select box
        String tResolution = tReq.getParameter("members_resolution");
        if (tResolution != null){
            String [] tResValues={"800x600", "1024x768", "1152x864", "1280x1024"};
            String [] tResTexts={"800x600 Pixel", "1024x768 Pixel", "1152x864 Pixel", "1280x1024 Pixel"};
            mTemplate.replaceAllKfmSelect ("Select_members_resolution", "members_resolution", tResValues,
                                           tResTexts, tResolution);
        }
        mTemplate.replaceAllKfmIf("UserTriedLoginWithoutRegistration", tTrylogin.equals("yes"));


        // Output.
        execute();
        aWriter.println(mTemplate.writeToString());

        // autocommitted
    }

    /** Store registration data in the database.  Afterwards redirect to the login
     *  event of the Persoanlize Servlet.
     *
     * @Param aReq  Servlet Request
     * @Param aWriter  Servlet Writer
     * @Param aRes  Servlet Response.
     */
    public void handle_PS_Person_Store (
        KFM_HttpServletRequest aReq,
        PrintWriter aWriter,
        HttpServletResponse aRes)
        throws IOException, KFM_SQLException
    {
        // We must distinguish between aReq and tReq. -- ThH
        KFM_HttpServletRequest tReq = new KFM_HttpServletRequest(aReq);

        // IN-Parameters from tReq
        String tSessionId   = tReq.getParam("sessionid");
        String tServer      = tReq.getParam("p_location"); // Not "server"!
        String tUtask       = tReq.getParam("utask");
        String tFile        = tReq.getParam("file");
        String tExecute     = tReq.getParam("p_execute");
        String tRedirect = tReq.getParam("p_redirect");
        String tLanguage = tReq.getParam(mParams.language); // @@@ Quick hack.

        if (tUtask.equals("")){
            tUtask="new";
        }
        String tTcgid     = tReq.getParam("members_tcgid");
        String tEMail     = tReq.getParam("members_email");
        String tApdpersno = tReq.getParam("members_apd_persnr");
        String tMaident   = tReq.getParam("members_ma_ident");
        String tDN        = tReq.getParam("members_dn");


        // Sometimes we get from the Framework the parameter names in upper case, therefore
        // convert the names to lower case
        aReq.paramsToLowerCase();

        String tNick     = tReq.getParam("members_nick");
        String tPassword = tReq.getParam("members_password");
        String tAuthType = tReq.getParam(P_Params.MEMBERS_AUTHTYPE);


        // In case of SCD we do not use the email address as nick in the database, we use the tcgid which
        // we get from the Employee Services !!!
        if (tAuthType.equals("scd")) {
            tEMail=tNick;
            tNick=tTcgid;
        }


        String tUser=tNick;
        // check if nick already exists. If yes, display error message
        if(mPSDb.checkUserProfileExists(tUser, tAuthType)) {
            printRegisteredPage(aWriter, tNick, tLanguage, true);
            transactionRollback();
            return;
        }

        String tIsAvailableInSelectBox = "";
        String tIsAvailableOnLoad = "";

        // If it is a tab, fetch the available values from request.
        if (tNick.startsWith("tab."))
        {
            tIsAvailableInSelectBox = tReq.getParam("members_isAvailableInSelectBox");
            tIsAvailableOnLoad = tReq.getParam("members_isAvailableOnLoad");
        }

        // Clear for all (plain) users.
        tReq.removeParam("members_isAvailableInSelectBox");
        tReq.removeParam("members_isAvailableOnLoad");


        // only in case of authtype=plain we store nick, password and authtype in the database
        if (!tAuthType.equals("plain")){
            tReq.removeParam(P_Params.MEMBERS_PASSWORD);
            tReq.removeParam(P_Params.MEMBERS_AUTHTYPE);
            tReq.removeParam(P_Params.MEMBERS_NICK);
        }

        // Nick does not exist.
        // Try to create the new member.

        // check for each database column (defined in PersonalizeDbConsts) if
        // an HTTP parameter with this name exists. If it exists and the value
        // is not empty we insert the value in the database.
        // The vector tInsertData contains for every column which has to be inserted
        // the name, the new value and the type of the column
        Vector tInsertData = new Vector();
        //first compute the identity
        P_DBEntry tEntry=new P_DBEntry("id", KFM_JdbcAdapter.computeIdentity(), PersonalizeDbConsts.cChar);
        tInsertData.addElement(tEntry);

        Hashtable tMapping = PersonalizeDbConsts.getNameDBTypMapping();
        for (Enumeration tKeys = tMapping.keys() ; tKeys.hasMoreElements() ;) {
            String tName = (String)tKeys.nextElement();
            String tParam = tReq.getParameter("members_"+tName); //�es, we want null for not existing parameters
            if (tParam != null){
                tEntry=new P_DBEntry(tName, tParam, ((Integer)tMapping.get(tName)).intValue());
                tInsertData.addElement(tEntry);
            }
        }


        // insert values in the database which are not part of the HTML form
        java.util.Date tDate = new java.util.Date();
        tEntry=new P_DBEntry("date_reg", new KFM_Date(tDate).toIsoString(), PersonalizeDbConsts.cChar);
        tInsertData.addElement(tEntry);

        tEntry=new P_DBEntry("last_modified", new KFM_Date(tDate).toIsoString(), PersonalizeDbConsts.cChar);
        tInsertData.addElement(tEntry);

        tEntry=new P_DBEntry("last_login", new KFM_Date(tDate).toIsoString(), PersonalizeDbConsts.cChar);
        tInsertData.addElement(tEntry);

        tEntry=new P_DBEntry("count_logins", "0" , PersonalizeDbConsts.cInt);
        tInsertData.addElement(tEntry);

        tEntry = new P_DBEntry("isAvailableInSelectBox", tIsAvailableInSelectBox , PersonalizeDbConsts.cInt);
        tInsertData.addElement(tEntry);

        tEntry = new P_DBEntry("isAvailableOnLoad", tIsAvailableOnLoad , PersonalizeDbConsts.cInt);
        tInsertData.addElement(tEntry);

        // at registration time we set the cas_status for pki and scd (not plain)
        // user to "new"
        if (!tAuthType.equals("plain")){
            tEntry=new P_DBEntry("cas_status", "new" , PersonalizeDbConsts.cChar);
            tInsertData.addElement(tEntry);
        }


        // insert data into members database
        String tWhere="";
        if (tAuthType.equals("plain")){
            tWhere="nick";
        } else if (tAuthType.equals("scd") || tAuthType.equals("pki")){
            tWhere="tcgid";
        }

        mPSDb.insertMember(tInsertData, tUser, tWhere);

        // now everything was saved - close the transaction
        transactionCommit();

        // send redirect to login page
        String tRegistrationRedirectUrl = mServletProps.RegistrationRedirectUrl.trim();

        // in case of SCD we store tcgid as nick in the database, but we invoke the
        // login event still with the email address of the user
        if (tAuthType.equals("scd")){
            tNick=tEMail;
        }

        // in case of SCD and PKI we could have the following scenario:
        // 1) user tries to login
        // 2) P_DBAuthorizedUserstate2 stores user data in user state
        // 3) Personalize Login event finds out that user is not registered
        //    in the database and calls PersonalizeSubscribe
        // 4) PersonalizeSubscribe adds profile in database and invokes Personalize
        //    with valid session id and utask
        String tRedirectUrl=tRegistrationRedirectUrl
            // We want `&server=� as early as possible, because CISCO looks for *first*
            // occurence of "server=", and has a length restriction.
            + "&server="+tServer
            + "&redirect="+Converter.quoteURL(tRedirect)
            + "&members_nick="+Converter.quoteURL(tNick)
            + "&language="+Converter.quoteURL(tLanguage)
            + "&members_authtype="+tAuthType
            + "&sessionid="+tSessionId
            + "&execute="+tExecute
            + "&file="+tFile
            + "&utask="+tUtask
            + "&members_dn="+Converter.quoteURL(tDN)
            + "&standalone=no";

        // in case of Plain Login we have to send the password to the personalize servlet
        if (tAuthType.equals("plain")){
            aRes.sendRedirect(tRedirectUrl+"&members_password="+Converter.quoteURL(tPassword));
        } else {
            aRes.sendRedirect(tRedirectUrl);
        }

        return;
    }


    // ************************************************************
    // Helper methods
    // ************************************************************


    /** Check for errors in standalone registration form.
     *
     * @param kfmrep ServletRequest
     * @return ErrorVector
     */
    protected Vector check (KFM_HttpServletRequest aReq)
    {
        //
        // Step one: get parameters from request
        //
        ErrVector tFounderrors = new ErrVector();

        // We must distinguish between aReq and tReq. -- ThH
        KFM_HttpServletRequest tReq = new KFM_HttpServletRequest(aReq);

        // Sometimes we get the parameter names in upper case, therefore
        // convert the names to lower case
        tReq.paramsToLowerCase();

        // IN-Parameters from tReq
        Language tLanguage       = new Language("members_language"); // @@@ Quick hack.

        String  tNick            = tReq.getParam("members_nick");
        String  tPassword        = tReq.getParam("members_password");
        String  tPassword_2      = tReq.getParam("members_password_2");
        String  tReminder        = tReq.getParam("members_reminder");

        String  tLastname        = tReq.getParam("members_last_name");
        String  tFirstname       = tReq.getParam("members_first_name");
        String  tEMail           = tReq.getParam("members_email");
        String  tPhone           = tReq.getParam("members_phone");

        String  tUnit            = tReq.getParam("members_unit");
        String  tLocation        = tReq.getParam("members_location");

        //
        // Step two: check words for existance and correctness
        //

        // `g == true� for German, `g == false� for English.
        boolean g = tLanguage.isGerman();

        String NOVALIDNAME, OBLIGATORY, NOVALIDEMAIL, NOVALIDNUMBER;
        if(g) {
            NOVALIDNAME   = " ist kein g�ltiger Name.";
            OBLIGATORY    = " ist obligatorisch.";
            NOVALIDEMAIL  = " ist keine g�ltige Email Adresse.";
            NOVALIDNUMBER = " ist keine g�ltige Telefonnummer.";
        } else {
            // Default language english.
            NOVALIDNAME   = " is not a valid name.";
            OBLIGATORY    = " is obligatory.";
            NOVALIDEMAIL  = " is not a valid email address.";
            NOVALIDNUMBER = " is not a valid telefon number.";
        }

        // check first name
        if(tFirstname.equals("")) {
            tFounderrors.addError("Input_members_first_name",
                    (g ? "Vorname:" : "First Name:") + OBLIGATORY);
        } else if(! FormInputChecker.isNameCorrect(tFirstname)) {
            tFounderrors.addError("Input_members_first_name",
                (g ? "Vorname:" : "First Name:") + tFirstname + NOVALIDNAME);
        }

        // check last name
        if(tLastname.equals("")) {
            tFounderrors.addError("Input_members_last_name",
                    (g ? "Nachname:" : "Last Name:") + OBLIGATORY);
        } else if(! FormInputChecker.isNameCorrect(tLastname)) {
            tFounderrors.addError("Input_members_last_name",
                (g ? "Nachname:" : "Last Name:") + tLastname + NOVALIDNAME);
        }


        // check phone
        if(! FormInputChecker.isCorrectPhone(tPhone)) {
            tFounderrors.addError("Input_members_phone",
                (g ? "Telefon: " : "Phone: ") + tPhone + NOVALIDNUMBER);
        }

        // check email
        if(tEMail.equals("")) {
            tFounderrors.addError("Input_members_email",
                (g ? "E-mail" : "e-mail:") + OBLIGATORY);
        } else if(! FormInputChecker.isCorrectEmail(tEMail)) {
            tFounderrors.addError("Input_members_email",
                (g ? "E-mail" : "e-mail:") + tEMail + NOVALIDEMAIL);
        }

        // check department / unit
        if(! FormInputChecker.isNameDigitAmpersandAposCorrect(tUnit)) {
            tFounderrors.addError("Input_members_unit",
                (g ? "Abteilung:" : "Department:") + tUnit + NOVALIDNAME);
        }

        // check location
        if(! FormInputChecker.isNameDigitSlashCorrect(tLocation)) {
            tFounderrors.addError("Input_members_location",
                (g ? "Standort:" : "Location:") + tLocation + NOVALIDNAME);
        }



        // check nickname
        if(tNick.equals("")) {
            tFounderrors.addError("Input_members_nick",
                (g ? "Kennungsname" : "Nickname") + OBLIGATORY);
        } else if (! FormInputChecker.isNameDigitCorrect(tReminder)) {
            tFounderrors.addError("Input_members_reminder",
                (g ? "Kennungsname:" : "Nickname:") + tNick + NOVALIDNAME);
        }

        //check passwords are ok
        if(tPassword.equals("")) {
            tFounderrors.addError("Input_members_password",
                (g ? "Pa�wort" : "Password") + OBLIGATORY);
        }

        if(tPassword_2.equals("")) {
            tFounderrors.addError("Input_members_password_2",
                (g ? "Pa�wort-�berpr�fung" : "Enter password twice ") + OBLIGATORY);
        }

        if((! tPassword_2.equals("")) && (! tPassword.equals("")) &&
           (! tPassword.equals(tPassword_2)))
        {
            tFounderrors.addError("Input_members_password",
                (g ? "Pa�wort und Pa�wort�berpr�fung stimmen nicht �berein."
                 : "Password and Enter password twice do not match."));
        }

        // check reminder
        if(tReminder.equals("")) {
            tFounderrors.addError("Input_members_reminder",
                (g ? "Passwort Hinweis:" : "Password hint:") + OBLIGATORY);
        } else if (! FormInputChecker.isNameDigitCorrect(tReminder)) {
            tFounderrors.addError("Input_members_reminder",
                (g ? "Passwort Hinweis:" : "Password hint:") + tReminder + NOVALIDNAME);
        }


        return tFounderrors;
    }

    /** Adds the needed permissions into DB.
     * Currently unused !!!
     */
    public void createPermissions (
        String aAccountName)
        throws KFM_SQLException
    {
    }

    /** Prints error page when nick already exists.
    */
    public void printRegisteredPage (
        PrintWriter aWriter,
        String  aNick,
        String  aLanguage,
        boolean aAccountAlreadyExists)
        throws  IOException
    {
        KfmTemplate templ = new KfmTemplate(mServletProps.TemplateDir,
            "Page_Error",
            mServletProps.DefaultStylesheet, (Page) null /* no footer required */);
        templ.startWithLanguage(new Language(aLanguage));

        templ.replaceAllKfmIf("AccountAlreadyExists", aAccountAlreadyExists);
        templ.replaceAllKfm("adminEmail", mServletProps.HotlineEmail);
        templ.replaceAllKfm("account", aNick);
        templ.execute();
        aWriter.println(templ.writeToString());
    }


    /** Sends notification email to admin.
     *
     *@param aReq HttpServletrequest
     *@param aNick nickname of the user
     */
     public void sendAdminEmail (
        KFM_HttpServletRequest aReq,
        String aNick)
    {
    }


    /**
     * Insert an error in current form. The error references to the label label.
     * <br>
     * The shown errormessage is theSring
     * <p>
     *
     * @param label reference to the template
     * @param theString Errormessage
     */

    public void addError(String label,String theString)
    {
        if(label==null || label.equals(""))
            addError(theString);
        else
        {
            if(mErrors==null)
                mErrors=new Vector(2);
            mErrors.addElement(new String("<a href=\"#" + label + "\">" + theString + "</a>"));
        }
    }//addError

    public void addError(String theString)
    {
        if(mErrors==null)
            mErrors=new Vector(2);
        mErrors.addElement(theString);
    }//addError


    public void execute()
    {
        String tAction;
        String tValue;

        //if thre are some errors show them
        if(mErrors!=null)
        {
            String tErrString="<ul>\n";
            Enumeration enum=mErrors.elements();
            while(enum.hasMoreElements())
                tErrString+="<li>"+enum.nextElement()+"\n</li><br>";
            tErrString+="</ul>\n";
            mTemplate.replaceAllKfm("errors", tErrString);
        }
        mTemplate.replaceAllKfmIf("correctInput",mErrors==null);
        mTemplate.replaceAllKfmIf("wrongInput",mErrors!=null);


        mTemplate.execute();
    }//end execute


    // ************************************************************
    // Inner classes
    // ************************************************************

    /** Helper class for reporting errors.
     */
    private static class ErrVector extends Vector
    {
        private void addError (
            String one,
            String two)
        {
            this.addElement(new String[] { one, two });
        }
    }

    /** Checks if a required HTTP param exists. If not an error message will be displayed.
     * @param aParam current value of the param
     * @param aName  name of the param
     */
    private boolean _checkForMissingParams(String aParam, String aName, PrintWriter aWriter)
        throws IOException
    {
        if (aParam.equals("")){
            _displayErrorMsg ("Parameter '"+aName+"' is missing", aWriter);
            mLog.info("Parameter "+aName+" is missing");
            return false;
        }
        return true;
    }

    /**
     * A helper method to display HTML error messages
     * @param aError The text which should be displayed
     * @param aWriter   The writer
     */
    private void _displayErrorMsg (
        String aError, PrintWriter aWriter)
        throws IOException
    {
        aWriter.println("<HTML><HEAD><TITLE>Personalize</TITLE></HEAD><BODY BGCOLOR=\"white\">");
        aWriter.println("<H2> Error </H2>");
        aWriter.println(aError);
        aWriter.println("</BODY></HTML>");
    }

}
TOP

Related Classes of appl.Portal.Personalize.GUI.PS_ApplicationPage$ErrVector

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.