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.portal.business.workgroup;
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 describes a workgroup used by the administration
49   */
50  public class AdminWorkgroupFilter
51  {
52      // Constants
53      private static final String CONSTANT_EQUAL = "=";
54      private static final String CONSTANT_ESPERLUETTE = "&";
55  
56      // Parameters
57      private static final String PARAMETER_SEARCH_IS_SEARCH = "search_is_search";
58      private static final String PARAMETER_SEARCH_KEY = "search_key";
59      private static final String PARAMETER_SEARCH_DESCRIPTION = "search_description";
60  
61      // Properties
62      private static final String PROPERTY_ENCODING_URL = "lutece.encoding.url";
63      private String _strKey;
64      private String _strDescription;
65  
66      /**
67       * Constructor
68       */
69      public AdminWorkgroupFilter(  )
70      {
71      }
72  
73      /**
74       * Initialize each component of the object
75       */
76      public void init(  )
77      {
78          _strKey = "";
79          _strDescription = "";
80      }
81  
82      /**
83       * Gets the workgroup key
84       * @return Returns the Key.
85       */
86      public String getKey(  )
87      {
88          return _strKey;
89      }
90  
91      /**
92       * Sets the workgroup key
93       *
94       * @param strKey The Key
95       */
96      public void setKey( String strKey )
97      {
98          _strKey = strKey;
99      }
100 
101     /**
102      * Returns the workgroup's description
103      * @return Returns the Description.
104      */
105     public String getDescription(  )
106     {
107         return _strDescription;
108     }
109 
110     /**
111      * Sets the workgroup's description
112      *
113      * @param strDescription The workgroup's description
114      */
115     public void setDescription( String strDescription )
116     {
117         _strDescription = strDescription;
118     }
119 
120     /**
121      * Gets the workgroup key
122      *
123      * @return The workgroup key
124      */
125     public String getWorkgroup(  )
126     {
127         return getKey(  );
128     }
129 
130     /**
131      * Set the value of the AdminWorkgroupFilter
132      * @param request HttpServletRequest
133      * @return true if there is a search
134      */
135     public boolean setAdminWorkgroupFilter( HttpServletRequest request )
136     {
137         boolean bIsSearch = false;
138         String strIsSearch = request.getParameter( PARAMETER_SEARCH_IS_SEARCH );
139 
140         if ( strIsSearch != null )
141         {
142             bIsSearch = true;
143             _strKey = request.getParameter( PARAMETER_SEARCH_KEY );
144             _strDescription = request.getParameter( PARAMETER_SEARCH_DESCRIPTION );
145         }
146         else
147         {
148             init(  );
149         }
150 
151         return bIsSearch;
152     }
153 
154     /**
155      * Build url attributes
156      * @param url The url item
157      */
158     public void setUrlAttributes( UrlItem url )
159     {
160         url.addParameter( PARAMETER_SEARCH_IS_SEARCH, Boolean.TRUE.toString(  ) );
161 
162         try
163         {
164             url.addParameter( PARAMETER_SEARCH_KEY,
165                 URLEncoder.encode( _strKey, AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
166             url.addParameter( PARAMETER_SEARCH_DESCRIPTION,
167                 URLEncoder.encode( _strDescription, AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
168         }
169         catch ( UnsupportedEncodingException e )
170         {
171             AppLogService.error( e.getMessage(  ), e );
172         }
173     }
174 
175     /**
176      * Build url attributes
177      * @return the url attributes
178      */
179     public String getUrlAttributes(  )
180     {
181         StringBuilder sbUrlAttributes = new StringBuilder(  );
182         sbUrlAttributes.append( PARAMETER_SEARCH_IS_SEARCH + CONSTANT_EQUAL + Boolean.TRUE );
183 
184         try
185         {
186             sbUrlAttributes.append( CONSTANT_ESPERLUETTE + PARAMETER_SEARCH_KEY + CONSTANT_EQUAL +
187                 URLEncoder.encode( _strKey, AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
188             sbUrlAttributes.append( CONSTANT_ESPERLUETTE + PARAMETER_SEARCH_DESCRIPTION + CONSTANT_EQUAL +
189                 URLEncoder.encode( _strDescription, AppPropertiesService.getProperty( PROPERTY_ENCODING_URL ) ) );
190         }
191         catch ( UnsupportedEncodingException e )
192         {
193             AppLogService.error( e.getMessage(  ), e );
194         }
195 
196         return sbUrlAttributes.toString(  );
197     }
198 }