1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.servlet.taglib.ui;
24  
25  import com.germinus.easyconf.Filter;
26  
27  import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
28  import com.liferay.portal.kernel.util.ArrayUtil;
29  import com.liferay.portal.kernel.util.HttpUtil;
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  /**
44   * <a href="SocialBookmarkTagUtil.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Jorge Ferrer
47   *
48   */
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<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.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 }