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 (Validator.isNull(getImage())) {
046 if (_trash) {
047 setImage("trash");
048 }
049 else {
050 setImage("delete");
051 }
052 }
053
054 if (_trash && Validator.isNull(getMessage())) {
055 setMessage("move-to-the-recycle-bin");
056 }
057
058 String url = getUrl();
059
060 if (url.startsWith("javascript:if (confirm('")) {
061 return super.getPage();
062 }
063
064 if (url.startsWith("javascript:")) {
065 url = url.substring(11);
066 }
067
068 if (url.startsWith(Http.HTTP_WITH_SLASH) ||
069 url.startsWith(Http.HTTPS_WITH_SLASH)) {
070
071 url =
072 "submitForm(document.hrefFm, '".concat(
073 HttpUtil.encodeURL(url)).concat("');");
074 }
075
076 if (url.startsWith("wsrp_rewrite?")) {
077 url = StringUtil.replace(
078 url, "/wsrp_rewrite",
079 "&wsrp-extensions=encodeURL/wsrp_rewrite");
080 url = "submitForm(document.hrefFm, '".concat(url).concat("');");
081 }
082
083 if (!_trash) {
084 StringBundler sb = new StringBundler(5);
085
086 sb.append("javascript:if (confirm('");
087
088 if (Validator.isNotNull(_confirmation)) {
089 sb.append(UnicodeLanguageUtil.get(pageContext, _confirmation));
090 }
091 else {
092 String confirmation = "are-you-sure-you-want-to-delete-this";
093
094 sb.append(UnicodeLanguageUtil.get(pageContext, confirmation));
095 }
096
097 sb.append("')) { ");
098 sb.append(url);
099 sb.append(" } else { self.focus(); }");
100
101 url = sb.toString();
102 }
103 else {
104 url = "javascript:".concat(url);
105 }
106
107 setUrl(url);
108
109 return super.getPage();
110 }
111
112 private static final String _PAGE = "/html/taglib/ui/icon_delete/page.jsp";
113
114 private String _confirmation;
115 private boolean _trash;
116
117 }