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.aui;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.taglib.aui.base.BaseNavItemTag;
021    import com.liferay.taglib.util.TagResourceBundleUtil;
022    
023    import java.util.ResourceBundle;
024    
025    import javax.servlet.http.HttpServletRequest;
026    import javax.servlet.jsp.JspException;
027    import javax.servlet.jsp.tagext.BodyTag;
028    
029    /**
030     * @author Eduardo Lundgren
031     * @author Bruno Basto
032     * @author Nathan Cavanaugh
033     * @author Julio Camarero
034     * @author Carlos Sierra Andrés
035     */
036    public class NavItemTag extends BaseNavItemTag implements BodyTag {
037    
038            @Override
039            public int doStartTag() throws JspException {
040                    NavBarTag navBarTag = (NavBarTag)findAncestorWithClass(
041                            this, NavBarTag.class);
042    
043                    if ((navBarTag != null) && getSelected()) {
044                            String title = getTitle();
045    
046                            if (Validator.isNull(title)) {
047                                    title = getLabel();
048                            }
049    
050                            navBarTag.setSelectedItemName(title);
051                    }
052    
053                    super.doStartTag();
054    
055                    return BodyTag.EVAL_BODY_BUFFERED;
056            }
057    
058            @Override
059            protected void setAttributes(HttpServletRequest request) {
060                    super.setAttributes(request);
061    
062                    if (!getUseDialog() && AUIUtil.isOpensNewWindow(getTarget())) {
063                            String title = getTitle();
064    
065                            if (title == null) {
066                                    title = StringPool.BLANK;
067                            }
068    
069                            ResourceBundle resourceBundle =
070                                    TagResourceBundleUtil.getResourceBundle(pageContext);
071    
072                            title = title.concat(
073                                    LanguageUtil.get(resourceBundle, "opens-new-window"));
074    
075                            setNamespacedAttribute(request, "title", String.valueOf(title));
076                    }
077            }
078    
079    }