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.ui;
016    
017    import com.liferay.portal.kernel.language.UnicodeLanguageUtil;
018    import com.liferay.portal.kernel.servlet.taglib.FileAvailabilityUtil;
019    import com.liferay.portal.kernel.util.Http;
020    import com.liferay.portal.kernel.util.HttpUtil;
021    import com.liferay.portal.kernel.util.StringBundler;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Shuyang Zhou
026     */
027    public class IconDeactivateTag extends IconTag {
028    
029            @Override
030            protected String getPage() {
031                    if (FileAvailabilityUtil.isAvailable(servletContext, _PAGE)) {
032                            return _PAGE;
033                    }
034    
035                    String url = getUrl();
036    
037                    if (url.startsWith("javascript:")) {
038                            url = url.substring(11);
039                    }
040    
041                    if (url.startsWith(Http.HTTP_WITH_SLASH) ||
042                            url.startsWith(Http.HTTPS_WITH_SLASH)) {
043    
044                            url =
045                                    "submitForm(document.hrefFm, '".concat(
046                                            HttpUtil.encodeURL(url)).concat("');");
047                    }
048    
049                    StringBundler sb = new StringBundler(5);
050    
051                    sb.append("javascript:if (confirm('");
052                    sb.append(
053                            UnicodeLanguageUtil.get(
054                                    pageContext, "are-you-sure-you-want-to-deactivate-this"));
055                    sb.append("')) { ");
056                    sb.append(url);
057                    sb.append(" } else { self.focus(); }");
058    
059                    url = sb.toString();
060    
061                    setImage("deactivate");
062                    setUrl(url);
063    
064                    return super.getPage();
065            }
066    
067            private static final String _PAGE =
068                    "/html/taglib/ui/icon_deactivate/page.jsp";
069    
070    }