View Javadoc
1   /*
2    * Copyright (c) 2002-2025, 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.menus.business;
35  
36  import java.io.Serializable;
37  import java.util.ArrayList;
38  import java.util.List;
39  
40  import javax.validation.constraints.NotEmpty;
41  import javax.validation.constraints.Pattern;
42  import javax.validation.constraints.Size;
43  
44  /**
45   * This is the business class for the object CustomMenu
46   */
47  public class CustomMenu implements Serializable
48  {
49  	private static final long serialVersionUID = 2L;
50  
51  	// Variables declarations
52  	private int _nId;
53  	@NotEmpty( message = "#i18n{menus.validation.customMenu.name.notEmpty}" )
54  	@Size( max = 100, message = "#i18n{menus.validation.customMenu.name.size}" )
55  	private String _strName;
56  	@Pattern( regexp = "^[a-zA-Z0-9_]*$", message = "#i18n{menus.validation.customMenu.bookmark.pattern}" )
57  	@Pattern( regexp = "^(?!customMenu$|customMenuMainPage$|customMenuInternalPage$|customMenuSideBar$|page_tree_menu_main$|page_tree_menu_tree$|page_tree_menu_tree_all_pages$).+$", message = "#i18n{menus.validation.customMenu.bookmark.forbiddenName}" )
58  	@Size( max = 100, message = "#i18n{menus.validation.customMenu.bookmark.size}" )
59  	@NotEmpty( message = "#i18n{menus.validation.customMenu.bookmark.notEmpty}" )
60  	private String _strBookmark;
61  	@Pattern( regexp = "main|internal|sidebar|submenu", message = "#i18n{menus.validation.customMenu.type.pattern}" )
62  	private String _strType;
63  	@Size( max = 255, message = "#i18n{menus.validation.customMenu.description.size}" )
64  	private String _strDescription;
65  	private List < CustomMenuItem > _listItems;
66  
67  	// Type constants
68  	public static final String TYPE_MAIN = "menus.constant_custom_menu.type.main";
69  	public static final String TYPE_SUBMENU = "menus.constant_custom_menu.type.customMenu";
70  	public static final String TYPE_INTERNAL = "menus.constant_custom_menu.type.internal";
71  	public static final String TYPE_SIDEBAR = "menus.constant_custom_menu.type.sidebar";
72  
73  	/**
74  	 * Constructor
75  	 */
76  	public CustomMenu( )
77  	{
78  		_listItems = new ArrayList < CustomMenuItem >( );
79  		_strBookmark = "";
80  	}
81  
82  	/**
83  	 * Returns the Id
84  	 * 
85  	 * @return The Id
86  	 */
87  	public int getId( )
88  	{
89  		return _nId;
90  	}
91  
92  	/**
93  	 * Sets the Id
94  	 * 
95  	 * @param nId
96  	 *            The Id
97  	 */
98  	public void setId( int nId )
99  	{
100 		_nId = nId;
101 	}
102 
103 	/**
104 	 * Returns the Name
105 	 * 
106 	 * @return The Name
107 	 */
108 	public String getName( )
109 	{
110 		return _strName;
111 	}
112 
113 	/**
114 	 * Sets the Name
115 	 * 
116 	 * @param strName
117 	 *                The Name
118 	 */
119 	public void setName( String strName )
120 	{
121 		_strName = strName;
122 	}
123 
124 	/**
125 	 * Returns the Bookmark
126 	 * 
127 	 * @return The Bookmark
128 	 */
129 	public String getBookmark( )
130 	{
131 		return _strBookmark;
132 	}
133 
134 	/**
135 	 * Sets the Bookmark
136 	 * 
137 	 * @param strBookmark
138 	 *                    The Bookmark
139 	 */
140 	public void setBookmark( String strBookmark )
141 	{
142 		_strBookmark = strBookmark;
143 	}
144 
145 	/**
146 	 * Returns the Type
147 	 * 
148 	 * @return The Type
149 	 */
150 	public String getType( )
151 	{
152 		return _strType;
153 	}
154 
155 	/**
156 	 * Sets the Type
157 	 * 
158 	 * @param strType
159 	 *                The Type
160 	 */
161 	public void setType( String strType )
162 	{
163 		_strType = strType;
164 	}
165 
166 	/**
167 	 * Returns the Description
168 	 * 
169 	 * @return The Description
170 	 */
171 	public String getDescription( )
172 	{
173 		return _strDescription;
174 	}
175 
176 	/**
177 	 * Sets the description
178 	 * 
179 	 * @param string Description
180 	 *               The Description
181 	 */
182 	public void setDescription( String strDescription )
183 	{
184 		_strDescription = strDescription;
185 	}
186 
187 	/**
188 	 * Returns the list of items
189 	 * 
190 	 * @return The list of items
191 	 */
192 	public List < CustomMenuItem > getListItems( )
193 	{
194 		return _listItems;
195 	}
196 
197 	/**
198 	 * Sets the list of items
199 	 * 
200 	 * @param listItems
201 	 *                  The list of items
202 	 */
203 	public void setListItems( List < CustomMenuItem > listItems )
204 	{
205 		_listItems = listItems;
206 	}
207 
208 	/**
209 	 * Add an item to the menu
210 	 * 
211 	 * @param item
212 	 *             The item to add
213 	 */
214 	public void addItem( CustomMenuItem item )
215 	{
216 		_listItems.add( item );
217 	}
218 
219 	/**
220 	 * Remove an item from the menu
221 	 * 
222 	 * @param item
223 	 *             The item to remove
224 	 */
225 	public void removeItem( CustomMenuItem item )
226 	{
227 		_listItems.remove( item );
228 	}
229 }