View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.links.business;
35  
36  import fr.paris.lutece.portal.service.image.ImageResource;
37  import fr.paris.lutece.portal.service.spring.SpringContextService;
38  
39  import java.util.Collection;
40  
41  
42  /**
43   * This class provides instances management methods (create, find, ...) for Link objects
44   */
45  public final class LinkHome
46  {
47      // Static variable pointed at the DAO instance
48      private static ILinkDAO _dao = SpringContextService.getBean( "linkDAO" );
49  
50      /**
51       * Private constructor - this class need not be instantiated
52       */
53      private LinkHome(  )
54      {
55      }
56  
57      /**
58       * Create the link wich is specified in parameter
59       *
60       * @param link The instance  of link wich contains the data to store
61       * @return The instance of the link wich has been created with a primary key.
62       */
63      public static Linkef="../../../../../../fr/paris/lutece/plugins/links/business/Link.html#Link">Link create( Link link )
64      {
65          _dao.insert( link );
66  
67          return link;
68      }
69  
70      /**
71       * Returns an instance of link whose identifier is specified in parameter
72       *
73       * @param nKey The identifier (primary key) of the link
74       * @return An instance of link object
75       */
76      public static Link findByPrimaryKey( int nKey )
77      {
78          return _dao.load( nKey );
79      }
80  
81      /**
82       * Return the list of all the links
83       *
84       * @return A collection of links objects
85       */
86      public static Collection<Link> getLinksList(  )
87      {
88          return _dao.selectList(  );
89      }
90  
91      /**
92       * Update the link wich is specified in parameter
93       *
94       * @param link The instance  of link wich contains the data to store
95       */
96      public static void update( Link link )
97      {
98          _dao.store( link );
99      }
100 
101     /**
102      * Remove the link whose identifier is specified in parameter
103      *
104      * @param nLinkId The identifier of the link to remove
105      */
106     public static void delete( int nLinkId )
107     {
108         //link.doUnselect();
109         _dao.delete( nLinkId );
110     }
111 
112     /**
113      * Return a collection of all the links in a defined portlet
114      *
115      * @param nPortletId The identifier of the portlet
116      * @return a links collection
117      */
118     public static Collection<Link> findByPortlet( int nPortletId )
119     {
120         return _dao.selectByPortlet( nPortletId );
121     }
122 
123     /**
124     *
125     * @param nLinkId
126     * @return ImageResource
127     */
128     public static ImageResource getImageResource( int nLinkId )
129     {
130         return _dao.loadImageResource( nLinkId );
131     }
132 }