1
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
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 }