001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.ui;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    import com.liferay.taglib.util.IncludeTag;
019    
020    import java.util.Map;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    /**
025     * @author Eudaldo Alonso
026     */
027    public class EmailNotificationSettingsTag extends IncludeTag {
028    
029            @Override
030            public int doStartTag() {
031                    return EVAL_BODY_INCLUDE;
032            }
033    
034            public void setBodyLabel(String bodyLabel) {
035                    _bodyLabel = bodyLabel;
036            }
037    
038            public void setEmailBody(String emailBody) {
039                    _emailBody = emailBody;
040            }
041    
042            public void setEmailDefinitionTerms(
043                    Map<String, String> emailDefinitionTerms) {
044    
045                    _emailDefinitionTerms = emailDefinitionTerms;
046            }
047    
048            public void setEmailEnabled(boolean emailEnabled) {
049                    _emailEnabled = emailEnabled;
050            }
051    
052            public void setEmailParam(String emailParam) {
053                    _emailParam = emailParam;
054            }
055    
056            public void setEmailSubject(String emailSubject) {
057                    _emailSubject = emailSubject;
058            }
059    
060            public void setFieldPrefix(String fieldPrefix) {
061                    _fieldPrefix = fieldPrefix;
062            }
063    
064            public void setFieldPrefixSeparator(String fieldPrefixSeparator) {
065                    _fieldPrefixSeparator = fieldPrefixSeparator;
066            }
067    
068            public void setHelpMessage(String helpMessage) {
069                    _helpMessage = helpMessage;
070            }
071    
072            public void setShowEmailEnabled(boolean showEmailEnabled) {
073                    _showEmailEnabled = showEmailEnabled;
074            }
075    
076            public void setShowSubject(boolean showSubject) {
077                    _showSubject = showSubject;
078            }
079    
080            @Override
081            protected void cleanUp() {
082                    _bodyLabel = null;
083                    _emailBody = null;
084                    _emailDefinitionTerms = null;
085                    _emailEnabled = false;
086                    _emailParam = null;
087                    _emailSubject = null;
088                    _fieldPrefix = null;
089                    _fieldPrefixSeparator = null;
090                    _helpMessage = null;
091                    _showEmailEnabled = true;
092                    _showSubject = true;
093            }
094    
095            @Override
096            protected String getPage() {
097                    return _PAGE;
098            }
099    
100            @Override
101            protected boolean isCleanUpSetAttributes() {
102                    return _CLEAN_UP_SET_ATTRIBUTES;
103            }
104    
105            @Override
106            protected void setAttributes(HttpServletRequest request) {
107                    if (Validator.isNull(_bodyLabel)) {
108                            _bodyLabel = "body";
109                    }
110    
111                    if (Validator.isNull(_fieldPrefix)) {
112                            _fieldPrefix = "preferences";
113                    }
114    
115                    if (Validator.isNull(_fieldPrefixSeparator)) {
116                            _fieldPrefixSeparator = "--";
117                    }
118    
119                    request.setAttribute(
120                            "liferay-ui:email-notification-settings:bodyLabel", _bodyLabel);
121                    request.setAttribute(
122                            "liferay-ui:email-notification-settings:emailBody", _emailBody);
123                    request.setAttribute(
124                            "liferay-ui:email-notification-settings:emailDefinitionTerms",
125                            _emailDefinitionTerms);
126                    request.setAttribute(
127                            "liferay-ui:email-notification-settings:emailEnabled",
128                            String.valueOf(_emailEnabled));
129                    request.setAttribute(
130                            "liferay-ui:email-notification-settings:emailParam", _emailParam);
131                    request.setAttribute(
132                            "liferay-ui:email-notification-settings:emailSubject",
133                            _emailSubject);
134                    request.setAttribute(
135                            "liferay-ui:email-notification-settings:fieldPrefix", _fieldPrefix);
136                    request.setAttribute(
137                            "liferay-ui:email-notification-settings:fieldPrefixSeparator",
138                            _fieldPrefixSeparator);
139                    request.setAttribute(
140                            "liferay-ui:email-notification-settings:helpMessage", _helpMessage);
141                    request.setAttribute(
142                            "liferay-ui:email-notification-settings:showEmailEnabled",
143                            _showEmailEnabled);
144                    request.setAttribute(
145                            "liferay-ui:email-notification-settings:showSubject", _showSubject);
146            }
147    
148            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
149    
150            private static final String _PAGE =
151                    "/html/taglib/ui/email_notification_settings/page.jsp";
152    
153            private String _bodyLabel;
154            private String _emailBody;
155            private Map<String, String> _emailDefinitionTerms;
156            private boolean _emailEnabled;
157            private String _emailParam;
158            private String _emailSubject;
159            private String _fieldPrefix;
160            private String _fieldPrefixSeparator;
161            private String _helpMessage;
162            private boolean _showEmailEnabled = true;
163            private boolean _showSubject = true;
164    
165    }