View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of 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  /*
35   * AnnounceUtils.java
36   *
37   * Created on 23 octobre 2009, 11:31
38   *
39   * To change this template, choose Tools | Template Manager
40   * and open the template in the editor.
41   */
42  package fr.paris.lutece.plugins.blog.utils;
43  
44  import fr.paris.lutece.plugins.blog.service.BlogPlugin;
45  import fr.paris.lutece.portal.service.plugin.Plugin;
46  import fr.paris.lutece.portal.service.plugin.PluginService;
47  
48  import java.util.List;
49  
50  import javax.servlet.http.HttpServletRequest;
51  import javax.servlet.http.HttpServletResponse;
52  
53  /**
54   * Utility class for announce plugin
55   */
56  public final class BlogUtils
57  {
58      // Constants
59      public static final String CONSTANT_WHERE = " WHERE ";
60      public static final String CONSTANT_AND = " AND ";
61      public static final int CONSTANT_ID_NULL = -1;
62      public static final String CONSTANT_TYPE_RESOURCE = "BLOG_DOCUMENT";
63  
64      /**
65       * Private default constructor
66       */
67      private BlogUtils( )
68      {
69          // Do nothing
70      }
71  
72      /**
73       * Builds a query with filters placed in parameters
74       * 
75       * @param strSelect
76       *            the select of the query
77       * @param listStrFilter
78       *            the list of filter to add in the query
79       * @param strOrder
80       *            the order by of the query
81       * @return a query
82       */
83      public static String buildRequetteWithFilter( String strSelect, List<String> listStrFilter, String strOrder )
84      {
85          StringBuilder strBuffer = new StringBuilder( );
86          strBuffer.append( strSelect );
87  
88          int nCount = 0;
89  
90          for ( String strFilter : listStrFilter )
91          {
92              if ( ++nCount == 1 )
93              {
94                  strBuffer.append( CONSTANT_WHERE );
95              }
96  
97              strBuffer.append( strFilter );
98  
99              if ( nCount != listStrFilter.size( ) )
100             {
101                 strBuffer.append( CONSTANT_AND );
102             }
103         }
104 
105         if ( strOrder != null )
106         {
107             strBuffer.append( strOrder );
108         }
109 
110         return strBuffer.toString( );
111     }
112 
113     /**
114      * write the http header in the response
115      *
116      * @param request
117      *            the httpServletRequest
118      * @param response
119      *            the http response
120      * @param strFileName
121      *            the name of the file who must insert in the response
122      *
123      */
124     public static void addHeaderResponse( HttpServletRequest request, HttpServletResponse response, String strFileName )
125     {
126         response.setHeader( "Content-Disposition", "attachment ;filename=\"" + strFileName + "\"" );
127         response.setHeader( "Pragma", "public" );
128         response.setHeader( "Expires", "0" );
129         response.setHeader( "Cache-Control", "must-revalidate,post-check=0,pre-check=0" );
130     }
131 
132     /**
133      * Gets the plugin
134      *
135      * @return the plugin
136      */
137     public static Plugin getPlugin( )
138     {
139         return PluginService.getPlugin( BlogPlugin.PLUGIN_NAME );
140     }
141 }