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.om.window.PortletWindow; 92 import org.apache.pluto.portalImpl.om.window.impl.PortletWindowImpl; 93 import org.apache.pluto.portalImpl.services.config.Config; 94 import org.apache.pluto.services.information.DynamicInformationProvider; 95 import org.apache.pluto.services.information.PortletActionProvider; 96 import org.apache.pluto.services.information.PortletURLProvider; 97 import org.apache.pluto.services.information.ResourceURLProvider; 98 99 import java.util.HashSet; 100 import java.util.Iterator; 101 102 import javax.portlet.PortletMode; 103 import javax.portlet.WindowState; 104 105 import javax.servlet.http.HttpServletRequest; 106 107 108 /** 109 * Lutece/Pluto implementation of {@link org.apache.pluto.services.information.DynamicInformationProvider} 110 * 111 * @see fr.paris.lutece.plugins.jsr168.pluto.core.InformationProviderServiceFactoryImpl 112 */ 113 public class DynamicInformationProviderImpl implements DynamicInformationProvider 114 { 115 private static final int NumberOfKnownMimetypes = 15; 116 private final HttpServletRequest _request; 117 private PortalEnvironment _env; 118 119 /** 120 * Initialize the new instance (extract {@link PortalEnvironment} from 121 * <code>request</code>) 122 * 123 * @param request The current HTTP request 124 */ 125 DynamicInformationProviderImpl( HttpServletRequest request ) 126 { 127 _request = request; 128 _env = PortalEnvironment.getPortalEnvironment( request ); 129 } 130 131 /** 132 * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletMode(org.apache.pluto.om.window.PortletWindow) 133 */ 134 public PortletMode getPortletMode( PortletWindow portletWindow ) 135 { 136 return ( (PortletWindowImpl) portletWindow ).getPortletMode( ); 137 } 138 139 /** 140 * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletURLProvider(org.apache.pluto.om.window.PortletWindow) 141 */ 142 public PortletURLProvider getPortletURLProvider( PortletWindow portletWindow ) 143 { 144 return new PortletURLProviderImpl( _request, this, portletWindow ); 145 } 146 147 /** 148 * @see org.apache.pluto.services.information.DynamicInformationProvider#getResourceURLProvider(org.apache.pluto.om.window.PortletWindow) 149 */ 150 public ResourceURLProvider getResourceURLProvider( PortletWindow portletWindow ) 151 { 152 return new ResourceURLProviderImpl( this, portletWindow ); 153 } 154 155 /** 156 * @see org.apache.pluto.services.information.DynamicInformationProvider#getPortletActionProvider(org.apache.pluto.om.window.PortletWindow) 157 */ 158 public PortletActionProvider getPortletActionProvider( PortletWindow portletWindow ) 159 { 160 return new PortletActionProviderImpl( (PortletWindowImpl) portletWindow ); 161 } 162 163 /** 164 * @see org.apache.pluto.services.information.DynamicInformationProvider#getPreviousPortletMode(org.apache.pluto.om.window.PortletWindow) 165 */ 166 public PortletMode getPreviousPortletMode( PortletWindow portletWindow ) 167 { 168 return ( (PortletWindowImpl) portletWindow ).getPrevPortletMode( ); 169 } 170 171 /** 172 * @see org.apache.pluto.services.information.DynamicInformationProvider#getPreviousWindowState(org.apache.pluto.om.window.PortletWindow) 173 */ 174 public WindowState getPreviousWindowState( PortletWindow portletWindow ) 175 { 176 return ( (PortletWindowImpl) portletWindow ).getPrevWindowState( ); 177 } 178 179 /** 180 * @see org.apache.pluto.services.information.DynamicInformationProvider#getResponseContentType() 181 */ 182 public String getResponseContentType( ) 183 { 184 return "text/html"; 185 } 186 187 /** 188 * @see org.apache.pluto.services.information.DynamicInformationProvider#getResponseContentTypes() 189 */ 190 public Iterator getResponseContentTypes( ) 191 { 192 HashSet responseMimeTypes = new HashSet( NumberOfKnownMimetypes ); 193 responseMimeTypes.add( "text/html" ); 194 195 return responseMimeTypes.iterator( ); 196 } 197 198 /** 199 * @see org.apache.pluto.services.information.DynamicInformationProvider#getWindowState(org.apache.pluto.om.window.PortletWindow) 200 */ 201 public WindowState getWindowState( final PortletWindow portletWindow ) 202 { 203 return ( (PortletWindowImpl) portletWindow ).getWindowState( ); 204 } 205 206 /** 207 * @see org.apache.pluto.services.information.DynamicInformationProvider#isPortletModeAllowed(javax.portlet.PortletMode) 208 */ 209 public boolean isPortletModeAllowed( PortletMode mode ) 210 { 211 //checks whether PortletMode is supported as example 212 String[] supportedModes = Config.getParameters( ) 213 .getStrings( LutecePlutoConstant.CONFIG_SERVICES_PARAM_SUPPORTED_PORTLETMODE ); 214 215 for ( int i = 0; i < supportedModes.length; i++ ) 216 { 217 if ( supportedModes[i].equalsIgnoreCase( mode.toString( ) ) ) 218 { 219 return true; 220 } 221 } 222 223 return false; 224 } 225 226 /** 227 * @see org.apache.pluto.services.information.DynamicInformationProvider#isWindowStateAllowed(javax.portlet.WindowState) 228 */ 229 public boolean isWindowStateAllowed( WindowState state ) 230 { 231 //checks whether WindowState is supported as example 232 String[] supportedStates = Config.getParameters( ) 233 .getStrings( LutecePlutoConstant.CONFIG_SERVICES_PARAM_SUPPORTED_WINDOWSTATE ); 234 235 for ( int i = 0; i < supportedStates.length; i++ ) 236 { 237 if ( supportedStates[i].equalsIgnoreCase( state.toString( ) ) ) 238 { 239 return true; 240 } 241 } 242 243 return false; 244 } 245 }