1
22
23 package com.liferay.portal.servlet.taglib.ui;
24
25 import com.germinus.easyconf.Filter;
26
27 import com.liferay.portal.kernel.util.ArrayUtil;
28 import com.liferay.portal.servlet.PortalIncludeUtil;
29 import com.liferay.portal.util.PropsUtil;
30 import com.liferay.util.HttpUtil;
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 req =
58 (HttpServletRequest)pageContext.getRequest();
59
60 req.setAttribute("liferay-ui:social-bookmark:type", type);
61 req.setAttribute("liferay-ui:social-bookmark:url", url);
62 req.setAttribute("liferay-ui:social-bookmark:title", title);
63 req.setAttribute("liferay-ui:social-bookmark:target", target);
64
65 String[] socialTypes = PropsUtil.getArray(
66 PropsUtil.SOCIAL_BOOKMARK_TYPES);
67
68 if (!ArrayUtil.contains(socialTypes, type)) {
69 return;
70 }
71
72 String postUrl = _getPostUrl(type, url, title);
73
74 req.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 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.getComponentProperties().getString(
94 PropsUtil.SOCIAL_BOOKMARK_POST_URL,
95 Filter.by(type).setVariables(vars));
96
97 return postUrl;
98 }
99
100 private static Log _log = LogFactory.getLog(SocialBookmarkTagUtil.class);
101
102 }