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
44 public class SocialBookmarkTag extends IncludeTag {
45
46 public static String doTag(
47 String type, String url, String title, String target,
48 PageContext pageContext)
49 throws Exception {
50
51 return doTag(_PAGE, type, url, title, target, pageContext);
52 }
53
54 public static String doTag(
55 String page, String type, String url, String title, String target,
56 PageContext pageContext)
57 throws Exception {
58
59 Object returnObj = null;
60
61 Thread currentThread = Thread.currentThread();
62
63 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
64
65 try {
66 currentThread.setContextClassLoader(
67 PortalClassLoaderUtil.getClassLoader());
68
69 Object targetWrapper = target;
70
71 if (targetWrapper == null) {
72 targetWrapper = new NullWrapper(String.class.getName());
73 }
74
75 MethodWrapper methodWrapper = new MethodWrapper(
76 _TAG_CLASS, _TAG_DO_END_METHOD,
77 new Object[] {
78 page, type, url, title, targetWrapper, pageContext
79 });
80
81 returnObj = MethodInvoker.invoke(methodWrapper);
82 }
83 catch (Exception e) {
84 _log.error(e, e);
85 }
86 finally {
87 currentThread.setContextClassLoader(contextClassLoader);
88 }
89
90 if (returnObj != null) {
91 return returnObj.toString();
92 }
93 else {
94 return StringPool.BLANK;
95 }
96 }
97
98 public int doEndTag() throws JspException {
99 try {
100 doTag(getPage(), _type, _url, _title, _target, pageContext);
101 }
102 catch (Exception e) {
103 if (e instanceof JspException) {
104 throw (JspException)e;
105 }
106 else {
107 throw new JspException(e);
108 }
109 }
110
111 return EVAL_PAGE;
112 }
113
114 public void setType(String type) {
115 _type = type;
116 }
117
118 public void setUrl(String url) {
119 _url = url;
120 }
121
122 public void setTitle(String title) {
123 _title = title;
124 }
125
126 public void setTarget(String target) {
127 _target = target;
128 }
129
130 protected String getDefaultPage() {
131 return _PAGE;
132 }
133
134 private static final String _TAG_CLASS =
135 "com.liferay.portal.servlet.taglib.ui.SocialBookmarkTagUtil";
136
137 private static final String _TAG_DO_END_METHOD = "doEndTag";
138
139 private static final String _PAGE =
140 "/html/taglib/ui/social_bookmark/page.jsp";
141
142 private static Log _log = LogFactoryUtil.getLog(SocialBookmarkTag.class);
143
144 private String _type;
145 private String _url;
146 private String _title;
147 private String _target;
148
149 }