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.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.kernel.util.WebKeys;
020    import com.liferay.portal.theme.ThemeDisplay;
021    import com.liferay.taglib.FileAvailabilityUtil;
022    
023    import javax.servlet.jsp.JspWriter;
024    
025    /**
026     * @author Scott Lee
027     * @author Shuyang Zhou
028     */
029    public class IconHelpTag extends IconTag {
030    
031            @Override
032            protected String getPage() {
033                    if (FileAvailabilityUtil.isAvailable(servletContext, _PAGE)) {
034                            return _PAGE;
035                    }
036                    else {
037                            return null;
038                    }
039            }
040    
041            @Override
042            protected int processEndTag() throws Exception {
043                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
044                            WebKeys.THEME_DISPLAY);
045    
046                    JspWriter jspWriter = pageContext.getOut();
047    
048                    String id = StringUtil.randomId();
049    
050                    jspWriter.write("<span class=\"taglib-icon-help\"><img alt=\"\" ");
051                    jspWriter.write("aria-labelledby=\"");
052                    jspWriter.write(id);
053                    jspWriter.write("\" ");
054                    jspWriter.write("onBlur=\"Liferay.Portal.ToolTip.hide();\" ");
055                    jspWriter.write("onFocus=\"Liferay.Portal.ToolTip.show(this);\" ");
056                    jspWriter.write("onMouseOver=\"Liferay.Portal.ToolTip.show(this);\" ");
057                    jspWriter.write("src=\"");
058                    jspWriter.write(themeDisplay.getPathThemeImages());
059                    jspWriter.write("/portlet/help.png\" tabIndex=\"0\" ");
060                    jspWriter.write("/><span ");
061                    jspWriter.write("class=\"hide-accessible tooltip-text\" ");
062                    jspWriter.write("id=\"");
063                    jspWriter.write(id);
064                    jspWriter.write("\" >");
065                    jspWriter.write(LanguageUtil.get(request, getMessage()));
066                    jspWriter.write("</span></span>");
067    
068                    return EVAL_PAGE;
069            }
070    
071            private static final String _PAGE = "/html/taglib/ui/icon_help/page.jsp";
072    
073    }