1
14
15 package com.liferay.taglib.ui;
16
17 import com.liferay.portal.kernel.configuration.Filter;
18 import com.liferay.portal.kernel.util.ArrayUtil;
19 import com.liferay.portal.kernel.util.HttpUtil;
20 import com.liferay.portal.kernel.util.PropsKeys;
21 import com.liferay.portal.kernel.util.PropsUtil;
22 import com.liferay.taglib.util.IncludeTag;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import javax.servlet.http.HttpServletRequest;
28
29
36 public class SocialBookmarkTag extends IncludeTag {
37
38 public void setTarget(String target) {
39 _target = target;
40 }
41
42 public void setTitle(String title) {
43 _title = title;
44 }
45
46 public void setType(String type) {
47 _type = type;
48 }
49
50 public void setUrl(String url) {
51 _url = url;
52 }
53
54 protected void cleanUp() {
55 _target = null;
56 _title = null;
57 _type = null;
58 _url = null;
59 }
60
61 protected String getPage() {
62 String[] socialTypes = PropsUtil.getArray(
63 PropsKeys.SOCIAL_BOOKMARK_TYPES);
64
65 if (ArrayUtil.contains(socialTypes, _type)) {
66 return _PAGE;
67 }
68 else {
69 return null;
70 }
71 }
72
73 protected void setAttributes(HttpServletRequest request) {
74 request.setAttribute(
75 "liferay-ui:social-bookmark:postUrl", getPostUrl());
76 request.setAttribute("liferay-ui:social-bookmark:target", _target);
77 request.setAttribute("liferay-ui:social-bookmark:title", _title);
78 request.setAttribute("liferay-ui:social-bookmark:type", _type);
79 request.setAttribute("liferay-ui:social-bookmark:url", _url);
80 }
81
82 private String getPostUrl() {
83 Map<String, String> vars = new HashMap<String, String>();
84
85 vars.put("liferay:social-bookmark:title", HttpUtil.encodeURL(_title));
86 vars.put("liferay:social-bookmark:url", _url);
87
88 String postUrl = PropsUtil.get(
89 PropsKeys.SOCIAL_BOOKMARK_POST_URL, new Filter(_type, vars));
90
91 return postUrl;
92 }
93
94 private static final String _PAGE =
95 "/html/taglib/ui/social_bookmark/page.jsp";
96
97 private String _target;
98 private String _title;
99 private String _type;
100 private String _url;
101
102 }