1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.taglib.security;
24  
25  import com.liferay.portal.kernel.util.MethodInvoker;
26  import com.liferay.portal.kernel.util.MethodWrapper;
27  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
28  import com.liferay.portal.kernel.util.StringUtil;
29  
30  import java.util.HashSet;
31  import java.util.Set;
32  
33  import javax.servlet.jsp.JspException;
34  import javax.servlet.jsp.tagext.TagSupport;
35  
36  /**
37   * <a href="EncryptTag.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class EncryptTag extends TagSupport {
43  
44      public int doStartTag() throws JspException {
45          ClassLoader contextClassLoader =
46              Thread.currentThread().getContextClassLoader();
47  
48          try {
49              Thread.currentThread().setContextClassLoader(
50                  PortalClassLoaderUtil.getClassLoader());
51  
52              MethodWrapper methodWrapper = new MethodWrapper(
53                  _TAG_CLASS, _TAG_DO_START_METHOD,
54                  new Object[] {
55                      _className, _style, _protocol, _unencryptedParamsSet, _url,
56                      _target, pageContext
57                  });
58  
59              MethodInvoker.invoke(methodWrapper);
60          }
61          catch (Exception e) {
62              throw new JspException(e);
63          }
64          finally {
65              Thread.currentThread().setContextClassLoader(contextClassLoader);
66          }
67  
68          return EVAL_BODY_INCLUDE;
69      }
70  
71      public int doEndTag() throws JspException {
72          ClassLoader contextClassLoader =
73              Thread.currentThread().getContextClassLoader();
74  
75          try {
76              Thread.currentThread().setContextClassLoader(
77                  PortalClassLoaderUtil.getClassLoader());
78  
79              MethodWrapper methodWrapper = new MethodWrapper(
80                  _TAG_CLASS, _TAG_DO_END_METHOD, new Object[] {pageContext});
81  
82              MethodInvoker.invoke(methodWrapper);
83          }
84          catch (Exception e) {
85              throw new JspException(e);
86          }
87          finally {
88              Thread.currentThread().setContextClassLoader(contextClassLoader);
89          }
90  
91          return EVAL_PAGE;
92      }
93  
94      public void setClassName(String className) {
95          _className = className;
96      }
97  
98      public void setStyle(String style) {
99          _style = style;
100     }
101 
102     public void setProtocol(String protocol) {
103         _protocol = protocol;
104     }
105 
106     public void setUnencryptedParams(String unencryptedParams) {
107         _unencryptedParamsSet.clear();
108 
109         String[] unencryptedParamsArray = StringUtil.split(unencryptedParams);
110 
111         for (int i = 0; i < unencryptedParamsArray.length; i++) {
112             _unencryptedParamsSet.add(unencryptedParamsArray[i]);
113         }
114     }
115 
116     public void setUrl(String url) {
117         _url = url;
118     }
119 
120     public void setTarget(String target) {
121         _target = target;
122     }
123 
124     private static final String _TAG_CLASS =
125         "com.liferay.portal.servlet.taglib.security.EncryptTagUtil";
126 
127     private static final String _TAG_DO_START_METHOD = "doStartTag";
128 
129     private static final String _TAG_DO_END_METHOD = "doEndTag";
130 
131     private String _className;
132     private String _style;
133     private String _protocol;
134     private Set _unencryptedParamsSet = new HashSet();
135     private String _url;
136     private String _target;
137 
138 }