1
22
23 package com.liferay.taglib.security;
24
25 import com.liferay.portal.kernel.util.BooleanWrapper;
26 import com.liferay.portal.kernel.util.LongWrapper;
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
33 import javax.servlet.jsp.JspException;
34 import javax.servlet.jsp.PageContext;
35 import javax.servlet.jsp.tagext.TagSupport;
36
37 import org.apache.commons.logging.Log;
38 import org.apache.commons.logging.LogFactory;
39
40
46 public class DoAsURLTag extends TagSupport {
47
48 public static String doTag(
49 long doAsUserId, String var, boolean writeOutput,
50 PageContext pageContext)
51 throws Exception {
52
53 Object returnObj = null;
54
55 ClassLoader contextClassLoader =
56 Thread.currentThread().getContextClassLoader();
57
58 try {
59 Thread.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 Thread.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 = LogFactory.getLog(DoAsURLTag.class);
122
123 private long _doAsUserId;
124 private String _var;
125
126 }