All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.eng.spago.dispatching.httpchannel.RouterPortlet Maven / Gradle / Ivy

/**

    Copyright 2004, 2007 Engineering Ingegneria Informatica S.p.A.

    This file is part of Spago.

    Spago 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
    any later version.

    Spago 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 Spago; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

**/
package it.eng.spago.dispatching.httpchannel;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.portlet.PortletContext;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import it.eng.spago.base.Constants;
import it.eng.spago.tracing.TracerSingleton;
import it.eng.spago.util.JavaScript;

public class RouterPortlet {
    public RouterPortlet(String publisher) {
        _publisher = publisher;
        _parameters = new Hashtable();    	
    } // public PortletRouter(String publisher)

    public static RouterPortlet getDefaultRouter() {
        return new RouterPortlet(Constants.DEFAULT_PUBLISHER);
    } // public static PortletRouter getDefaultRouter()

    public Object getParameter(String key) {
        if (key == null)
            return null;
        return _parameters.get(key);
    } // public Object getParameter(String key)

    public void setParameter(String key, Object value) {
        if (key == null)
            return;
        if (value == null)
            delParameter(key);
        else
            _parameters.put(key, value);
    } // public void setParameter(String key, Object value)

    public void delParameter(String key) {
        if (key == null)
            return;
        _parameters.remove(key);
    } // public void delParameter(String key)

    public void route(
        PortletContext portletContext,
        RenderRequest request,
        RenderResponse response)
        throws PortletException, IOException {
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.DEBUG,
            "PortletRouter::route: _publisher [" + _publisher + "]");
        String publishingParameters = "";
        Enumeration parameterNames = _parameters.keys();
        while (parameterNames.hasMoreElements()) {
            String parameterName = (String) parameterNames.nextElement();
            String parameterValue =
                String.valueOf(_parameters.get(parameterName));
            if (_publisher.indexOf(parameterName) == -1)
                publishingParameters += JavaScript.escape(parameterName)
                    + "="
                    + JavaScript.escape(parameterValue)
                    + "&";
        } // while (parameterNames.hasMoreElements())
        TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.DEBUG,
            "PortletRouter::route: publishingParameters ["
                + publishingParameters
                + "]");
        String publishingURL = _publisher; 
                
		if (_publisher.indexOf('?') == -1)
		    publishingURL += "?" + publishingParameters;
		else
		    publishingURL += "&" + publishingParameters;
        
	    TracerSingleton.log(
            Constants.NOME_MODULO,
            TracerSingleton.DEBUG,
            "PortletRouter::route: publishingURL [" + publishingURL + "]");

	    PortletRequestDispatcher requestDispatcher = portletContext.getRequestDispatcher(publishingURL);
        requestDispatcher.include(request, response);    
    
    
    } 

    private String _publisher = null;
    private Hashtable _parameters = null;
} // public class PortletRouter




© 2015 - 2025 Weber Informatics LLC | Privacy Policy