1 /*
2 * Copyright (c) 2002-2020, 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.document.business.rules;
35
36 import fr.paris.lutece.portal.business.user.AdminUser;
37
38 import java.util.HashMap;
39 import java.util.Locale;
40 import java.util.Map;
41
42 import javax.servlet.http.HttpServletRequest;
43
44
45 /**
46 * Default implementation of a rule
47 */
48 public abstract class AbstractRule implements Rule
49 {
50 private static final String PARAMETER_RULE_TYPE_ID = "id_rule_type";
51
52 // Variables declarations
53 private int _nIdRule;
54 private String _strIdRuleType;
55 private Map<String, String> _mapAttributes = new HashMap<String, String>( );
56 private Locale _locale;
57 private AdminUser _user;
58
59 /**
60 * Returns the IdRule
61 *
62 * @return The IdRule
63 */
64 public int getId( )
65 {
66 return _nIdRule;
67 }
68
69 /**
70 * Sets the IdRule
71 *
72 * @param nIdRule The IdRule
73 */
74 public void setId( int nIdRule )
75 {
76 _nIdRule = nIdRule;
77 }
78
79 /**
80 * Returns the IdRuleType
81 *
82 * @return The IdRuleType
83 */
84 public String getRuleTypeId( )
85 {
86 return _strIdRuleType;
87 }
88
89 /**
90 * Sets the IdRuleType
91 *
92 * @param strIdRuleType The IdRuleType
93 */
94 public void setRuleTypeId( String strIdRuleType )
95 {
96 _strIdRuleType = strIdRuleType;
97 }
98
99 /**
100 * Sets the locale
101 *
102 * @param locale The locale
103 */
104 public void setLocale( Locale locale )
105 {
106 _locale = locale;
107 }
108
109 /**
110 * Get the locale
111 * @return The locale
112 */
113 public Locale getLocale( )
114 {
115 return _locale;
116 }
117
118 /**
119 * Set an attribute
120 * @param strAttributeName the name of the attribute
121 * @param strAttributeValue the value of the attribute
122 */
123 public void setAttribute( String strAttributeName, String strAttributeValue )
124 {
125 _mapAttributes.put( strAttributeName, strAttributeValue );
126 }
127
128 /**
129 * Get the value of an attribute from its name
130 * @param strAttributeNamethe name of the attribute
131 * @return the value of the attribute
132 */
133 public String getAttribute( String strAttributeName )
134 {
135 return _mapAttributes.get( strAttributeName );
136 }
137
138 /**
139 * Read attributes from a request
140 * @param request The request
141 */
142 public void readAttributes( HttpServletRequest request )
143 {
144 String strRuleTypeId = request.getParameter( PARAMETER_RULE_TYPE_ID );
145 setRuleTypeId( strRuleTypeId );
146
147 String[] attributes = getAttributesList( );
148
149 for ( int i = 0; i < attributes.length; i++ )
150 {
151 String strAttributeValue = request.getParameter( attributes[i] );
152
153 if ( strAttributeValue != null )
154 {
155 setAttribute( attributes[i], strAttributeValue );
156 }
157 }
158 }
159
160 /**
161 * {@inheritDoc}
162 */
163 @Override
164 public abstract boolean equals( Object obj );
165
166 /**
167 * Gets the current user
168 * @return The the current user
169 */
170 public AdminUser getUser( )
171 {
172 return _user;
173 }
174
175 /**
176 * set the current user
177 * @param user the current user
178 *
179 */
180 public void setUser( AdminUser user )
181 {
182 _user = user;
183 }
184 }