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