1 31 32 package org.opencms.notification; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.file.CmsResource; 36 import org.opencms.file.CmsUser; 37 import org.opencms.file.types.CmsResourceTypeJsp; 38 import org.opencms.file.types.CmsResourceTypePlain; 39 import org.opencms.file.types.CmsResourceTypeXmlPage; 40 import org.opencms.i18n.CmsLocaleManager; 41 import org.opencms.i18n.CmsMessages; 42 import org.opencms.main.CmsException; 43 import org.opencms.main.CmsLog; 44 import org.opencms.main.OpenCms; 45 import org.opencms.site.CmsSiteManager; 46 import org.opencms.util.CmsDateUtil; 47 import org.opencms.util.CmsRequestUtil; 48 import org.opencms.workplace.CmsDialog; 49 import org.opencms.workplace.CmsFrameset; 50 import org.opencms.workplace.CmsWorkplace; 51 52 import java.util.ArrayList ; 53 import java.util.Calendar ; 54 import java.util.Collections ; 55 import java.util.GregorianCalendar ; 56 import java.util.HashMap ; 57 import java.util.Iterator ; 58 import java.util.List ; 59 import java.util.Map ; 60 import java.util.TimeZone ; 61 62 import org.apache.commons.logging.Log; 63 64 70 public class CmsContentNotification extends A_CmsNotification { 71 72 73 public static final String NOTIFICATION_CONTENT = "/system/workplace/admin/notification/notification"; 74 75 76 private static final Log LOG = CmsLog.getLog(CmsContentNotification.class); 77 78 79 private CmsMessages m_messages; 80 81 82 private List m_notificationCauses; 83 84 85 private CmsUser m_responsible; 86 87 88 private String m_serverAndContext = OpenCms.getSiteManager().getWorkplaceServer() 89 + OpenCms.getSystemInfo().getOpenCmsContext(); 90 91 92 private String m_uriWorkplace = m_serverAndContext + CmsWorkplace.VFS_PATH_WORKPLACE; 93 94 95 private String m_uriWorkplaceJsp = m_serverAndContext + CmsFrameset.JSP_WORKPLACE_URI; 96 97 103 CmsContentNotification(CmsUser responsible, CmsObject cms) { 104 105 super(cms, responsible); 106 m_responsible = responsible; 107 } 108 109 116 public static boolean existsEditor(CmsResource resource) { 117 118 if ((resource.getTypeId() == CmsResourceTypeJsp.getStaticTypeId()) 119 || (resource.getTypeId() == CmsResourceTypePlain.getStaticTypeId()) 120 || (resource.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId())) { 121 return true; 122 } 123 return false; 124 } 125 126 131 public CmsUser getResponsible() { 132 133 return m_responsible; 134 } 135 136 137 143 protected String generateHtmlMsg() { 144 145 m_messages = Messages.get().getBundle(getLocale()); 147 148 StringBuffer htmlMsg = new StringBuffer (); 149 htmlMsg.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"); 150 htmlMsg.append("<tr><td colspan=\"5\"><br/>"); 151 152 GregorianCalendar tomorrow = new GregorianCalendar (TimeZone.getDefault(), CmsLocaleManager.getDefaultLocale()); 153 tomorrow.add(Calendar.DAY_OF_YEAR, 1); 154 List outdatedResources = new ArrayList (); 155 List resourcesNextDay = new ArrayList (); 156 List resourcesNextWeek = new ArrayList (); 157 158 Iterator notificationCauses = m_notificationCauses.iterator(); 161 while (notificationCauses.hasNext()) { 162 CmsExtendedNotificationCause notificationCause = (CmsExtendedNotificationCause)notificationCauses.next(); 163 if (notificationCause.getCause() == CmsExtendedNotificationCause.RESOURCE_OUTDATED) { 164 outdatedResources.add(notificationCause); 165 } else if (notificationCause.getDate().before(tomorrow.getTime())) { 166 resourcesNextDay.add(notificationCause); 167 } else { 168 resourcesNextWeek.add(notificationCause); 169 } 170 } 171 Collections.sort(resourcesNextDay); 172 Collections.sort(resourcesNextWeek); 173 Collections.sort(outdatedResources); 174 appendResourceList(htmlMsg, resourcesNextDay, m_messages.key(Messages.GUI_WITHIN_NEXT_DAY_0)); 175 appendResourceList(htmlMsg, resourcesNextWeek, m_messages.key(Messages.GUI_WITHIN_NEXT_WEEK_0)); 176 appendResourceList(htmlMsg, outdatedResources, m_messages.key( 177 Messages.GUI_FILES_NOT_UPDATED_1, 178 String.valueOf(OpenCms.getSystemInfo().getNotificationTime()))); 179 180 htmlMsg.append("</td></tr></table>"); 181 String result = htmlMsg.toString(); 182 return result; 183 } 184 185 190 protected List getNotificationCauses() { 191 192 return m_notificationCauses; 193 } 194 195 198 protected String getNotificationContent() { 199 200 return NOTIFICATION_CONTENT; 201 } 202 203 208 protected void setNotificationCauses(List resources) { 209 210 m_notificationCauses = resources; 211 } 212 213 219 private void appendConfirmLink(StringBuffer html, CmsExtendedNotificationCause notificationCause) { 220 221 Map params = new HashMap (); 222 html.append("<td>"); 223 try { 224 String resourcePath = notificationCause.getResource().getRootPath(); 225 String siteRoot = CmsSiteManager.getSiteRoot(resourcePath); 226 resourcePath = resourcePath.substring(siteRoot.length()); 227 html.append("[<a HREF=\""); 228 StringBuffer wpStartUri = new StringBuffer (m_uriWorkplace); 229 wpStartUri.append("commons/confirm_content_notification.jsp?userId="); 230 wpStartUri.append(m_responsible.getId()); 231 wpStartUri.append("&cause="); 232 wpStartUri.append(notificationCause.getCause()); 233 wpStartUri.append("&resource="); 234 wpStartUri.append(resourcePath); 235 params.put(CmsFrameset.PARAM_WP_START, wpStartUri.toString()); 236 params.put(CmsWorkplace.PARAM_WP_EXPLORER_RESOURCE, CmsResource.getParentFolder(resourcePath)); 237 params.put(CmsWorkplace.PARAM_WP_SITE, siteRoot); 238 int projectId = getCmsObject().readProject(OpenCms.getSystemInfo().getNotificationProject()).getId(); 239 params.put(CmsWorkplace.PARAM_WP_PROJECT, String.valueOf(projectId)); 240 html.append(CmsRequestUtil.appendParameters(m_uriWorkplaceJsp, params, true)); 241 html.append("\">"); 242 html.append(m_messages.key(Messages.GUI_CONFIRM_0)); 243 html.append("</a>]"); 244 } catch (CmsException e) { 245 if (LOG.isInfoEnabled()) { 246 LOG.info(e); 247 } 248 } 249 html.append("</td>"); 250 } 251 252 258 private void appendEditLink(StringBuffer html, CmsExtendedNotificationCause notificationCause) { 259 260 html.append("<td>"); 261 if (existsEditor(notificationCause.getResource())) { 262 try { 263 String resourcePath = notificationCause.getResource().getRootPath(); 264 String siteRoot = CmsSiteManager.getSiteRoot(resourcePath); 265 resourcePath = resourcePath.substring(siteRoot.length()); 266 Map params = new HashMap (); 267 int projectId = getCmsObject().readProject(OpenCms.getSystemInfo().getNotificationProject()).getId(); 268 params.put(CmsWorkplace.PARAM_WP_PROJECT, String.valueOf(projectId)); 269 params.put(CmsWorkplace.PARAM_WP_EXPLORER_RESOURCE, CmsResource.getParentFolder(resourcePath)); 270 params.put(CmsWorkplace.PARAM_WP_SITE, siteRoot); 271 params.put(CmsDialog.PARAM_RESOURCE, resourcePath); 272 html.append("[<a HREF=\""); 273 html.append(CmsRequestUtil.appendParameters(m_uriWorkplace + "editors/editor.jsp", params, false)); 274 html.append("\">"); 275 html.append(m_messages.key(Messages.GUI_EDIT_0)); 276 html.append("</a>]"); 277 } catch (CmsException e) { 278 if (LOG.isInfoEnabled()) { 279 LOG.info(e); 280 } 281 } 282 } 283 html.append("</td>"); 284 } 285 286 292 private void appendModifyLink(StringBuffer html, CmsExtendedNotificationCause notificationCause) { 293 294 Map params = new HashMap (); 295 html.append("<td>"); 296 try { 297 html.append("[<a HREF=\""); 298 String resourcePath = notificationCause.getResource().getRootPath(); 299 String siteRoot = CmsSiteManager.getSiteRoot(resourcePath); 300 resourcePath = resourcePath.substring(siteRoot.length()); 301 StringBuffer wpStartUri = new StringBuffer (m_uriWorkplace); 302 wpStartUri.append("commons/availability.jsp?resource="); 303 wpStartUri.append(resourcePath); 304 params.put(CmsWorkplace.PARAM_WP_EXPLORER_RESOURCE, CmsResource.getParentFolder(resourcePath)); 305 params.put(CmsFrameset.PARAM_WP_START, wpStartUri.toString()); 306 params.put(CmsWorkplace.PARAM_WP_SITE, siteRoot); 307 int projectId = getCmsObject().readProject(OpenCms.getSystemInfo().getNotificationProject()).getId(); 308 params.put(CmsWorkplace.PARAM_WP_PROJECT, String.valueOf(projectId)); 309 html.append(CmsRequestUtil.appendParameters(m_uriWorkplaceJsp, params, true)); 310 html.append("\">"); 311 html.append(m_messages.key(Messages.GUI_MODIFY_0)); 312 html.append("</a>]"); 313 } catch (CmsException e) { 314 if (LOG.isInfoEnabled()) { 315 LOG.info(e); 316 } 317 } 318 html.append("</td>"); 319 } 320 321 328 private void appendResourceList(StringBuffer htmlMsg, List notificationCauseList, String header) { 329 330 if (!notificationCauseList.isEmpty()) { 331 htmlMsg.append("<tr><td colspan=\"5\"><br/><p style=\"margin-top:20px;margin-bottom:10px;\"><b>"); 332 htmlMsg.append(header); 333 htmlMsg.append("</b></p></td></tr><tr class=\"trow1\"><td><div style=\"padding-top:2px;padding-bottom:2px;\">"); 334 htmlMsg.append(m_messages.key(Messages.GUI_RESOURCE_0)); 335 htmlMsg.append("</div></td><td><div style=\"padding-top:2px;padding-bottom:2px;padding-left:10px;\">"); 336 htmlMsg.append(m_messages.key(Messages.GUI_SITE_0)); 337 htmlMsg.append("</div></td><td><div style=\"padding-top:2px;padding-bottom:2px;padding-left:10px;\">"); 338 htmlMsg.append(m_messages.key(Messages.GUI_ISSUE_0)); 339 htmlMsg.append("</div></td><td colspan=\"2\"/></tr>"); 340 Iterator notificationCauses = notificationCauseList.iterator(); 341 for (int i = 0; notificationCauses.hasNext(); i++) { 342 CmsExtendedNotificationCause notificationCause = (CmsExtendedNotificationCause)notificationCauses.next(); 343 htmlMsg.append(buildNotificationListItem(notificationCause, (i % 2) + 2)); 344 } 345 } 346 } 347 348 353 private String buildNotificationListItem(CmsExtendedNotificationCause notificationCause, int row) { 354 355 StringBuffer result = new StringBuffer ("<tr class=\"trow"); 356 result.append(row); 357 result.append("\"><td width=\"100%\">"); 358 String resourcePath = notificationCause.getResource().getRootPath(); 359 String siteRoot = CmsSiteManager.getSiteRoot(resourcePath); 360 resourcePath = resourcePath.substring(siteRoot.length()); 361 if (notificationCause.getResource().getDateReleased() < System.currentTimeMillis() 363 && notificationCause.getResource().getDateExpired() > System.currentTimeMillis()) { 364 365 Map params = new HashMap (); 366 params.put(CmsWorkplace.PARAM_WP_SITE, siteRoot); 367 params.put(CmsDialog.PARAM_RESOURCE, resourcePath); 368 result.append("<a HREF=\""); 369 result.append(CmsRequestUtil.appendParameters(m_uriWorkplace + "commons/displayresource.jsp", params, false)); 370 result.append("\">"); 371 result.append(resourcePath); 372 result.append("</a>"); 373 } else { 374 result.append(resourcePath); 375 } 376 result.append("</td><td><div style=\"white-space:nowrap;padding-left:10px;padding-right:10px;\">"); 377 result.append(siteRoot); 378 result.append("</td><td><div style=\"white-space:nowrap;padding-left:10px;padding-right:10px;\">"); 379 if (notificationCause.getCause() == CmsExtendedNotificationCause.RESOURCE_EXPIRES) { 380 result.append(m_messages.key(Messages.GUI_EXPIRES_AT_1, new Object [] {notificationCause.getDate()})); 381 result.append("</div></td>"); 382 appendConfirmLink(result, notificationCause); 383 appendModifyLink(result, notificationCause); 384 } else if (notificationCause.getCause() == CmsExtendedNotificationCause.RESOURCE_RELEASE) { 385 result.append(m_messages.key(Messages.GUI_RELEASE_AT_1, new Object [] {notificationCause.getDate()})); 386 result.append("</div></td>"); 387 appendConfirmLink(result, notificationCause); 388 appendModifyLink(result, notificationCause); 389 } else if (notificationCause.getCause() == CmsExtendedNotificationCause.RESOURCE_UPDATE_REQUIRED) { 390 result.append(m_messages.key(Messages.GUI_UPDATE_REQUIRED_1, new Object [] {notificationCause.getDate()})); 391 result.append("</div></td>"); 392 appendConfirmLink(result, notificationCause); 393 appendEditLink(result, notificationCause); 394 } else { 395 result.append(m_messages.key(Messages.GUI_UNCHANGED_SINCE_1, new Object [] {new Integer ( 396 CmsDateUtil.getDaysPassedSince(notificationCause.getDate()))})); 397 result.append("</div></td>"); 398 appendConfirmLink(result, notificationCause); 399 appendEditLink(result, notificationCause); 400 } 401 402 result.append("</tr>"); 403 404 return result.toString(); 405 } 406 } | Popular Tags |