View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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  package fr.paris.lutece.portal.business.resourceenhancer;
35  
36  import fr.paris.lutece.portal.service.spring.SpringContextService;
37  
38  import java.util.List;
39  import java.util.Map;
40  
41  import javax.servlet.http.HttpServletRequest;
42  
43  /**
44   * ResourceEnhancer : handles {@link IResourceDisplayManager} and {@link IResourceManager}
45   */
46  public final class ResourceEnhancer
47  {
48      /**
49       * Empty constructor
50       */
51      private ResourceEnhancer( )
52      {
53          // nothing
54      }
55  
56      // IResourceDisplayManager facade
57  
58      /**
59       * Add to the the XML String additional datas
60       * 
61       * @param strXml
62       *            The xml string use by stylesheet
63       * @param strResourceType
64       *            the resource type
65       * @param nResourceId
66       *            The resource Id
67       */
68      public static void getXmlAddOn( StringBuffer strXml, String strResourceType, int nResourceId )
69      {
70          List<IResourceDisplayManager> managers = SpringContextService.getBeansOfType( IResourceDisplayManager.class );
71  
72          for ( IResourceDisplayManager manager : managers )
73          {
74              manager.getXmlAddOn( strXml, strResourceType, nResourceId );
75          }
76      }
77  
78      /**
79       * Add datas to the model use by document template
80       *
81       * @param model
82       *            The model use by document template
83       * @param strResourceType
84       *            the ressource Type
85       * @param nIdResource
86       *            The resource id
87       * @param strPortletId
88       *            The portlet ID
89       * @param request
90       *            The HTTP Request
91       */
92      public static void buildPageAddOn( Map<String, Object> model, String strResourceType, int nIdResource, String strPortletId, HttpServletRequest request )
93      {
94          List<IResourceDisplayManager> managers = SpringContextService.getBeansOfType( IResourceDisplayManager.class );
95  
96          for ( IResourceDisplayManager manager : managers )
97          {
98              manager.buildPageAddOn( model, strResourceType, nIdResource, strPortletId, request );
99          }
100     }
101 
102     // IResourceManage facade
103 
104     /**
105      * Add datas to the create document model use in the template
106      * 
107      * @param model
108      *            the map use in the template
109      */
110     public static void getCreateResourceModelAddOn( Map<String, Object> model )
111     {
112         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
113 
114         for ( IResourceManager manager : managers )
115         {
116             manager.getCreateResourceModelAddOn( model );
117         }
118     }
119 
120     /**
121      * Perform actions associated to the document creation
122      * 
123      * @param request
124      *            The HTTP request
125      * @param strResourceType
126      *            the resource type
127      * @param nResourceId
128      *            the resource id
129      */
130     public static void doCreateResourceAddOn( HttpServletRequest request, String strResourceType, int nResourceId )
131     {
132         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
133 
134         for ( IResourceManager manager : managers )
135         {
136             manager.doCreateResourceAddOn( request, strResourceType, nResourceId );
137         }
138     }
139 
140     /**
141      * Add datas to the modify document model use in the template
142      * 
143      * @param model
144      *            the map use in the template
145      * @param strResourceType
146      *            the resource type
147      * @param nResourceId
148      *            the resource id
149      */
150     public static void getModifyResourceModelAddOn( Map<String, Object> model, String strResourceType, int nResourceId )
151     {
152         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
153 
154         for ( IResourceManager manager : managers )
155         {
156             manager.getModifyResourceModelAddOn( model, strResourceType, nResourceId );
157         }
158     }
159 
160     /**
161      * Perform actions associated to the document modification
162      * 
163      * @param request
164      *            The HTTP request
165      * @param strResourceType
166      *            the resource type
167      * @param nResourceId
168      *            the resource id
169      */
170     public static void doModifyResourceAddOn( HttpServletRequest request, String strResourceType, int nResourceId )
171     {
172         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
173 
174         for ( IResourceManager manager : managers )
175         {
176             manager.doModifyResourceAddOn( request, strResourceType, nResourceId );
177         }
178     }
179 
180     /**
181      * Perform actions associated to the document deletion
182      * 
183      * @param request
184      *            The HTTP request
185      * @param strResourceType
186      *            the resource type
187      * @param nResourceId
188      *            the resource id
189      */
190     public static void doDeleteResourceAddOn( HttpServletRequest request, String strResourceType, int nResourceId )
191     {
192         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
193 
194         for ( IResourceManager manager : managers )
195         {
196             manager.doDeleteResourceAddOn( request, strResourceType, nResourceId );
197         }
198     }
199 
200     /**
201      * Perform actions associated to the document download
202      * 
203      * @param request
204      *            The HTTP request
205      * @param strResourceType
206      *            the resource type
207      * @param nResourceId
208      *            the resource id
209      */
210     public static void doDownloadResourceAddOn( HttpServletRequest request, String strResourceType, int nResourceId )
211     {
212         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
213 
214         for ( IResourceManager manager : managers )
215         {
216             manager.doDownloadResourceAddOn( request, strResourceType, nResourceId );
217         }
218     }
219 }