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.dbpage.business.section;
35  
36  import fr.paris.lutece.plugins.dbpage.business.DbPageHome;
37  import fr.paris.lutece.portal.service.template.AppTemplateService;
38  import fr.paris.lutece.portal.service.util.AppLogService;
39  import fr.paris.lutece.portal.service.util.AppPropertiesService;
40  import fr.paris.lutece.util.html.HtmlTemplate;
41  
42  import java.sql.SQLException;
43  
44  import java.util.Collection;
45  import java.util.HashMap;
46  import java.util.List;
47  import java.util.Map;
48  
49  import javax.servlet.http.HttpServletRequest;
50  
51  
52  /**
53   * This class represents business object DbPageSectionSelect
54   */
55  public class DbPageSectionSelect extends DbPageSection
56  {
57      /**
58       *
59       */
60      private static final long serialVersionUID = 672960958632821828L;
61      private static final String MARK_SECTION_TITLE = "section_title";
62      private static final String MARK_SELECT_LIST = "list_select";
63      private static final String PROPERTY_FILES_PATH = "dbpage.files.path";
64      private static final String TEMPLATE_DEFAULT_SELECT = "skin/plugins/dbpage/default_select.html";
65      private static final String TEMPLATE_CREATION_SELECT = "admin/plugins/dbpage/create_section_select.html";
66      private static final String TEMPLATE_MODIFICATION_SELECT = "admin/plugins/dbpage/modify_section_select.html";
67      private static final String MARK_VALUE = "value";
68  
69      /**
70       * Constructor
71       * @param strDescType The type of the section
72       */
73      public DbPageSectionSelect( String strDescType )
74      {
75          this.setIdTypeSignature( serialVersionUID );
76          this.setDescType( strDescType );
77      }
78  
79      /**
80       * Returns the Html Section Table form
81       *
82       * @return the html code of the html Section Table form
83       * @param request
84       *            The request
85       * @param listValues
86       *            the list of id values substitute in the SQL request
87       */
88      public String getHtmlSection( List<String> listValues, HttpServletRequest request )
89      {
90          HashMap rootModel = new HashMap(  );
91          rootModel.put( MARK_SECTION_TITLE, getTitle(  ) );
92  
93          Collection listSelects;
94  
95          try
96          {
97              listSelects = DbPageHome.selectRows( getValuatedQuery( listValues ), getConnectionService( getDbPool(  ) ) );
98              rootModel.put( MARK_SELECT_LIST, listSelects );
99              for( int i=0;i<listValues.size();i++)
100             {
101             	 rootModel.put( MARK_VALUE+(i+1), listValues.get(i) );
102             }
103         }
104         catch ( SQLException e )
105         {
106             AppLogService.error( e );
107         }
108 
109         if ( getTemplatePath(  ).equals( "" ) )
110         {
111           
112             HtmlTemplate tSelect = AppTemplateService.getTemplate( TEMPLATE_DEFAULT_SELECT, request.getLocale(  ),
113                     rootModel );
114 
115             return tSelect.getHtml(  );
116         }
117         else
118         {
119             String strFilePath = AppPropertiesService.getProperty( PROPERTY_FILES_PATH );
120            
121             HtmlTemplate tSelect = AppTemplateService.getTemplate( getTemplatePath(  ), strFilePath,
122                     request.getLocale(  ), rootModel );
123 
124             return tSelect.getHtml(  );
125         }
126     }
127 
128     /**
129      * The type of the section
130      * @return The type of the section
131      */
132     public long getIdType(  )
133     {
134         return getIdTypeSignature(  );
135     }
136 
137     /**
138      * The description of the section type
139      * @return The description of the section type
140      */
141     public String getTypeDescription(  )
142     {
143         return getDescType(  );
144     }
145 
146     /**
147      * The path of the template for creation
148      * @return the path of the creation template
149      */
150     public String getCreationTemplate(  )
151     {
152         return TEMPLATE_CREATION_SELECT;
153     }
154 
155     /**
156      * The path of the template for modification
157      * @return the path of the modification template
158      */
159     public String getModificationTemplate(  )
160     {
161         return TEMPLATE_MODIFICATION_SELECT;
162     }
163 
164     /**
165      * Returns a map with additional markers
166      */
167     public Map<String, Object> getMarkMap(  )
168     {
169         Map map = new HashMap(  );
170 
171         return map;
172     }
173 }