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