1
14
15 package com.liferay.taglib.security;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19 import com.liferay.portal.kernel.util.BooleanWrapper;
20 import com.liferay.portal.kernel.util.MethodInvoker;
21 import com.liferay.portal.kernel.util.MethodWrapper;
22 import com.liferay.portal.kernel.util.NullWrapper;
23 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
24 import com.liferay.portal.kernel.util.StringPool;
25
26 import javax.servlet.jsp.JspException;
27 import javax.servlet.jsp.PageContext;
28 import javax.servlet.jsp.tagext.TagSupport;
29
30
35 public class PermissionsURLTag extends TagSupport {
36
37 public static String doTag(
38 String redirect, String modelResource,
39 String modelResourceDescription, String resourcePrimKey, String var,
40 boolean writeOutput, PageContext pageContext)
41 throws Exception {
42
43 Object returnObj = null;
44
45 Thread currentThread = Thread.currentThread();
46
47 ClassLoader contextClassLoader = currentThread.getContextClassLoader();
48
49 try {
50 currentThread.setContextClassLoader(
51 PortalClassLoaderUtil.getClassLoader());
52
53 Object redirectWrapper = redirect;
54
55 if (redirectWrapper == null) {
56 redirectWrapper = new NullWrapper(String.class.getName());
57 }
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 redirectWrapper, modelResource, modelResourceDescription,
69 resourcePrimKey, varWrapper,
70 new BooleanWrapper(writeOutput), pageContext
71 });
72
73 returnObj = MethodInvoker.invoke(methodWrapper);
74 }
75 catch (Exception e) {
76 _log.error(e, e);
77 }
78 finally {
79 currentThread.setContextClassLoader(contextClassLoader);
80 }
81
82 if (returnObj != null) {
83 return returnObj.toString();
84 }
85 else {
86 return StringPool.BLANK;
87 }
88 }
89
90 public int doEndTag() throws JspException {
91 try {
92 doTag(
93 _redirect, _modelResource, _modelResourceDescription,
94 _resourcePrimKey, _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 setRedirect(String redirect) {
109 _redirect = redirect;
110 }
111
112 public void setModelResource(String modelResource) {
113 _modelResource = modelResource;
114 }
115
116 public void setModelResourceDescription(String modelResourceDescription) {
117 _modelResourceDescription = modelResourceDescription;
118 }
119
120 public void setResourcePrimKey(String resourcePrimKey) {
121 _resourcePrimKey = resourcePrimKey;
122 }
123
124 public void setVar(String var) {
125 _var = var;
126 }
127
128 private static final String _TAG_CLASS =
129 "com.liferay.portal.servlet.taglib.security.PermissionsURLTagUtil";
130
131 private static final String _TAG_DO_END_METHOD = "doEndTag";
132
133 private static Log _log = LogFactoryUtil.getLog(PermissionsURLTag.class);
134
135 private String _redirect;
136 private String _modelResource;
137 private String _modelResourceDescription;
138 private String _resourcePrimKey;
139 private String _var;
140
141 }