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.dila.business.stylesheet.dao.impl;
35  
36  import fr.paris.lutece.plugins.dila.business.stylesheet.dao.IContentTypeDAO;
37  import fr.paris.lutece.plugins.dila.business.stylesheet.dto.ContentType;
38  import fr.paris.lutece.plugins.dila.service.DilaPlugin;
39  import fr.paris.lutece.portal.service.plugin.PluginService;
40  import fr.paris.lutece.util.sql.DAOUtil;
41  
42  import java.io.Serializable;
43  import java.util.ArrayList;
44  import java.util.List;
45  
46  
47  /**
48   * The Class ContentTypeDAO. Gives access to "ContentType" data.
49   */
50  public class ContentTypeDAO implements IContentTypeDAO, Serializable
51  {
52      /** Serial ID */
53      private static final long serialVersionUID = -5939477738412898729L;
54  
55      /** The Constant SQL_QUERY_SELECT_ALL_TYPE_CONTENU. */
56      private static final String SQL_QUERY_SELECT_ALL_CONTENT_TYPE = "SELECT id, label FROM dila_content_type ORDER BY id ASC";
57      private static final String SQL_QUERY_SELECT = "SELECT id, label FROM dila_content_type WHERE id = ?";
58      private static final String SQL_QUERY_SELECT_CONTENT_TYPE_WITHOUT_ASSOCIATED_STYLESHEET = "SELECT id, label FROM dila_content_type WHERE id NOT IN (SELECT content_type_id FROM dila_stylesheet WHERE id_stylesheet <> ? ) ORDER BY id ASC";
59  
60      @Override
61      public List<ContentType> getContentTypes( )
62      {
63          List<ContentType> result = new ArrayList<ContentType>( );
64  
65          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALL_CONTENT_TYPE,
66                  PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) );
67  
68          daoUtil.executeQuery( );
69  
70          while ( daoUtil.next( ) )
71          {
72              ContentType contentType = new ContentType( );
73              contentType.setId( daoUtil.getInt( 1 ) );
74              contentType.setLabel( daoUtil.getString( 2 ) );
75  
76              result.add( contentType );
77          }
78  
79          daoUtil.free( );
80  
81          return result;
82      }
83  
84      @Override
85      public ContentType findByPrimaryKey( Integer nIdTypeContenu )
86      {
87          ContentType contentType = null;
88          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) );
89          daoUtil.setInt( 1, nIdTypeContenu );
90  
91          daoUtil.executeQuery( );
92  
93          if ( daoUtil.next( ) )
94          {
95              contentType = new ContentType( );
96              contentType.setId( daoUtil.getInt( 1 ) );
97              contentType.setLabel( daoUtil.getString( 2 ) );
98          }
99  
100         daoUtil.free( );
101 
102         return contentType;
103     }
104 
105     @Override
106     public List<ContentType> getContentTypesWithoutAssociatedStyleSheet( Integer nIdStylesheet )
107     {
108         List<ContentType> result = new ArrayList<ContentType>( );
109 
110         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_CONTENT_TYPE_WITHOUT_ASSOCIATED_STYLESHEET,
111                 PluginService.getPlugin( DilaPlugin.PLUGIN_NAME ) );
112         daoUtil.setInt( 1, nIdStylesheet );
113 
114         daoUtil.executeQuery( );
115 
116         while ( daoUtil.next( ) )
117         {
118             ContentType typeContenu = new ContentType( );
119             typeContenu.setId( daoUtil.getInt( 1 ) );
120             typeContenu.setLabel( daoUtil.getString( 2 ) );
121 
122             result.add( typeContenu );
123         }
124 
125         daoUtil.free( );
126 
127         return result;
128     }
129 }