1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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  public class EncryptTag extends TagSupport {
42  
43      public int doStartTag() throws JspException {
44          Thread currentThread = Thread.currentThread();
45  
46          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
47  
48          try {
49              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              currentThread.setContextClassLoader(contextClassLoader);
66          }
67  
68          return EVAL_BODY_INCLUDE;
69      }
70  
71      public int doEndTag() throws JspException {
72          Thread currentThread = Thread.currentThread();
73  
74          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
75  
76          try {
77              currentThread.setContextClassLoader(
78                  PortalClassLoaderUtil.getClassLoader());
79  
80              MethodWrapper methodWrapper = new MethodWrapper(
81                  _TAG_CLASS, _TAG_DO_END_METHOD, new Object[] {pageContext});
82  
83              MethodInvoker.invoke(methodWrapper);
84          }
85          catch (Exception e) {
86              throw new JspException(e);
87          }
88          finally {
89              currentThread.setContextClassLoader(contextClassLoader);
90          }
91  
92          return EVAL_PAGE;
93      }
94  
95      public void setClassName(String className) {
96          _className = className;
97      }
98  
99      public void setStyle(String style) {
100         _style = style;
101     }
102 
103     public void setProtocol(String protocol) {
104         _protocol = protocol;
105     }
106 
107     public void setUnencryptedParams(String unencryptedParams) {
108         _unencryptedParamsSet.clear();
109 
110         String[] unencryptedParamsArray = StringUtil.split(unencryptedParams);
111 
112         for (int i = 0; i < unencryptedParamsArray.length; i++) {
113             _unencryptedParamsSet.add(unencryptedParamsArray[i]);
114         }
115     }
116 
117     public void setUrl(String url) {
118         _url = url;
119     }
120 
121     public void setTarget(String target) {
122         _target = target;
123     }
124 
125     private static final String _TAG_CLASS =
126         "com.liferay.portal.servlet.taglib.security.EncryptTagUtil";
127 
128     private static final String _TAG_DO_START_METHOD = "doStartTag";
129 
130     private static final String _TAG_DO_END_METHOD = "doEndTag";
131 
132     private String _className;
133     private String _style;
134     private String _protocol;
135     private Set<String> _unencryptedParamsSet = new HashSet<String>();
136     private String _url;
137     private String _target;
138 
139 }