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.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  /**
45   * ResourceEnhancer : handles {@link IResourceDisplayManager} and {@link IResourceManager}
46   */
47  public final class ResourceEnhancer
48  {
49      /**
50       * Empty constructor
51       */
52      private ResourceEnhancer(  )
53      {
54          // nothing
55      }
56  
57      // IResourceDisplayManager facade
58  
59      /**
60       * Add to the the XML String additional datas
61       * @param strXml The xml string use by stylesheet
62       * @param strResourceType the resource type
63       * @param nResourceId The resource Id
64       */
65      public static void getXmlAddOn( StringBuffer strXml, String strResourceType, int nResourceId )
66      {
67          List<IResourceDisplayManager> managers = SpringContextService.getBeansOfType( IResourceDisplayManager.class );
68  
69          for ( IResourceDisplayManager manager : managers )
70          {
71              manager.getXmlAddOn( strXml, strResourceType, nResourceId );
72          }
73      }
74  
75      /**
76       * Add datas to the model use by document template
77       *
78       * @param model The model use by document template
79       * @param strResourceType the ressource Type
80       * @param nIdResource The resource id
81       * @param strPortletId The portlet ID
82       * @param request The HTTP Request
83       */
84      public static void buildPageAddOn( Map<String, Object> model, String strResourceType, int nIdResource,
85          String strPortletId, HttpServletRequest request )
86      {
87          List<IResourceDisplayManager> managers = SpringContextService.getBeansOfType( IResourceDisplayManager.class );
88  
89          for ( IResourceDisplayManager manager : managers )
90          {
91              manager.buildPageAddOn( model, strResourceType, nIdResource, strPortletId, request );
92          }
93      }
94  
95      // IResourceManage facade
96  
97      /**
98       * Add datas to the create document model use in the template
99       * @param model the map use in the template
100      */
101     public static void getCreateResourceModelAddOn( Map<String, Object> model )
102     {
103         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
104 
105         for ( IResourceManager manager : managers )
106         {
107             manager.getCreateResourceModelAddOn( model );
108         }
109     }
110 
111     /**
112      * Perform actions associated to the document creation
113      * @param request The HTTP request
114      * @param strResourceType the resource type
115      * @param nResourceId the resource id
116      */
117     public static void doCreateResourceAddOn( HttpServletRequest request, String strResourceType, int nResourceId )
118     {
119         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
120 
121         for ( IResourceManager manager : managers )
122         {
123             manager.doCreateResourceAddOn( request, strResourceType, nResourceId );
124         }
125     }
126 
127     /**
128      * Add datas to the modify document model use in the template
129      * @param model the map use in the template
130      * @param strResourceType the resource type
131      * @param nResourceId the resource id
132      */
133     public static void getModifyResourceModelAddOn( Map<String, Object> model, String strResourceType, int nResourceId )
134     {
135         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
136 
137         for ( IResourceManager manager : managers )
138         {
139             manager.getModifyResourceModelAddOn( model, strResourceType, nResourceId );
140         }
141     }
142 
143     /**
144      * Perform actions associated to the document modification
145      * @param request The HTTP request
146      * @param strResourceType the resource type
147      * @param nResourceId the resource id
148      */
149     public static void doModifyResourceAddOn( HttpServletRequest request, String strResourceType, int nResourceId )
150     {
151         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
152 
153         for ( IResourceManager manager : managers )
154         {
155             manager.doModifyResourceAddOn( request, strResourceType, nResourceId );
156         }
157     }
158 
159     /**
160      * Perform actions associated to the document deletion
161      * @param request The HTTP request
162      * @param strResourceType the resource type
163      * @param nResourceId the resource id
164      */
165     public static void doDeleteResourceAddOn( HttpServletRequest request, String strResourceType, int nResourceId )
166     {
167         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
168 
169         for ( IResourceManager manager : managers )
170         {
171             manager.doDeleteResourceAddOn( request, strResourceType, nResourceId );
172         }
173     }
174 
175     /**
176      * Perform actions associated to the document download
177      * @param request The HTTP request
178      * @param strResourceType the resource type
179      * @param nResourceId the resource id
180      */
181     public static void doDownloadResourceAddOn( HttpServletRequest request, String strResourceType, int nResourceId )
182     {
183         List<IResourceManager> managers = SpringContextService.getBeansOfType( IResourceManager.class );
184 
185         for ( IResourceManager manager : managers )
186         {
187             manager.doDownloadResourceAddOn( request, strResourceType, nResourceId );
188         }
189     }
190 }