📄 cmscontentnotification.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/notification/CmsContentNotification.java,v $
* Date : $Date: 2006/10/04 07:35:21 $
* Version: $Revision: 1.3 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2002 - 2004 Alkacon Software (http://www.alkacon.com)
*
* 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 Alkacon Software, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project 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 org.opencms.notification;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsUser;
import org.opencms.file.types.CmsResourceTypeJsp;
import org.opencms.file.types.CmsResourceTypePlain;
import org.opencms.file.types.CmsResourceTypeXmlPage;
import org.opencms.i18n.CmsLocaleManager;
import org.opencms.i18n.CmsMessages;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.site.CmsSiteManager;
import org.opencms.util.CmsDateUtil;
import org.opencms.util.CmsRequestUtil;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsFrameset;
import org.opencms.workplace.CmsWorkplace;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import org.apache.commons.logging.Log;
/**
* The E-Mail to be written to responsibles of resources.<p>
*
* @author Jan Baudisch
* @author Peter Bonrad
*/
public class CmsContentNotification extends A_CmsNotification {
/** The path to the xml content with the subject, header and footer of the notification e-mail.<p> */
public static final String NOTIFICATION_CONTENT = "/system/workplace/admin/notification/notification";
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsContentNotification.class);
/** The message bundle initialized with the locale of the reciever. */
private CmsMessages m_messages;
/** The resources the responsible will be notified of, a list of CmsNotificationCauses. */
private List m_notificationCauses;
/** The receiver of the notification. */
private CmsUser m_responsible;
/** Server name and opencms context. */
private String m_serverAndContext = OpenCms.getSiteManager().getWorkplaceServer()
+ OpenCms.getSystemInfo().getOpenCmsContext();
/** Uri of the workplace folder. */
private String m_uriWorkplace = m_serverAndContext + CmsWorkplace.VFS_PATH_WORKPLACE;
/** Uri of the workplace jsp. */
private String m_uriWorkplaceJsp = m_serverAndContext + CmsFrameset.JSP_WORKPLACE_URI;
/**
* Creates a new CmsContentNotification.<p>
*
* @param responsible the user that will be notified
* @param cms the cms object to use
*/
CmsContentNotification(CmsUser responsible, CmsObject cms) {
super(cms, responsible);
m_responsible = responsible;
}
/**
* Returns true, if there exists an editor for a specific resource.<p>
*
* @param resource the resource to check if there exists an editor
*
* @return true if there exists an editor for the resource
*/
public static boolean existsEditor(CmsResource resource) {
if ((resource.getTypeId() == CmsResourceTypeJsp.getStaticTypeId())
|| (resource.getTypeId() == CmsResourceTypePlain.getStaticTypeId())
|| (resource.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId())) {
return true;
}
return false;
}
/**
* Returns the responsible.<p>
*
* @return the responsible
*/
public CmsUser getResponsible() {
return m_responsible;
}
/**
* Creates the mail to be sent to the responsible user.<p>
*
* @return the mail to be sent to the responsible user
* @throws CmsException if something goes wrong
*/
protected String generateHtmlMsg() {
// set the messages
m_messages = Messages.get().getBundle(getLocale());
StringBuffer htmlMsg = new StringBuffer();
htmlMsg.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">");
htmlMsg.append("<tr><td colspan=\"5\"><br/>");
GregorianCalendar tomorrow = new GregorianCalendar(TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale());
tomorrow.add(Calendar.DAY_OF_YEAR, 1);
List outdatedResources = new ArrayList();
List resourcesNextDay = new ArrayList();
List resourcesNextWeek = new ArrayList();
// split all resources into three lists: the resources that expire, will be released or get outdated
// within the next 24h, within the next week and the resources unchanged since a long time
Iterator notificationCauses = m_notificationCauses.iterator();
while (notificationCauses.hasNext()) {
CmsExtendedNotificationCause notificationCause = (CmsExtendedNotificationCause)notificationCauses.next();
if (notificationCause.getCause() == CmsExtendedNotificationCause.RESOURCE_OUTDATED) {
outdatedResources.add(notificationCause);
} else if (notificationCause.getDate().before(tomorrow.getTime())) {
resourcesNextDay.add(notificationCause);
} else {
resourcesNextWeek.add(notificationCause);
}
}
Collections.sort(resourcesNextDay);
Collections.sort(resourcesNextWeek);
Collections.sort(outdatedResources);
appendResourceList(htmlMsg, resourcesNextDay, m_messages.key(Messages.GUI_WITHIN_NEXT_DAY_0));
appendResourceList(htmlMsg, resourcesNextWeek, m_messages.key(Messages.GUI_WITHIN_NEXT_WEEK_0));
appendResourceList(htmlMsg, outdatedResources, m_messages.key(
Messages.GUI_FILES_NOT_UPDATED_1,
String.valueOf(OpenCms.getSystemInfo().getNotificationTime())));
htmlMsg.append("</td></tr></table>");
String result = htmlMsg.toString();
return result;
}
/**
* Returns a list of CmsNotificationResourceInfos of the resources that will occur in the notification.<p>
*
* @return a list of CmsNotificationResourceInfos of the resources that will occur in the notification
*/
protected List getNotificationCauses() {
return m_notificationCauses;
}
/**
* @see org.opencms.notification.A_CmsNotification#getNotificationContent()
*/
protected String getNotificationContent() {
return NOTIFICATION_CONTENT;
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -