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.service.insert;
35
36 import fr.paris.lutece.portal.service.i18n.I18nService;
37 import fr.paris.lutece.portal.service.i18n.Localizable;
38 import fr.paris.lutece.portal.service.plugin.Plugin;
39 import fr.paris.lutece.portal.service.plugin.PluginService;
40 import fr.paris.lutece.portal.service.rbac.RBACResource;
41 import fr.paris.lutece.portal.service.util.AppException;
42 import fr.paris.lutece.portal.web.insert.InsertServiceSelectionBean;
43
44 import java.util.Locale;
45
46 import javax.servlet.http.HttpServletRequest;
47
48
49 /**
50 * The insert Service
51 */
52 public class InsertService implements RBACResource, Localizable
53 {
54 public static final String RESOURCE_TYPE = "INSERT_SERVICE";
55
56 /** Unique ID of the Service */
57 private String _strId;
58
59 /** Name used in the UI */
60 private String _strNameKey;
61
62 /** Label used in the UI */
63 private String _strLabelKey;
64
65 /** Name of the Bean to use to select a link */
66 private String _strActionBean;
67
68 /** Name of the plugin */
69 private String _strPluginName;
70 private Locale _locale;
71
72 /**
73 * Returns the insert service Id
74 *
75 * @return The Id as a String
76 */
77 public String getId( )
78 {
79 return _strId;
80 }
81
82 /**
83 * Set the Id of the insert service
84 *
85 * @param strId the id
86 */
87 public void setId( String strId )
88 {
89 _strId = strId;
90 }
91
92 /**
93 * Returns the insert service name
94 *
95 * @return The name key as a String
96 */
97 public String getNameKey( )
98 {
99 return _strNameKey;
100 }
101
102 /**
103 * Returns the insert service name
104 *
105 * @return The name as a String
106 */
107 public String getName( )
108 {
109 return I18nService.getLocalizedString( _strNameKey, _locale );
110 }
111
112 /**
113 * Set the name of the insert service
114 *
115 * @param strNameKey the label
116 */
117 public void setNameKey( String strNameKey )
118 {
119 _strNameKey = strNameKey;
120 }
121
122 /**
123 * Returns the insert service label
124 *
125 * @return The label key as a String
126 */
127 public String getLabelKey( )
128 {
129 return _strLabelKey;
130 }
131
132 /**
133 * Returns the insert service label
134 *
135 * @return The label as a String
136 */
137 public String getLabel( )
138 {
139 return I18nService.getLocalizedString( _strLabelKey, _locale );
140 }
141
142 /**
143 * Set the name of the insert service
144 *
145 * @param strLabelKey the label
146 */
147 public void setLabelKey( String strLabelKey )
148 {
149 _strLabelKey = strLabelKey;
150 }
151
152 /**
153 * Returns the ActionBean
154 *
155 * @return The ActionBean as a String
156 */
157 public String getActionBeanString( )
158 {
159 return _strActionBean;
160 }
161
162 /**
163 * Set the ActionBean of the insert service
164 *
165 * @param strActionBean the ActionBean
166 */
167 public void setActionBeanString( String strActionBean )
168 {
169 _strActionBean = strActionBean;
170 }
171
172 /**
173 * Register the name of the Action Bean associated with the service
174 *
175 * @param strSelectionBean The ActionBean to use
176 */
177 public void setActionBeanClassName( String strSelectionBean )
178 {
179 _strActionBean = strSelectionBean;
180 }
181
182 /**
183 * Return the name of the plugin
184 *
185 * @return The name of the plugin
186 */
187 public String getPluginName( )
188 {
189 return _strPluginName;
190 }
191
192 /**
193 * Set the plugin name of the insert service
194 *
195 * @param strPluginName the plugin name
196 */
197 public void setPluginName( String strPluginName )
198 {
199 _strPluginName = strPluginName;
200 }
201
202 /**
203 * Returns the name of the Bean to select an object
204 *
205 * @return an Instance of the Bean
206 * @see fr.paris.lutece.portal.service.LinkService#getActionBean()
207 */
208 public InsertServiceSelectionBean getSelectionActionBean( )
209 {
210 try
211 {
212 return (InsertServiceSelectionBean) Class.forName( getActionBeanString( ) ).newInstance( );
213 }
214 catch ( InstantiationException e )
215 {
216 throw new AppException( "Error instantiating a LinkService Selection Bean : " + e.getMessage( ), e );
217 }
218 catch ( IllegalAccessException e )
219 {
220 throw new AppException( "Error instantiating a LinkService Selection Bean : " + e.getMessage( ), e );
221 }
222 catch ( ClassNotFoundException e )
223 {
224 throw new AppException( "Error instantiating a LinkService Selection Bean : " + e.getMessage( ), e );
225 }
226 }
227
228 /**
229 * Get the UI to select an object
230 *
231 * @param request The Http request.
232 * @return HTML code of the page as string
233 */
234 public String getSelectorUI( HttpServletRequest request )
235 {
236 return getSelectionActionBean( ).getInsertServiceSelectorUI( request );
237 }
238
239 /**
240 * Tells if the insertservice is enable (plugin activated).
241 * @return Returns the state of the insert service : enable or disable
242 */
243 public boolean isEnabled( )
244 {
245 Plugin plugin = PluginService.getPlugin( _strPluginName );
246
247 return plugin.isInstalled( );
248 }
249
250 ////////////////////////////////////////////////////////////////////////////
251 // RBAC Resource implementation
252
253 /**
254 * Returns the Resource Type Code that identify the resource type
255 * @return The Resource Type Code
256 */
257 public String getResourceTypeCode( )
258 {
259 return RESOURCE_TYPE;
260 }
261
262 /**
263 * Returns the resource Id of the current object
264 * @return The resource Id of the current object
265 */
266 public String getResourceId( )
267 {
268 return "" + getId( );
269 }
270
271 /**
272 * Implements Localizable
273 * @param locale The current locale
274 */
275 public void setLocale( Locale locale )
276 {
277 _locale = locale;
278 }
279 }