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.xsl;
35
36 import fr.paris.lutece.portal.business.file.FileHome;
37 import fr.paris.lutece.portal.service.html.XmlTransformerService;
38 import fr.paris.lutece.portal.service.plugin.Plugin;
39 import fr.paris.lutece.portal.service.spring.SpringContextService;
40 import fr.paris.lutece.util.ReferenceList;
41
42 import java.util.List;
43
44
45 /**
46 * This class provides instances management methods (create, find, ...) for ExportFormat objects
47 */
48 public final class XslExportHome
49 {
50 // Static variable pointed at the DAO instance
51 private static IXslExportDAO _dao = SpringContextService.getBean( "xslExportDAO" );
52
53 /**
54 * Private constructor - this class do not need to be instantiated
55 */
56 private XslExportHome( )
57 {
58 }
59
60 /**
61 * Creation of an instance of Xsl Export
62 *
63 * @param xslExport The instance of the xslExport which contains the informations to store
64 *
65 */
66 public static void create( XslExport xslExport )
67 {
68 _dao.insert( xslExport );
69 }
70
71 /**
72 * Update of the XslExport which is specified in parameter
73 *
74 * @param xslExport The instance of the xslExport which contains the informations to update
75 */
76 public static void update( XslExport xslExport )
77 {
78 _dao.store( xslExport );
79 XmlTransformerService.clearXslCache( );
80 }
81
82 /**
83 * Remove the XslExport whose identifier is specified in parameter
84 *
85 * @param nIdXslExport The XslExport Id
86 */
87 public static void remove( int nIdXslExport )
88 {
89 _dao.delete( nIdXslExport );
90 XmlTransformerService.clearXslCache( );
91 }
92
93 // /////////////////////////////////////////////////////////////////////////
94 // Finders
95
96 /**
97 * Returns an instance of a XslExport whose identifier is specified in parameter
98 *
99 * @param nKey The xslExport primary key
100 * @return an instance of XslExport
101 */
102 public static XslExport findByPrimaryKey( int nKey )
103 {
104 XslExport xslExport = _dao.load( nKey );
105
106 if ( ( xslExport != null ) && ( xslExport.getFile( ) != null ) )
107 {
108 xslExport.setFile( FileHome.findByPrimaryKey( xslExport.getFile( ).getIdFile( ) ) );
109 }
110
111 return xslExport;
112 }
113
114 /**
115 * Loads the data of all the XslExport and returns them in a list
116 * @return the list which contains the data of every Xsl export items
117 */
118 public static List<XslExport> getList( )
119 {
120 return _dao.selectList( );
121 }
122
123 /**
124 * Loads the data of XslExport associated with a given plugin and returns
125 * them in a list
126 * @param plugin The plugin
127 * @return the list which contains the data of Xsl export items
128 */
129 public static List<XslExport> getListByPlugin( Plugin plugin )
130 {
131 return _dao.selectListByPlugin( plugin );
132 }
133
134 /**
135 * Loads in the reference list the data of all the XslExport and returns
136 * them in a list
137 * @return the list which contains the data of every Xsl Export items
138 */
139 public static ReferenceList getRefList( )
140 {
141 ReferenceList refList = new ReferenceList( );
142
143 List<XslExport> xslList = getList( );
144
145 for ( XslExport xslExport : xslList )
146 {
147 refList.addItem( xslExport.getIdXslExport( ), xslExport.getTitle( ) );
148 }
149
150 return refList;
151 }
152
153 /**
154 * Loads the data of XslExport associated with a given plugin and returns
155 * them in a list
156 * @param plugin The plugin
157 * @return the list which contains the data of Xsl export items
158 */
159 public static ReferenceList getRefListByPlugin( Plugin plugin )
160 {
161 ReferenceList refList = new ReferenceList( );
162
163 List<XslExport> xslList = getListByPlugin( plugin );
164
165 for ( XslExport xslExport : xslList )
166 {
167 refList.addItem( xslExport.getIdXslExport( ), xslExport.getTitle( ) );
168 }
169
170 return refList;
171 }
172 }