⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmstaskaction.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsTaskAction.java,v $
 * Date   : $Date: 2005/08/31 07:29:39 $
 * Version: $Revision: 1.7 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2001  The OpenCms Group
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about OpenCms, please see the
 * OpenCms Website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package com.opencms.workplace;

import org.opencms.file.CmsGroup;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsRequestContext;
import org.opencms.file.CmsUser;
import org.opencms.mail.CmsMailTransport;
import org.opencms.mail.CmsSimpleMail;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.util.CmsDateUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.workflow.CmsTask;
import org.opencms.workflow.CmsTaskLog;
import org.opencms.workflow.CmsTaskService;
import org.opencms.workplace.CmsFrameset;

import com.opencms.legacy.CmsLegacyException;

import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Vector;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;

/**
 * This helper-class is used to do task-actions like create or forward. It uses the
 * workplace-languagefile to add task-logs in the language of the user.
 * <P>
 *
 * @author Andreas Schouten
 * @version $Revision: 1.7 $ $Date: 2005/08/31 07:29:39 $
 * @see com.opencms.workplace.CmsXmlWpTemplateFile
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */

public class CmsTaskAction {

    /**
     * Constant for generating user javascriptlist
     */
    private final static String C_ALL_ROLES = "___all";

    /**
     * Accepts a task.
     * @param cms The cms-object.
     * @param int taskid The id of the task.
     * @throws CmsException Throws CmsExceptions, that are be
     * thrown in calling methods.
     */

    public static void accept(CmsObject cms, int taskid) throws CmsException {

        CmsTaskService taskService = cms.getTaskService();
        taskService.acceptTask(taskid);
        String comment = "";
        taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_ACCEPTED);

