1   /**
2    * Copyright (c) 2000-2007 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.taglib.ui;
24  
25  import com.liferay.portal.kernel.util.MethodInvoker;
26  import com.liferay.portal.kernel.util.MethodWrapper;
27  import com.liferay.portal.kernel.util.NullWrapper;
28  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
29  import com.liferay.portal.kernel.util.StringPool;
30  
31  import javax.servlet.jsp.JspException;
32  import javax.servlet.jsp.PageContext;
33  import javax.servlet.jsp.tagext.TagSupport;
34  
35  import org.apache.commons.logging.Log;
36  import org.apache.commons.logging.LogFactory;
37  
38  /**
39   * <a href="SocialBookmarkTag.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author David Truong
42   * @author Jorge Ferrer
43   *
44   */
45  public class SocialBookmarkTag extends TagSupport {
46  
47      public static String doTag(
48              String type, String url, String title, String target,
49              PageContext pageContext)
50          throws Exception {
51  
52          Object returnObj = null;
53  
54          ClassLoader contextClassLoader =
55              Thread.currentThread().getContextClassLoader();
56  
57          try {
58              Thread.currentThread().setContextClassLoader(
59                  PortalClassLoaderUtil.getClassLoader());
60  
61              Object targetWrapper = target;
62  
63              if (targetWrapper == null) {
64                  targetWrapper = new NullWrapper(String.class.getName());
65              }
66  
67              MethodWrapper methodWrapper = new MethodWrapper(
68                  _TAG_CLASS, _TAG_DO_END_METHOD,
69                  new Object[] {
70                      _PAGE, type, url, title, targetWrapper, pageContext
71                  });
72  
73              returnObj = MethodInvoker.invoke(methodWrapper);
74          }
75          catch (Exception e) {
76              _log.error(e, e);
77          }
78          finally {
79              Thread.currentThread().setContextClassLoader(contextClassLoader);
80          }
81  
82          if (returnObj != null) {
83              return returnObj.toString();
84          }
85          else {
86              return StringPool.BLANK;
87          }
88      }
89  
90      public int doEndTag() throws JspException {
91          try {
92              doTag(_type, _url, _title, _target, pageContext);
93          }
94          catch (Exception e) {
95              if (e instanceof JspException) {
96                  throw (JspException)e;
97              }
98              else {
99                  throw new JspException(e);
100             }
101         }
102 
103         return EVAL_PAGE;
104     }
105 
106     public void setType(String type) {
107         _type = type;
108     }
109 
110     public void setUrl(String url) {
111         _url = url;
112     }
113 
114     public void setTitle(String title) {
115         _title = title;
116     }
117 
118     public void setTarget(String target) {
119         _target = target;
120     }
121 
122     private static final String _TAG_CLASS =
123         "com.liferay.portal.servlet.taglib.ui.SocialBookmarkTagUtil";
124 
125     private static final String _TAG_DO_END_METHOD = "doEndTag";
126 
127     private static final String _PAGE =
128         "/html/taglib/ui/social_bookmark/page.jsp";
129 
130     private static Log _log = LogFactory.getLog(SocialBookmarkTag.class);
131 
132     private String _type;
133     private String _url;
134     private String _title;
135     private String _target;
136 
137 }