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