1
19
20 package com.liferay.taglib.security;
21
22 import com.liferay.portal.kernel.log.Log;
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
24 import com.liferay.portal.kernel.util.BooleanWrapper;
25 import com.liferay.portal.kernel.util.LongWrapper;
26 import com.liferay.portal.kernel.util.MethodInvoker;
27 import com.liferay.portal.kernel.util.MethodWrapper;
28 import com.liferay.portal.kernel.util.NullWrapper;
29 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
30 import com.liferay.portal.kernel.util.StringPool;
31
32 import javax.servlet.jsp.JspException;
33 import javax.servlet.jsp.PageContext;
34 import javax.servlet.jsp.tagext.TagSupport;
35
36
42 public class DoAsURLTag extends TagSupport {
43
44 public static String doTag(
45 long doAsUserId, String var, boolean writeOutput,
46 PageContext pageContext)
47 throws Exception {
48
49 Object returnObj = null;
50
51 Thread currentThread = Thread.currentThread();
52
53 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
54
55 try {
56 currentThread.setContextClassLoader(
57 PortalClassLoaderUtil.getClassLoader());
58
59 Object varWrapper = var;
60
61 if (varWrapper == null) {
62 varWrapper = new NullWrapper(String.class.getName());
63 }
64
65 MethodWrapper methodWrapper = new MethodWrapper(
66 _TAG_CLASS, _TAG_DO_END_METHOD,
67 new Object[] {
68 new LongWrapper(doAsUserId), varWrapper,
69 new BooleanWrapper(writeOutput), pageContext
70 });
71
72 returnObj = MethodInvoker.invoke(methodWrapper);
73 }
74 catch (Exception e) {
75 _log.error(e, e);
76 }
77 finally {
78 currentThread.setContextClassLoader(contextClassLoader);
79 }
80
81 if (returnObj != null) {
82 return returnObj.toString();
83 }
84 else {
85 return StringPool.BLANK;
86 }
87 }
88
89 public int doEndTag() throws JspException {
90 try {
91 doTag(_doAsUserId, _var, true, pageContext);
92 }
93 catch (Exception e) {
94 if (e instanceof JspException) {
95 throw (JspException)e;
96 }
97 else {
98 throw new JspException(e);
99 }
100 }
101
102 return EVAL_PAGE;
103 }
104
105 public void setDoAsUserId(long doAsUserId) {
106 _doAsUserId = doAsUserId;
107 }
108
109 public void setVar(String var) {
110 _var = var;
111 }
112
113 private static final String _TAG_CLASS =
114 "com.liferay.portal.servlet.taglib.security.DoAsURLTagUtil";
115
116 private static final String _TAG_DO_END_METHOD = "doEndTag";
117
118 private static Log _log = LogFactoryUtil.getLog(DoAsURLTag.class);
119
120 private long _doAsUserId;
121 private String _var;
122
123 }