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