1
22
23 package com.liferay.portal.servlet.taglib.ui;
24
25 import com.liferay.portal.kernel.configuration.Filter;
26 import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
27 import com.liferay.portal.kernel.util.ArrayUtil;
28 import com.liferay.portal.kernel.util.HttpUtil;
29 import com.liferay.portal.util.PropsKeys;
30 import com.liferay.portal.util.PropsUtil;
31
32 import java.util.Map;
33
34 import javax.servlet.http.HttpServletRequest;
35 import javax.servlet.jsp.JspException;
36 import javax.servlet.jsp.PageContext;
37
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40
41 import org.hibernate.util.FastHashMap;
42
43
49 public class SocialBookmarkTagUtil {
50
51 public static void doEndTag(
52 String page, String type, String url, String title, String target,
53 PageContext pageContext)
54 throws JspException {
55
56 try {
57 HttpServletRequest request =
58 (HttpServletRequest)pageContext.getRequest();
59
60 request.setAttribute("liferay-ui:social-bookmark:type", type);
61 request.setAttribute("liferay-ui:social-bookmark:url", url);
62 request.setAttribute("liferay-ui:social-bookmark:title", title);
63 request.setAttribute("liferay-ui:social-bookmark:target", target);
64
65 String[] socialTypes = PropsUtil.getArray(
66 PropsKeys.SOCIAL_BOOKMARK_TYPES);
67
68 if (!ArrayUtil.contains(socialTypes, type)) {
69 return;
70 }
71
72 String postUrl = _getPostUrl(type, url, title);
73
74 request.setAttribute("liferay-ui:social-bookmark:postUrl", postUrl);
75
76 PortalIncludeUtil.include(pageContext, page);
77 }
78 catch (Exception e) {
79 _log.error(e, e);
80
81 throw new JspException(e);
82 }
83 }
84
85 private static String _getPostUrl(String type, String url, String title)
86 throws Exception {
87
88 Map<String, String> vars = new FastHashMap();
89
90 vars.put("liferay:social-bookmark:url", url);
91 vars.put("liferay:social-bookmark:title", HttpUtil.encodeURL(title));
92
93 String postUrl = PropsUtil.get(
94 PropsKeys.SOCIAL_BOOKMARK_POST_URL, new Filter(type, vars));
95
96 return postUrl;
97 }
98
99 private static Log _log = LogFactory.getLog(SocialBookmarkTagUtil.class);
100
101 }