com.pureinfo.common.sms.action.SMSSendAction.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.common.sms.action.SMSSendAction.java

Source

/**
 * PureInfo Quake
 * @(#)SMSSendAction.java   1.0 Nov 3, 2005
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.common.sms.action;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForward;

import com.pureinfo.ark.ArkTypes;
import com.pureinfo.ark.auth.model.User;
import com.pureinfo.ark.content.ArkContentHelper;
import com.pureinfo.ark.content.domain.IContentMgr;
import com.pureinfo.ark.interaction.ActionBase;
import com.pureinfo.common.sender.SenderHelper;
import com.pureinfo.force.exception.PureException;
import com.pureinfo.force.lang.MappingString;

/**
 * <P>
 * Created on Nov 3, 2005 4:13:09 PM <BR>
 * Last modified on Nov 3, 2005
 * </P>
 * 
 * @author Freeman.Hu
 * @version 1.0, Nov 3, 2005
 * @since Quake 1.0
 */
public class SMSSendAction extends ActionBase {

    /**
     * @see com.pureinfo.ark.interaction.ActionBase#executeAction()
     */
    public ActionForward executeAction() throws PureException {
        //1. to read parameters
        String sAction = request.getParameter("action");
        if (sAction == null) {
            return mapping.getInputForward();
        }
        String sIds = request.getRequiredParameter("receiveIds", "");
        String sContent = request.getString("body", true);

        //2. to read mapping parameter
        MappingString mappingParameters = new MappingString(mapping.getParameter());
        String sMark = mappingParameters.getTrimed("mark");
        mappingParameters.clear();
        if (sMark == null) {
            throw new PureException(PureException.PARAMETER_REQUIRED,
                    "parameter [mark] missing in mapping config!");
        }

        //3. to send SMS
        sContent = (sContent == null) ? sMark : sContent + sMark;
        String[] idArray = StringUtils.split(sIds, ',');
        IContentMgr mgr = ArkContentHelper.lookupTypeById(ArkTypes.USER).getManagerBean();
        for (int i = 0; i < idArray.length; i++) {
            int nId = Integer.parseInt(idArray[i]);
            User usr = (User) mgr.lookupById(nId);
            String sPhoneNumber = usr.getMobile();
            User admin = (User) loginUser;
            if (sPhoneNumber != null && sPhoneNumber.length() != 0) {
                SenderHelper.getSender(SenderHelper.TYPE_SMS).send(admin.getMobile(), admin.getTrueName(),
                        sPhoneNumber, usr.getTrueName(), "", sContent);
                //                try {
                //                    Thread.sleep(10000);
                //                } catch (Exception ex) {}
            }
        }
        request.setAttribute("url", "../sms/sms-send.jsp");
        return mapping.findForward("success");
    }
}