001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.configuration.Filter;
018 import com.liferay.portal.kernel.util.ArrayUtil;
019 import com.liferay.portal.kernel.util.HttpUtil;
020 import com.liferay.portal.kernel.util.PropsKeys;
021 import com.liferay.portal.kernel.util.PropsUtil;
022 import com.liferay.taglib.util.IncludeTag;
023
024 import java.util.HashMap;
025 import java.util.Map;
026
027 import javax.servlet.http.HttpServletRequest;
028
029
034 public class SocialBookmarkTag extends IncludeTag {
035
036 public void setTarget(String target) {
037 _target = target;
038 }
039
040 public void setTitle(String title) {
041 _title = title;
042 }
043
044 public void setType(String type) {
045 _type = type;
046 }
047
048 public void setUrl(String url) {
049 _url = url;
050 }
051
052 protected void cleanUp() {
053 _target = null;
054 _title = null;
055 _type = null;
056 _url = null;
057 }
058
059 protected String getPage() {
060 String[] socialTypes = PropsUtil.getArray(
061 PropsKeys.SOCIAL_BOOKMARK_TYPES);
062
063 if (ArrayUtil.contains(socialTypes, _type)) {
064 return _PAGE;
065 }
066 else {
067 return null;
068 }
069 }
070
071 protected void setAttributes(HttpServletRequest request) {
072 request.setAttribute(
073 "liferay-ui:social-bookmark:postUrl", getPostUrl());
074 request.setAttribute("liferay-ui:social-bookmark:target", _target);
075 request.setAttribute("liferay-ui:social-bookmark:title", _title);
076 request.setAttribute("liferay-ui:social-bookmark:type", _type);
077 request.setAttribute("liferay-ui:social-bookmark:url", _url);
078 }
079
080 private String getPostUrl() {
081 Map<String, String> vars = new HashMap<String, String>();
082
083 vars.put("liferay:social-bookmark:title", HttpUtil.encodeURL(_title));
084 vars.put("liferay:social-bookmark:url", _url);
085
086 String postUrl = PropsUtil.get(
087 PropsKeys.SOCIAL_BOOKMARK_POST_URL, new Filter(_type, vars));
088
089 return postUrl;
090 }
091
092 private static final String _PAGE =
093 "/html/taglib/ui/social_bookmark/page.jsp";
094
095 private String _target;
096 private String _title;
097 private String _type;
098 private String _url;
099
100 }