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.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
31 import javax.servlet.jsp.JspException;
32 import javax.servlet.jsp.PageContext;
33 import javax.servlet.jsp.tagext.TagSupport;
34
35
41 public class PermissionsURLTag extends TagSupport {
42
43 public static String doTag(
44 String redirect, String modelResource,
45 String modelResourceDescription, String resourcePrimKey, String var,
46 boolean writeOutput, 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 redirectWrapper = redirect;
60
61 if (redirectWrapper == null) {
62 redirectWrapper = new NullWrapper(String.class.getName());
63 }
64
65 Object varWrapper = var;
66
67 if (varWrapper == null) {
68 varWrapper = new NullWrapper(String.class.getName());
69 }
70
71 MethodWrapper methodWrapper = new MethodWrapper(
72 _TAG_CLASS, _TAG_DO_END_METHOD,
73 new Object[] {
74 redirectWrapper, modelResource, modelResourceDescription,
75 resourcePrimKey, varWrapper,
76 new BooleanWrapper(writeOutput), pageContext
77 });
78
79 returnObj = MethodInvoker.invoke(methodWrapper);
80 }
81 catch (Exception e) {
82 _log.error(e, e);
83 }
84 finally {
85 currentThread.setContextClassLoader(contextClassLoader);
86 }
87
88 if (returnObj != null) {
89 return returnObj.toString();
90 }
91 else {
92 return StringPool.BLANK;
93 }
94 }
95
96 public int doEndTag() throws JspException {
97 try {
98 doTag(
99 _redirect, _modelResource, _modelResourceDescription,
100 _resourcePrimKey, _var, true, pageContext);
101 }
102 catch (Exception e) {
103 if (e instanceof JspException) {
104 throw (JspException)e;
105 }
106 else {
107 throw new JspException(e);
108 }
109 }
110
111 return EVAL_PAGE;
112 }
113
114 public void setRedirect(String redirect) {
115 _redirect = redirect;
116 }
117
118 public void setModelResource(String modelResource) {
119 _modelResource = modelResource;
120 }
121
122 public void setModelResourceDescription(String modelResourceDescription) {
123 _modelResourceDescription = modelResourceDescription;
124 }
125
126 public void setResourcePrimKey(String resourcePrimKey) {
127 _resourcePrimKey = resourcePrimKey;
128 }
129
130 public void setVar(String var) {
131 _var = var;
132 }
133
134 private static final String _TAG_CLASS =
135 "com.liferay.portal.servlet.taglib.security.PermissionsURLTagUtil";
136
137 private static final String _TAG_DO_END_METHOD = "doEndTag";
138
139 private static Log _log = LogFactoryUtil.getLog(PermissionsURLTag.class);
140
141 private String _redirect;
142 private String _modelResource;
143 private String _modelResourceDescription;
144 private String _resourcePrimKey;
145 private String _var;
146
147 }