1 /*
2 * Copyright (c) 2002-2021, City of 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.extend.service.extender;
35
36 import fr.paris.lutece.plugins.extend.web.component.IResourceExtenderComponent;
37 import fr.paris.lutece.portal.service.i18n.I18nService;
38
39 import org.springframework.beans.factory.InitializingBean;
40
41 import org.springframework.util.Assert;
42
43 import java.util.Locale;
44 import org.apache.commons.lang3.StringUtils;
45
46 /**
47 *
48 * AbstractResourceExtender
49 *
50 */
51 public abstract class AbstractResourceExtender implements IResourceExtender, InitializingBean
52 {
53 private String _strKey;
54 private String _strI18nTitleKey;
55 private boolean _bIsConfigRequired;
56 private boolean _bIsHistoryEnable;
57 private boolean _bIsStateEnable;
58 private IResourceExtenderComponent _resourceExtenderComponent;
59
60 /**
61 * {@inheritDoc}
62 */
63 @Override
64 public String getKey( )
65 {
66 return _strKey;
67 }
68
69 /**
70 * {@inheritDoc}
71 */
72 @Override
73 public void setKey( String strKey )
74 {
75 _strKey = strKey;
76 }
77
78 /**
79 * {@inheritDoc}
80 */
81 @Override
82 public String getTitle( Locale locale )
83 {
84 return I18nService.getLocalizedString( _strI18nTitleKey, locale );
85 }
86
87 /**
88 * {@inheritDoc}
89 */
90 @Override
91 public void setI18nTitleKey( String strI18nTitleKey )
92 {
93 _strI18nTitleKey = strI18nTitleKey;
94 }
95
96 /**
97 * @return the bIsConfigRequired
98 */
99 @Override
100 public boolean isConfigRequired( )
101 {
102 return _bIsConfigRequired;
103 }
104
105 /**
106 * @param bIsConfigRequired
107 * the bIsConfigRequired to set
108 */
109 public void setConfigRequired( boolean bIsConfigRequired )
110 {
111 _bIsConfigRequired = bIsConfigRequired;
112 }
113
114 /**
115 * {@inheritDoc}
116 */
117 @Override
118 public boolean isHistoryEnable( )
119 {
120 return _bIsHistoryEnable;
121 }
122
123 /**
124 * @param bIsHistoryEnable
125 * the bIsHistoryEnable to set
126 */
127 public void setHistoryEnable( boolean bIsHistoryEnable )
128 {
129 _bIsHistoryEnable = bIsHistoryEnable;
130 }
131
132 /**
133 * @return the _bIsStateEnable
134 */
135 public boolean isStateEnable( )
136 {
137 return _bIsStateEnable;
138 }
139
140 /**
141 * @param bIsStateEnable
142 * the _bIsStateEnable to set
143 */
144 public void setStateEnable( boolean bIsStateEnable )
145 {
146 this._bIsStateEnable = bIsStateEnable;
147 }
148
149 /**
150 * @return the resourceExtenderComponent
151 */
152 public IResourceExtenderComponent getResourceExtenderComponent( )
153 {
154 return _resourceExtenderComponent;
155 }
156
157 /**
158 * Sets the resource extender component.
159 *
160 * @param resourceExtenderComponent
161 * the new resource extender component
162 */
163 public void setResourceExtenderComponent( IResourceExtenderComponent resourceExtenderComponent )
164 {
165 _resourceExtenderComponent = resourceExtenderComponent;
166 }
167
168 /**
169 * {@inheritDoc}
170 */
171 @Override
172 public void afterPropertiesSet( ) throws Exception
173 {
174 Assert.notNull( _strKey, "The property 'key' must be provided" );
175 Assert.notNull( _strI18nTitleKey, "The property 'i18nTitleKey' must be provided" );
176 Assert.notNull( _resourceExtenderComponent, "The property 'resourceExtenderComponent' must be provided" );
177 }
178
179 /**
180 * {@inheritDoc}
181 */
182 @Override
183 public boolean isInvoked( String strExtenderType )
184 {
185 if ( StringUtils.isNotBlank( strExtenderType ) )
186 {
187 return getKey( ).equals( strExtenderType );
188 }
189
190 return false;
191 }
192
193 }