View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.business;
35  
36  import fr.paris.lutece.portal.service.util.AppLogService;
37  import fr.paris.lutece.portal.service.util.AppPropertiesService;
38  import fr.paris.lutece.util.url.UrlItem;
39  
40  import java.io.UnsupportedEncodingException;
41  
42  import java.net.URLEncoder;
43  
44  import javax.servlet.http.HttpServletRequest;
45  
46  
47  /**
48   * This class provides a filter for users search function
49   */
50  public class WssoProfilFilter
51  {
52      // Constants
53      private static final String EQUAL = "=";
54      private static final String AMPERSAND = "&";
55  
56      // Parameteres
57      private static final String PARAMETER_SEARCH_CODE = "search_code";
58      private static final String PARAMETER_SEARCH_DESCRIPTION = "search_description";
59      private static final String PARAMETER_SEARCH_IS_SEARCH = "search_is_search";
60  
61      // Properties
62      private static final String PROPERTY_ENCODING_URL = "lutece.encoding.url";
63      private String _strCode;
64      private String _strdescription;
65  
66      /**
67       * Constructor
68       */
69      public WssoProfilFilter(  )
70      {
71      }
72  
73      /**
74       * Initialize each component of the object
75       */
76      public void init(  )
77      {
78          _strCode = "";
79          _strdescription = "";
80      }
81  
82      /**
83       * Get the code
84       * @return The code
85       */
86      public String getCode(  )
87      {
88          return _strCode;
89      }
90  
91      /**
92       * Set the code
93       * @param strCode The Code
94       */
95      public void setCode( String strCode )
96      {
97          _strCode = strCode;
98      }
99  
100     /**
101      * Get the
102      * @return The description
103      */
104     public String getDescription(  )
105     {
106         return _strdescription;
107     }
108 
109     /**
110      * Set the descprition
111      * @param strdescription The description
112      */
113     public void setLastName( String strdescription )
114     {
115         _strdescription = strdescription;
116     }
117 
118     /**
119      * Set the value of the AdminUserFilter
120      * @param request HttpServletRequest
121      * @return true if there is a search
122      */
123     public boolean setDatabaseUserFilter( HttpServletRequest request )
124     {
125         boolean bIsSearch = false;
126         String strIsSearch = request.getParameter( PARAMETER_SEARCH_IS_SEARCH );
127 
128         if ( strIsSearch != null )
129         {
130             bIsSearch = true;
131             _strCode = request.getParameter( PARAMETER_SEARCH_CODE );
132             _strdescription = request.getParameter( PARAMETER_SEARCH_DESCRIPTION );
133         }
134         else
135         {
136             init(  );
137         }
138 
139         return bIsSearch;
140     }
141 
142     /**
143      * Build url attributes
144      * @param url the url
145      */
146     public void setUrlAttributes( UrlItem url )
147     {
148         url.addParameter( PARAMETER_SEARCH_IS_SEARCH, Boolean.TRUE.toString(  ) );
149 
150         try
151         {
152             url.addParameter( PARAMETER_SEARCH_CODE,
153                 URLEncoder.encode( _strCode, AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
154             url.addParameter( PARAMETER_SEARCH_DESCRIPTION,
155                 URLEncoder.encode( _strdescription, AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
156         }
157         catch ( UnsupportedEncodingException e )
158         {
159             AppLogService.error( e );
160         }
161     }
162 
163     /**
164      * Build url attributes
165      * @return the url attributes
166      */
167     public String getUrlAttributes(  )
168     {
169         StringBuilder sbUrlAttributes = new StringBuilder(  );
170         sbUrlAttributes.append( PARAMETER_SEARCH_IS_SEARCH + EQUAL + Boolean.TRUE );
171 
172         try
173         {
174             sbUrlAttributes.append( AMPERSAND + PARAMETER_SEARCH_CODE + EQUAL +
175                 URLEncoder.encode( _strCode, AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
176             sbUrlAttributes.append( AMPERSAND + PARAMETER_SEARCH_DESCRIPTION + EQUAL +
177                 URLEncoder.encode( _strdescription, AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
178         }
179         catch ( UnsupportedEncodingException e )
180         {
181             AppLogService.error( e );
182         }
183 
184         return sbUrlAttributes.toString(  );
185     }
186 }