1   /**
2    * Copyright (c) 2000-2009 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          Thread currentThread = Thread.currentThread();
46  
47          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
48  
49          try {
50              currentThread.setContextClassLoader(
51                  PortalClassLoaderUtil.getClassLoader());
52  
53              MethodWrapper methodWrapper = new MethodWrapper(
54                  _TAG_CLASS, _TAG_DO_START_METHOD,
55                  new Object[] {
56                      _className, _style, _protocol, _unencryptedParamsSet, _url,
57                      _target, pageContext
58                  });
59  
60              MethodInvoker.invoke(methodWrapper);
61          }
62          catch (Exception e) {
63              throw new JspException(e);
64          }
65          finally {
66              currentThread.setContextClassLoader(contextClassLoader);
67          }
68  
69          return EVAL_BODY_INCLUDE;
70      }
71  
72      public int doEndTag() throws JspException {
73          Thread currentThread = Thread.currentThread();
74  
75          ClassLoader contextClassLoader = currentThread.getContextClassLoader();
76  
77          try {
78              currentThread.setContextClassLoader(
79                  PortalClassLoaderUtil.getClassLoader());
80  
81              MethodWrapper methodWrapper = new MethodWrapper(
82                  _TAG_CLASS, _TAG_DO_END_METHOD, new Object[] {pageContext});
83  
84              MethodInvoker.invoke(methodWrapper);
85          }
86          catch (Exception e) {
87              throw new JspException(e);
88          }
89          finally {
90              currentThread.setContextClassLoader(contextClassLoader);
91          }
92  
93          return EVAL_PAGE;
94      }
95  
96      public void setClassName(String className) {
97          _className = className;
98      }
99  
100     public void setStyle(String style) {
101         _style = style;
102     }
103 
104     public void setProtocol(String protocol) {
105         _protocol = protocol;
106     }
107 
108     public void setUnencryptedParams(String unencryptedParams) {
109         _unencryptedParamsSet.clear();
110 
111         String[] unencryptedParamsArray = StringUtil.split(unencryptedParams);
112 
113         for (int i = 0; i < unencryptedParamsArray.length; i++) {
114             _unencryptedParamsSet.add(unencryptedParamsArray[i]);
115         }
116     }
117 
118     public void setUrl(String url) {
119         _url = url;
120     }
121 
122     public void setTarget(String target) {
123         _target = target;
124     }
125 
126     private static final String _TAG_CLASS =
127         "com.liferay.portal.servlet.taglib.security.EncryptTagUtil";
128 
129     private static final String _TAG_DO_START_METHOD = "doStartTag";
130 
131     private static final String _TAG_DO_END_METHOD = "doEndTag";
132 
133     private String _className;
134     private String _style;
135     private String _protocol;
136     private Set<String> _unencryptedParamsSet = new HashSet<String>();
137     private String _url;
138     private String _target;
139 
140 }