001
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 import com.liferay.portal.kernel.util.StringUtil;
023 import com.liferay.portal.kernel.util.Validator;
024
025
029 public class IconDeleteTag extends IconTag {
030
031 public void setConfirmation(String confirmation) {
032 _confirmation = confirmation;
033 }
034
035 public void setTrash(boolean trash) {
036 _trash = trash;
037 }
038
039 @Override
040 protected String getPage() {
041 if (FileAvailabilityUtil.isAvailable(servletContext, _PAGE)) {
042 return _PAGE;
043 }
044
045 if (_trash) {
046 setImage("trash");
047 }
048 else {
049 setImage("delete");
050 }
051
052 if (_trash && Validator.isNull(getMessage())) {
053 setMessage("move-to-the-recycle-bin");
054 }
055
056 String url = getUrl();
057
058 if (url.startsWith("javascript:if (confirm('")) {
059 return super.getPage();
060 }
061
062 if (url.startsWith("javascript:")) {
063 url = url.substring(11);
064 }
065
066 if (url.startsWith(Http.HTTP_WITH_SLASH) ||
067 url.startsWith(Http.HTTPS_WITH_SLASH)) {
068
069 url =
070 "submitForm(document.hrefFm, '".concat(
071 HttpUtil.encodeURL(url)).concat("');");
072 }
073
074 if (url.startsWith("wsrp_rewrite?")) {
075 url = StringUtil.replace(
076 url, "/wsrp_rewrite",
077 "&wsrp-extensions=encodeURL/wsrp_rewrite");
078 url = "submitForm(document.hrefFm, '".concat(url).concat("');");
079 }
080
081 if (!_trash) {
082 StringBundler sb = new StringBundler(5);
083
084 sb.append("javascript:if (confirm('");
085
086 if (Validator.isNotNull(_confirmation)) {
087 sb.append(UnicodeLanguageUtil.get(pageContext, _confirmation));
088 }
089 else {
090 String confirmation = "are-you-sure-you-want-to-delete-this";
091
092 sb.append(UnicodeLanguageUtil.get(pageContext, confirmation));
093 }
094
095 sb.append("')) { ");
096 sb.append(url);
097 sb.append(" } else { self.focus(); }");
098
099 url = sb.toString();
100 }
101 else {
102 url = "javascript:".concat(url);
103 }
104
105 setUrl(url);
106
107 return super.getPage();
108 }
109
110 private static final String _PAGE = "/html/taglib/ui/icon_delete/page.jsp";
111
112 private String _confirmation;
113 private boolean _trash;
114
115 }