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