View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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.portal.web.xpages;
35  
36  import java.util.ArrayList;
37  import java.util.List;
38  import java.util.StringTokenizer;
39  
40  import fr.paris.lutece.portal.service.plugin.Plugin;
41  import fr.paris.lutece.portal.service.plugin.PluginService;
42  
43  /**
44   * XPageApplication Entry
45   */
46  public class XPageApplicationEntry
47  {
48      // Variables declarations
49      private String _strId;
50      private String _strClassName;
51      private String _strPluginName;
52      private List<String> _listRoles = new ArrayList<>( );
53      private boolean _bEnabled = true; // defaults to enabled
54  
55      /**
56       * Returns the Id
57       *
58       * @return The Id
59       */
60      public String getId( )
61      {
62          return _strId;
63      }
64  
65      /**
66       * Sets the Id
67       *
68       * @param strId
69       *            The Id
70       */
71      public void setId( String strId )
72      {
73          _strId = strId;
74      }
75  
76      /**
77       * Returns the ClassName
78       *
79       * @return The ClassName
80       */
81      public String getClassName( )
82      {
83          return _strClassName;
84      }
85  
86      /**
87       * Sets the ClassName
88       *
89       * @param strClassName
90       *            The ClassName
91       */
92      public void setClassName( String strClassName )
93      {
94          _strClassName = strClassName;
95      }
96  
97      /**
98       * Returns the Roles
99       *
100      * @return The Roles
101      */
102     public List<String> getRoles( )
103     {
104         return _listRoles;
105     }
106 
107     /**
108      * Sets the Roles
109      *
110      * @param strRoles
111      *            The Roles
112      */
113     public void setRoles( String strRoles )
114     {
115         // extracts each role (separated by a comma) from the String
116         if ( strRoles != null )
117         {
118             StringTokenizer strTokens = new StringTokenizer( strRoles, "," );
119 
120             while ( strTokens.hasMoreTokens( ) )
121             {
122                 _listRoles.add( strTokens.nextToken( ) );
123             }
124         }
125     }
126 
127     /**
128      * Return the name of the plugin
129      *
130      * @return The name of the plugin
131      */
132     public String getPluginName( )
133     {
134         return _strPluginName;
135     }
136 
137     /**
138      * Set the plugin name of the insert service
139      *
140      * @param strPluginName
141      *            the plugin name
142      */
143     public void setPluginName( String strPluginName )
144     {
145         _strPluginName = strPluginName;
146     }
147 
148     /**
149      * Tells if the application is enable (plugin enabled)
150      *
151      * @return True if the application is enable, otherwise false
152      */
153     public boolean isEnable( )
154     {
155         return _bEnabled && PluginService.isPluginEnable( _strPluginName );
156     }
157 
158     /**
159      * Tells if the XPageApplication is enabled, independently of the plugin's status
160      * 
161      * @return <code>true</code> if this XPageApplication is enabled, <code>false</code> otherwise
162      * @since 5.1
163      */
164     public boolean isEnabled( )
165     {
166         return _bEnabled;
167     }
168 
169     /**
170      * Sets the enabled state of this XPageApplication
171      * 
172      * @param bEnabled
173      *            <code>true</code> if this XPageApplication is enabled, <code>false</code> otherwise
174      * @since 5.1
175      */
176     public void setEnabled( boolean bEnabled )
177     {
178         _bEnabled = bEnabled;
179     }
180 
181     /**
182      * Gets the plugin instance associated to the application
183      *
184      * @return the plugin
185      */
186     public Plugin getPlugin( )
187     {
188         return PluginService.getPlugin( _strPluginName );
189     }
190 }