001    /**
002     * Copyright (c) 2000-2013 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.aui;
016    
017    import com.liferay.portal.kernel.util.Validator;
018    import com.liferay.portal.kernel.workflow.WorkflowConstants;
019    import com.liferay.taglib.aui.base.BaseWorkflowStatusTag;
020    
021    import javax.servlet.http.HttpServletRequest;
022    
023    /**
024     * @author Julio Camarero
025     * @author Jorge Ferrer
026     * @author Brian Wing Shun Chan
027     */
028    public class WorkflowStatusTag extends BaseWorkflowStatusTag {
029    
030            @Override
031            protected boolean isCleanUpSetAttributes() {
032                    return _CLEAN_UP_SET_ATTRIBUTES;
033            }
034    
035            @Override
036            protected void setAttributes(HttpServletRequest request) {
037                    super.setAttributes(request);
038    
039                    Object bean = getBean();
040    
041                    if (bean == null) {
042                            bean = pageContext.getAttribute("aui:model-context:bean");
043                    }
044    
045                    String helpMessage = getHelpMessage();
046    
047                    if (Validator.isNull(helpMessage) &&
048                            (getStatus() == WorkflowConstants.STATUS_APPROVED) &&
049                            Validator.isNotNull(getVersion())) {
050    
051                            helpMessage = _HELP_MESSAGE_DEFAULT;
052                    }
053    
054                    Class<?> model = getModel();
055    
056                    if (model == null) {
057                            model = (Class<?>)pageContext.getAttribute(
058                                    "aui:model-context:model");
059                    }
060    
061                    setNamespacedAttribute(request, "bean", bean);
062                    setNamespacedAttribute(request, "helpMessage", helpMessage);
063                    setNamespacedAttribute(request, "model", model);
064            }
065    
066            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
067    
068            private static final String _HELP_MESSAGE_DEFAULT =
069                    "a-new-version-will-be-created-automatically-if-this-content-is-" +
070                            "modified";
071    
072    }