1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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.log.Log;
26  import com.liferay.portal.kernel.log.LogFactoryUtil;
27  import com.liferay.portal.kernel.util.MethodInvoker;
28  import com.liferay.portal.kernel.util.MethodWrapper;
29  import com.liferay.portal.kernel.util.NullWrapper;
30  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.taglib.util.IncludeTag;
33  
34  import javax.servlet.jsp.JspException;
35  import javax.servlet.jsp.PageContext;
36  
37  /**
38   * <a href="SocialBookmarkTag.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author David Truong
41   * @author Jorge Ferrer
42   */
43  public class SocialBookmarkTag extends IncludeTag {
44  
45      public static String doTag(
46              String type, String url, String title, String target,
47              PageContext pageContext)
48          throws Exception {
49  
50          return doTag(_PAGE, type, url, title, target, pageContext);
51      }
52  
53      public static String doTag(
54              String page, String type, String url, String title, String target,
55              PageContext pageContext)
56          throws Exception {
57  
58          Object returnObj = null;
59  
60          Thread currentThread = Thread.currentThread();
61  
62          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
63  
64          try {
65              currentThread.setContextClassLoader(
66                  PortalClassLoaderUtil.getClassLoader());
67  
68              Object targetWrapper = target;
69  
70              if (targetWrapper == null) {
71                  targetWrapper = new NullWrapper(String.class.getName());
72              }
73  
74              MethodWrapper methodWrapper = new MethodWrapper(
75                  _TAG_CLASS, _TAG_DO_END_METHOD,
76                  new Object[] {
77                      page, type, url, title, targetWrapper, pageContext
78                  });
79  
80              returnObj = MethodInvoker.invoke(methodWrapper);
81          }
82          catch (Exception e) {
83              _log.error(e, e);
84          }
85          finally {
86              currentThread.setContextClassLoader(contextClassLoader);
87          }
88  
89          if (returnObj != null) {
90              return returnObj.toString();
91          }
92          else {
93              return StringPool.BLANK;
94          }
95      }
96  
97      public int doEndTag() throws JspException {
98          try {
99              doTag(getPage(), _type, _url, _title, _target, pageContext);
100         }
101         catch (Exception e) {
102             if (e instanceof JspException) {
103                 throw (JspException)e;
104             }
105             else {
106                 throw new JspException(e);
107             }
108         }
109 
110         return EVAL_PAGE;
111     }
112 
113     public void setType(String type) {
114         _type = type;
115     }
116 
117     public void setUrl(String url) {
118         _url = url;
119     }
120 
121     public void setTitle(String title) {
122         _title = title;
123     }
124 
125     public void setTarget(String target) {
126         _target = target;
127     }
128 
129     protected String getDefaultPage() {
130         return _PAGE;
131     }
132 
133     private static final String _TAG_CLASS =
134         "com.liferay.portal.servlet.taglib.ui.SocialBookmarkTagUtil";
135 
136     private static final String _TAG_DO_END_METHOD = "doEndTag";
137 
138     private static final String _PAGE =
139         "/html/taglib/ui/social_bookmark/page.jsp";
140 
141     private static Log _log = LogFactoryUtil.getLog(SocialBookmarkTag.class);
142 
143     private String _type;
144     private String _url;
145     private String _title;
146     private String _target;
147 
148 }