📄 cmstaskaction.java
字号:
* @throws CmsException Throws CmsExceptions, that are be
* thrown in calling methods.
*/
public static void end(CmsObject cms, int taskid) throws CmsException {
cms.endTask(taskid);
String comment = "";
cms.writeTaskLog(taskid, comment, C_TASKLOGTYPE_OK);
// send an email if "Benachrichtigung bei Abhacken" was selected.
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
CmsTask task = cms.readTask(taskid);
if(cms.getTaskPar(task.getId(), C_TASKPARA_COMPLETION) != null) {
StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.end.content"));
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.project"));
contentBuf.append(": ");
String projectname = "?";
try {
projectname = cms.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.taskfor"));
contentBuf.append(": ");
contentBuf.append(Utils.getFullName(cms.readOriginalAgent(task)));
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.editor"));
contentBuf.append(": ");
contentBuf.append(Utils.getFullName(cms.readAgent(task)));
int projectid = cms.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
String subject = lang.getLanguageValue("task.email.end.subject") + " " + Utils.getFullName(cms.readAgent(task));
CmsUser[] users = {
cms.readOwner(task)
};
try {
com.opencms.defaults.CmsMail mail = new com.opencms.defaults.CmsMail(cms, cms.readAgent(task),
users, subject, contentBuf.toString(), "text/plain");
mail.start();
}
catch(Exception exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO, "[CmsTaskAction] error while sending mail "
+ exc.getMessage());
}
}
}
}
/**
* Forwards a task. The task is forwarded to a new editor in a new role.
* @param cms The cms-object.
* @param int taskid The id of the task.
* @param newEditorName The name of the new editor for this task.
* @param newRoleName The name of the new role for the user.
* @throws CmsException Throws CmsExceptions, that are be
* thrown in calling methods.
*/
public static void forward(CmsObject cms, int taskid, String newEditorName, String newRoleName) throws CmsException {
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
CmsUser newEditor = cms.readUser(newEditorName);
if(newRoleName.equals(C_ALL_ROLES)) {
newRoleName = cms.readUser(newEditorName).getDefaultGroup().getName();
}
CmsGroup oldRole = cms.readGroup(newRoleName);
cms.forwardTask(taskid, oldRole.getName(), newEditor.getName());
String comment = lang.getLanguageValue("task.dialog.forward.logmessage");
comment += " " + Utils.getFullName(newEditor);
cms.writeTaskLog(taskid, comment, C_TASKLOGTYPE_FORWARDED);
// send an email if "Benachrichtigung bei Weiterleitung" was selected.
CmsTask task = cms.readTask(taskid);
if(cms.getTaskPar(task.getId(), C_TASKPARA_DELIVERY) != null) {
StringBuffer contentBuf = new StringBuffer(lang.getLanguageValue("task.email.forward.content"));
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.project"));
contentBuf.append(": ");
String projectname = "?";
try {
projectname = cms.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(Utils.getFullName(cms.readOwner(task)));
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.taskfor"));
contentBuf.append(": ");
contentBuf.append(Utils.getFullName(cms.readOriginalAgent(task)));
contentBuf.append("\n");
contentBuf.append(lang.getLanguageValue("task.label.editor"));
contentBuf.append(": ");
contentBuf.append(Utils.getFullName(cms.readAgent(task)));
int projectid = cms.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
String subject = lang.getLanguageValue("task.email.forward.subject") + " " + Utils.getFullName(cms.readUser(task.getAgentUser())) + " / " + newRoleName;
// if "Alle Rollenmitglieder von Aufgabe Benachrichtigen" checkbox is selected.
if(cms.getTaskPar(task.getId(), C_TASKPARA_ALL) != null) {
try {
com.opencms.defaults.CmsMail mail = new com.opencms.defaults.CmsMail(cms, cms.getRequestContext().currentUser(),
cms.readGroup(task), subject, contentBuf.toString(), "text/plain");
mail.start();
}
catch(Exception exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO, "[CmsTaskAction] error while sending mail "
+ exc.getMessage());
}
}
}
else {
// send a mail to user
CmsUser[] user = {
cms.readAgent(task)
};
try {
com.opencms.defaults.CmsMail mail1 = new com.opencms.defaults.CmsMail(cms,
cms.getRequestContext().currentUser(), user, subject, contentBuf.toString(), "text/plain");
mail1.start();
}
catch(Exception exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO, "[CmsTaskAction] error while sending mail " + exc.getMessage());
}
}
// send a mail to owner
CmsUser[] owner = {
cms.readOwner(task)
};
try {
com.opencms.defaults.CmsMail mail2 = new com.opencms.defaults.CmsMail(cms, cms.getRequestContext().currentUser(),
owner, subject, contentBuf.toString(), "text/plain");
mail2.start();
}
catch(Exception exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO,
"[CmsTaskAction] error while sending mail " + exc.getMessage());
}
}
}
}
}
/**
* Gets the description of a task.
* The description is stored in the task-log.
* @param cms The cms-object.
* @param int taskid The id of the task.
* @return String the comment-string.
* @throws CmsException Throws CmsExceptions, that are be
* thrown in calling methods.
*/
public static String getDescription(CmsObject cms, int taskid) throws CmsException {
StringBuffer retValue = new StringBuffer("");
CmsTaskLog tasklog;
Vector taskdocs = cms.readTaskLogs(taskid);
// go through all tasklogs to find the comment
for(int i = 1;i <= taskdocs.size();i++) {
tasklog = (CmsTaskLog)taskdocs.elementAt(taskdocs.size() - i);
int type = tasklog.getType();
// check if this is a type "created" or "new"
if((type == C_TASKLOGTYPE_CREATED) || (type == C_TASKLOGTYPE_REACTIVATED)) {
String comment[] = Utils.split(tasklog.getComment(), "\n");
for(int j = 2;j < comment.length;j++) {
retValue.append(comment[j] + "\n");
}
break;
}
}
return retValue.toString();
}
/**
* Sends a message 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 message(CmsObject cms, int taskid, String message) throws CmsException {
CmsXmlLanguageFile lang = new CmsXmlLanguageFile(cms);
CmsTask task = cms.readTask(taskid);
String comment = lang.getLanguageValue("task.dialog.message.head") + " ";
if((message != null) && (message.length() != 0)) {
comment += Utils.getFullName(cms.readAgent(task)) + "\n";
comment += message;
cms.writeTaskLog(taskid, comment, C_TASKLOGTYPE_CALL);
}
// 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 = cms.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(Utils.getFullName(cms.readOwner(task)));
int projectid = cms.readProject(task).getId();
contentBuf.append("\n\n\n" + getTaskUrl(cms, task.getId(), projectid));
String subject = lang.getLanguageValue("task.email.message.subject") + " " + Utils.getFullName(cms.readOwner(task));
CmsUser[] users = {
cms.readAgent(task)
};
try {
com.opencms.defaults.CmsMail mail = new com.opencms.defaults.CmsMail(cms,
cms.readOwner(task), users, subject, contentBuf.toString(), "text/plain");
mail.start();
}
catch(Exception exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(I_CmsLogChannels.C_OPENCMS_INFO, "[CmsTaskAction] error while sending mail " + exc.getMessage());
}
}
}
/**
* Changes the priority of a task.
* @param cms The cms-object.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -