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