View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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  /*
35   * The Apache Software License, Version 1.1
36   *
37   * Copyright (c) 2003 The Apache Software Foundation.  All rights
38   * reserved.
39   *
40   * Redistribution and use in source and binary forms, with or without
41   * modification, are permitted provided that the following conditions
42   * are met:
43   *
44   * 1. Redistributions of source code must retain the above copyright
45   *    notice, this list of conditions and the following disclaimer.
46   *
47   * 2. Redistributions in binary form must reproduce the above copyright
48   *    notice, this list of conditions and the following disclaimer in
49   *    the documentation and/or other materials provided with the
50   *    distribution.
51   *
52   * 3. The end-user documentation included with the redistribution, if
53   *    any, must include the following acknowlegement:
54   *       "This product includes software developed by the
55   *        Apache Software Foundation (http://www.apache.org/)."
56   *    Alternately, this acknowlegement may appear in the software itself,
57   *    if and wherever such third-party acknowlegements normally appear.
58   *
59   * 4. The names "The Jakarta Project", "Pluto", and "Apache Software
60   *    Foundation" must not be used to endorse or promote products derived
61   *    from this software without prior written permission. For written
62   *    permission, please contact apache@apache.org.
63   *
64   * 5. Products derived from this software may not be called "Apache"
65   *    nor may "Apache" appear in their names without prior written
66   *    permission of the Apache Group.
67   *
68   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
69   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
70   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
71   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
72   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
73   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
74   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
75   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
76   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
77   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
78   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
79   * SUCH DAMAGE.
80   * ====================================================================
81   *
82   * This software consists of voluntary contributions made by many
83   * individuals on behalf of the Apache Software Foundation.  For more
84   * information on the Apache Software Foundation, please see
85   * <http://www.apache.org/>.
86   */
87  package fr.paris.lutece.plugins.jsr168.pluto.core;
88  
89  import fr.paris.lutece.plugins.jsr168.pluto.LutecePlutoConstant;
90  
91  import org.apache.pluto.portalImpl.services.config.Config;
92  import org.apache.pluto.services.information.PortalContextProvider;
93  
94  import java.util.ArrayList;
95  import java.util.Collection;
96  import java.util.HashMap;
97  import java.util.List;
98  import java.util.Map;
99  
100 import javax.portlet.PortletMode;
101 import javax.portlet.WindowState;
102 
103 
104 /**
105  * Context provider
106  */
107 public class PortalContextProviderImpl implements PortalContextProvider
108 {
109     /** Portal information */
110     private String _strInfo;
111 
112     /** supported portlet modes by this portal */
113     private List _listModes;
114 
115     /** supported window states by this portal */
116     private List _listStates;
117 
118     /** portal properties */
119     private Map _properties;
120 
121     /**
122      * Default constructor: initialize all members with default
123      * portlet container values
124      */
125     public PortalContextProviderImpl(  )
126     {
127         // these are the minimum modes that the portal needs to support
128         _listModes = getDefaultModes(  );
129 
130         // these are the minimum states that the portal needs to support
131         _listStates = getDefaultStates(  );
132 
133         // set info
134         _strInfo = "Lutece1.1/Pluto1.0";
135 
136         _properties = new HashMap(  );
137     }
138 
139     /**
140          * @see org.apache.pluto.services.information.PortalContextProvider#getProperty(java.lang.String)
141          */
142     public String getProperty( String name )
143     {
144         if ( name == null )
145         {
146             throw new IllegalArgumentException( "Property name == null" );
147         }
148 
149         return (String) _properties.get( name );
150     }
151 
152     /**
153          * @see org.apache.pluto.services.information.PortalContextProvider#getPropertyNames()
154          */
155     public Collection getPropertyNames(  )
156     {
157         return _properties.keySet(  );
158     }
159 
160     /**
161          * @see org.apache.pluto.services.information.PortalContextProvider#getSupportedPortletModes()
162          */
163     public Collection getSupportedPortletModes(  )
164     {
165         return _listModes;
166     }
167 
168     /**
169          * @see org.apache.pluto.services.information.PortalContextProvider#getSupportedWindowStates()
170          */
171     public Collection getSupportedWindowStates(  )
172     {
173         return _listStates;
174     }
175 
176     /**
177          * @see org.apache.pluto.services.information.PortalContextProvider#getPortalInfo()
178          */
179     public String getPortalInfo(  )
180     {
181         return _strInfo;
182     }
183 
184     /**
185      * Return default portlet supported modes
186      *
187      * @return default portlet supported modes
188      */
189     private List getDefaultModes(  )
190     {
191         List m = new ArrayList(  );
192 
193         String[] supportedModes = Config.getParameters(  )
194                                         .getStrings( LutecePlutoConstant.CONFIG_SERVICES_PARAM_SUPPORTED_PORTLETMODE );
195 
196         for ( int i = 0; i < supportedModes.length; i++ )
197         {
198             m.add( new PortletMode( supportedModes[i].toString(  ).toLowerCase(  ) ) );
199         }
200 
201         return m;
202     }
203 
204     /**
205     * Return default portlet supported states
206     *
207     * @return default portlet supported states
208      */
209     private List getDefaultStates(  )
210     {
211         List s = new ArrayList(  );
212 
213         String[] supportedStates = Config.getParameters(  )
214                                          .getStrings( LutecePlutoConstant.CONFIG_SERVICES_PARAM_SUPPORTED_WINDOWSTATE );
215 
216         for ( int i = 0; i < supportedStates.length; i++ )
217         {
218             s.add( new WindowState( supportedStates[i].toString(  ).toLowerCase(  ) ) );
219         }
220 
221         return s;
222     }
223 
224     /**
225      * reset all values to default portlet modes and window states;
226      * delete all properties and set the given portlet information
227      * as portlet info string.
228      *
229      * @param strPortalInfo  portal information string that will be returned
230      *                    by the <code>getPortalInfo</code> call.
231      */
232     private void reset( String strPortalInfo )
233     {
234         _strInfo = new String( strPortalInfo );
235 
236         // these are the minimum modes that the portal needs to support
237         _listModes = getDefaultModes(  );
238 
239         // these are the minimum states that the portal needs to support
240         _listStates = getDefaultStates(  );
241 
242         _properties.clear(  );
243     }
244 }