        // send an email if "Benachrichtigung bei Annahme" was selected.
        CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
        CmsTask task = taskService.readTask(taskid);
        if (taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ACCEPTATION) != null) {
            StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.accept.content"));
            contentBuf.append("\n");
            contentBuf.append(lang.getLanguageValue("task.label.project"));
            contentBuf.append(": ");
            String projectname = "?";
            try {
                projectname = taskService.readTask(task.getRoot()).getName();
            } catch (Exception exc) {

                // no root?!
            }
            contentBuf.append(projectname);
            contentBuf.append("\n");
            contentBuf.append(lang.getLanguageValue("task.label.task"));
            contentBuf.append(": ");
            contentBuf.append(task.getName());
            int projectid = taskService.readProject(task).getId();
            contentBuf.append("\n\n\n" + getTaskUrl(cms, taskid, projectid));
            String subject = lang.getLanguageValue("task.email.accept.subject")
                + " "
                + CmsUser.getFullName(taskService.readAgent(task));
            CmsUser[] users = {taskService.readOwner(task)};
            try {
                CmsSimpleMail mail = createMail(taskService.readAgent(task), users, subject, contentBuf.toString());
                new CmsMailTransport(mail).send();
            } catch (Exception exc) {
                if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
                    CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
                }
            }
        }
    }

    /**
     * Sends a comment to the editor of the task.
     * @param cms The cms-object.
     * @param int taskid The id of the task.
     * @param message The text of the message.
     * @throws CmsException Throws CmsExceptions, that are be
     * thrown in calling methods.
     */

    public static void comment(CmsObject cms, int taskid, String message) throws CmsException {

        CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
        CmsTaskService taskService = cms.getTaskService();
        CmsTask task = taskService.readTask(taskid);
        String comment = "";
        if ((message != null) && (message.length() != 0)) {
            comment += message;
            taskService.writeTaskLog(taskid, comment, CmsWorkplaceDefault.C_TASKLOGTYPE_COMMENT);
        }

        // send an email
        StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.message.content"));
        contentBuf.append("\n");
        contentBuf.append(lang.getLanguageValue("task.label.project"));
        contentBuf.append(": ");
        String projectname = "?";
        try {
            projectname = taskService.readTask(task.getRoot()).getName();
        } catch (Exception exc) {

            // no root?!
        }
        contentBuf.append(projectname);
        contentBuf.append("\n");
        contentBuf.append(lang.getLanguageValue("task.label.task"));
        contentBuf.append(": ");
        contentBuf.append(task.getName());
        contentBuf.append("\n");
        contentBuf.append(lang.getLanguageValue("task.label.actuator"));
        contentBuf.append(": ");
        contentBuf.append(CmsUser.getFullName(taskService.readOwner(task)));
        int projectid = taskService.readProject(task).getId();
        contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));

        contentBuf.append(addTaskText(task, taskService));

        String subject = lang.getLanguageValue("task.email.message.subject")
            + " "
            + CmsUser.getFullName(taskService.readOwner(task));
        CmsUser[] users = {taskService.readAgent(task)};
        try {
            CmsSimpleMail mail = createMail(taskService.readOwner(task), users, subject, contentBuf.toString());
            new CmsMailTransport(mail).send();
        } catch (Exception exc) {
            if (CmsLog.getLog(CmsTaskAction.class).isWarnEnabled()) {
                CmsLog.getLog(CmsTaskAction.class).warn("Error while sending task mail", exc);
            }
        }
    }

    /**
     * Creates a new task.
     * @param cms The cms-object.
     * @param agentName The name of the new editor for this task.
     * @param roleName The name of the new role for the user.
     * @param taskName The new name of the task.
     * @param taskcomment The new comment for this task.
     * @param timeoutString The new timeout-date as a string in the following format:
     * "dd.mm.yyyy"
     * @param priorityString the new priority as String ("1" = high,
     * "2" = normal or "3" = low)
     * @param paraAcceptation controls if a message should be send by acceptation. ("checked" | "")
     * @param paraAll controls if a message should be send to all users in a role. ("checked" | "")
     * @param paraCompletion controls if a message should be send by completing this task. ("checked" | "")
     * @param paraDelivery controls if a message should be send by delivering a task. ("checked" | "")
     * @throws CmsException Throws CmsExceptions, that are be
     * thrown in calling methods.
     */

    public static void create(
        CmsObject cms,
        String agentName,
        String roleName,
        String taskName,
        String taskcomment,
        String timeoutString,
        String priorityString,
        String paraAcceptation,
        String paraAll,
        String paraCompletion,
        String paraDelivery) throws CmsException {

        CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
        // TODO: CW: check effects of this
        // if(roleName.equals(C_ALL_ROLES)) {
        //     roleName = cms.readUser(agentName).getDefaultGroup().getName();
        //}

        // try to create the task
        int priority = Integer.parseInt(priorityString);

        // create a long from the overgiven date.
        String splittetDate[] = CmsStringUtil.splitAsArray(timeoutString, '.');
        GregorianCalendar cal = new GregorianCalendar(
            Integer.parseInt(splittetDate[2]),
            Integer.parseInt(splittetDate[1]) - 1,
            Integer.parseInt(splittetDate[0]),
            0,
            0,
            0);
        long timeout = cal.getTime().getTime();
        CmsTaskService taskService = cms.getTaskService();
        CmsTask task = taskService.createTask(agentName, roleName, taskName, timeout, priority);
        taskService.setTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ACCEPTATION, paraAcceptation);
        taskService.setTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ALL, paraAll);
        taskService.setTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_COMPLETION, paraCompletion);
        taskService.setTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_DELIVERY, paraDelivery);
        String comment = lang.getLanguageValue("task.label.forrole") + ": " + roleName + "\n";
        comment += lang.getLanguageValue("task.label.editor")
            + ": "
            + CmsUser.getFullName(cms.readUser(task.getAgentUser()))
            + "\n";
        comment += taskcomment;
        taskService.writeTaskLog(task.getId(), comment, CmsWorkplaceDefault.C_TASKLOGTYPE_CREATED);

        // send an email
        // per default send a mail from task's organizer to task's recipient.
        StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.create.content"));
        contentBuf.append("\n");
        contentBuf.append(lang.getLanguageValue("task.label.project"));
        contentBuf.append(": ");
        String projectname = "?";
        try {
            projectname = taskService.readTask(task.getRoot()).getName();
        } catch (Exception exc) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -