/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package com.xpn.xwiki.internal.sheet;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.commons.lang3.StringUtils;
import org.xwiki.component.annotation.Component;
import org.xwiki.container.Request;
import org.xwiki.container.RequestInitializer;
import org.xwiki.container.RequestInitializerException;
import org.xwiki.context.Execution;

import com.xpn.xwiki.XWikiContext;

/**
 * Takes the sheet parameter from the request and puts it on the execution context to be used by the sheet manager.
 * 
 * @version $Id$
 * @since 3.2M3
 */
@Component
@Named("sheet")
@Singleton
public class SheetRequestInitializer implements RequestInitializer
{
    /**
     * The name of the request parameter specifying the sheet to be applied to the requested document. This is also the
     * name of the execution context property specifying the same thing.
     */
    private static final String SHEET_PROPERTY_NAME = "sheet";

    /**
     * Execution context handler, needed for accessing the XWikiContext.
     */
    @Inject
    private Execution execution;

    @Override
    public void initialize(Request request) throws RequestInitializerException
    {
        XWikiContext xwikiContext = (XWikiContext) execution.getContext().getProperty("xwikicontext");
        String sheet = xwikiContext.getRequest().getParameter(SHEET_PROPERTY_NAME);
        if (!StringUtils.isEmpty(sheet)) {
            execution.getContext().setProperty(SHEET_PROPERTY_NAME, sheet);
        }
    }
}

@@ -1271,57 +1271,72 @@
 cont
-ext.Execution;%0A%0Aimport com.xpn.xwiki.XWikiContext
+ainer.servlet.ServletRequest;%0Aimport org.xwiki.context.Execution
 ;%0A%0A/
@@ -1919,49 +1919,10 @@
 dler
-, needed for accessing the XWikiContext
 .%0A
+
     
@@ -2082,140 +2082,115 @@
     
-XWikiContext xwikiContext = (XWikiContext) execution.getContext().getProperty(%22xwikicontext%22);%0A        String sheet = xwikiContext.g
+if (request instanceof ServletRequest) %7B%0A            String sheet = ((ServletRequest) request).getHttpServl
 etRe
@@ -2236,24 +2236,28 @@
 E);%0A        
+  
+  
 if (!StringU
@@ -2275,24 +2275,28 @@
 y(sheet)) %7B%0A
+    
             
@@ -2359,16 +2359,30 @@
 sheet);%0A
+            %7D%0A
         

Create a new sheet system * Improve the code of the SheetRequestInitialzier