001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.notification; 029 030import org.opencms.db.CmsUserSettings; 031import org.opencms.file.CmsObject; 032import org.opencms.file.CmsUser; 033import org.opencms.main.CmsException; 034import org.opencms.main.OpenCms; 035import org.opencms.util.CmsMacroResolver; 036import org.opencms.workplace.CmsWorkplaceLoginHandler; 037 038/** 039 * MacroResolver for Notifications.<p> 040 */ 041public class CmsNotificationMacroResolver extends CmsMacroResolver { 042 043 /**Macro for Receiver. */ 044 public static final String RECEIVER_SIMPLENAME = "receiver.simplename"; 045 046 /**Macro for Receiver. */ 047 public static final String RECEIVER_EMAIL = "receiver.email"; 048 049 /**Macro for Receiver. */ 050 public static final String RECEIVER_FIRSTNAME = "receiver.firstname"; 051 052 /**Macro for Receiver. */ 053 public static final String RECEIVER_LASTNAME = "receiver.lastname"; 054 055 /**Macro for Receiver. */ 056 public static final String RECEIVER_OU = "receiver.ou"; 057 058 /**Macro for Receiver. */ 059 public static final String RECEIVER_OU_FQN = "receiver.ou-fqn"; 060 061 /**Macro for Receiver. */ 062 public static final String RECEIVER_ADDRESS = "receiver.address"; 063 064 /**Macro for Receiver. */ 065 public static final String RECEIVER_CITY = "receiver.city"; 066 067 /**Macro for Receiver. */ 068 public static final String RECEIVER_COUNTRY = "receiver.country"; 069 070 /**Macro for Receiver. */ 071 public static final String RECEIVER_INSTITUTION = "receiver.institution"; 072 073 /**Macro for Receiver. */ 074 public static final String RECEIVER_FULLNAME = "receiver.fullname"; 075 076 /**Macro for Author. */ 077 public static final String AUTHOR_SIMPLENAME = "author.simplename"; 078 079 /**Macro for Workplace. */ 080 public static final String WORKPLACE_URL = "workplace.url"; 081 082 /**Macro for Workplace. */ 083 public static final String WORKPLACE_LOGIN_URL = "workplace.login-url"; 084 085 /** Macro for workplace url.*/ 086 public static final String WORKPLACE_LOGIN_LINK = "workplace.login-url.html"; 087 088 /** 089 * public constructor.<p> 090 * 091 * @param cms CmsObject 092 * @param receiver CmsUser who receives the Notification 093 */ 094 public CmsNotificationMacroResolver(CmsObject cms, CmsUser receiver) { 095 096 //Receiver information 097 addMacro(RECEIVER_SIMPLENAME, receiver.getSimpleName()); 098 addMacro(RECEIVER_FIRSTNAME, receiver.getFirstname()); 099 addMacro(RECEIVER_LASTNAME, receiver.getLastname()); 100 addMacro(RECEIVER_EMAIL, receiver.getEmail()); 101 addMacro(RECEIVER_OU_FQN, receiver.getOuFqn()); 102 try { 103 addMacro( 104 RECEIVER_OU, 105 OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, receiver.getOuFqn()).getDisplayName( 106 new CmsUserSettings(receiver).getLocale())); 107 108 } catch (CmsException e) { 109 addMacro(RECEIVER_OU, receiver.getOuFqn()); 110 } 111 addMacro(RECEIVER_ADDRESS, receiver.getAddress()); 112 addMacro(RECEIVER_CITY, receiver.getCity()); 113 addMacro(RECEIVER_COUNTRY, receiver.getCountry()); 114 addMacro(RECEIVER_INSTITUTION, receiver.getInstitution()); 115 addMacro(RECEIVER_FULLNAME, receiver.getFirstname() + " " + receiver.getLastname()); 116 117 //Author 118 addMacro(AUTHOR_SIMPLENAME, cms.getRequestContext().getCurrentUser().getSimpleName()); 119 120 //Workplace 121 addMacro(WORKPLACE_URL, OpenCms.getSiteManager().getWorkplaceServer()); 122 addMacro( 123 WORKPLACE_LOGIN_URL, 124 OpenCms.getLinkManager().getWorkplaceLink(cms, CmsWorkplaceLoginHandler.LOGIN_HANDLER, false)); 125 addMacro( 126 WORKPLACE_LOGIN_LINK, 127 "<a href =\"" 128 + OpenCms.getLinkManager().getWorkplaceLink(cms, CmsWorkplaceLoginHandler.LOGIN_HANDLER, false) 129 + "\">" 130 + OpenCms.getLinkManager().getWorkplaceLink(cms, CmsWorkplaceLoginHandler.LOGIN_HANDLER, false) 131 + "</a>"); 132 } 133}