You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by Roger Ruttimann <ro...@apache.org> on 2004/07/21 20:07:53 UTC

cvs commit: jakarta-jetspeed-2/applications/php/src/java/org/apache/jetspeed/portlets/php/PHPApplicationPortlet.java

rogerrut    2004/07/21 10:47:07

  Added:       applications/php/src/java/org/apache/jetspeed/portlets/php
                        PHPServletContextProviderImpl.java
                        PHPApplicationPortlet.java
                        PHPServletContextProvider.java
                        phpRedirectorServlet.java ServletConfigImpl.java
               applications/php/src/webapp/WEB-INF web.xml
                        jetspeed-portlet.xml php-setup.jsp portlet.xml
               applications/php project.xml maven.xml project.properties
               applications/php/src/webapp/hosts index.html index.php
                        install.php clear_tables.pl
               applications/php/src/webapp/hosts/common forms.php
                        functions.php
               applications/php/src/webapp/hosts/conf config.php
               applications/php/src/webapp/hosts/code hosts.php
                        interfaces.php services.php
               applications/php/src/webapp test.php
               applications/php/src/webapp/css style.css
  Log:
  Adding a Portlet Application Framework for running PHP applications inside Jetspeed.
  The php app includes a small php demo app and the default PHP test page.
  
  Revision  Changes    Path
  1.1                  jakarta-jetspeed-2/applications/php/src/java/org/apache/jetspeed/portlets/php/PHPServletContextProviderImpl.java
  
  Index: PHPServletContextProviderImpl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.portlets.php;
  
  import javax.portlet.GenericPortlet;
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletResponse;
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletRequestWrapper;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpServletResponseWrapper;
  
  import org.apache.jetspeed.container.JetspeedPortletContext;
  
  
  /**
   * PHPServletContextProviderImpl supplies a PHPPortlet access to the
   * Servlet context of a Jetspeed Portlet.
   * @author <a href="mailto:rogerrut@apache.org">Roger Ruttimann</a>
   * @version $Id: PHPServletContextProviderImpl.java,v 1.1 2004/07/21 17:47:06 rogerrut Exp $
   */
  public class PHPServletContextProviderImpl implements PHPServletContextProvider 
  {
      public ServletContext getServletContext(GenericPortlet portlet) 
      {
          return ((JetspeedPortletContext)portlet.getPortletContext()).getServletContext();
      }
  
      public HttpServletRequest getHttpServletRequest(GenericPortlet portlet, PortletRequest request) 
      {
          return (HttpServletRequest) ((HttpServletRequestWrapper) request).getRequest();
      }
  
      public HttpServletResponse getHttpServletResponse(GenericPortlet portlet, PortletResponse response) 
      {
          return (HttpServletResponse) ((HttpServletResponseWrapper) response).getResponse();
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/applications/php/src/java/org/apache/jetspeed/portlets/php/PHPApplicationPortlet.java
  
  Index: PHPApplicationPortlet.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.portlets.php;
  
  import java.io.IOException;
  import java.security.Principal;
  
  import javax.portlet.GenericPortlet;
  import javax.portlet.PortletConfig;
  import javax.portlet.PortletException;
  import javax.portlet.RenderRequest;
  import javax.portlet.RenderResponse;
  import javax.portlet.PortletContext;
  import javax.portlet.PortletRequestDispatcher;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpUtils;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   * This portlet is executes a PHP application in a portlet.
   *
   * @author <a href="mailto:rogerrut@apache.org">Roger Ruttimann</a>
   * @version $Id: PHPApplicationPortlet.java,v 1.1 2004/07/21 17:47:06 rogerrut Exp $
   */
  
  public class PHPApplicationPortlet extends GenericPortlet {
  
  	/**
  	 * INIT parameters required by the PHP Portlet:application and ServletContextProvider
  	 *
       * Name of class implementing {@link PHPServletContextProvider}
       */
      public static final String PARAM_SERVLET_CONTEXT_PROVIDER = "ServletContextProvider";
      
       /**
        * Name of the application for this portlet
  	 */
  	public static final String PARAM_APPLICATION	=	"application";
  
  		   
      // Local variables
      
      private PHPServletContextProvider servletContextProvider;
      private static final Log log = LogFactory.getLog(PHPApplicationPortlet.class);
      
      // Servlet INFO needed for portlet    
      
      ServletConfigImpl servletConfig = null;
      
      // PHP engine 
      com.itgroundwork.portlet.php.servlet phpServletImpl = null;
      
       // Parameters
      private String applicationName = null;
      
      // caching status    
      private String lastContextPath = null;
      private String lastQuery = null;
      private String lastURI = null;
      
      //ID to identify portlet
      private String portletID = null;
   
      public void init(PortletConfig config) throws PortletException
      {    
          super.init(config);
          
          // Initialize config
          servletConfig = new ServletConfigImpl(config);
          
          //Get the INIT PARAMETERS for this portlet. If the values are missing
          // throw an exception
          applicationName					=	config.getInitParameter(PARAM_APPLICATION);
          String contextProviderClassName =	config.getInitParameter(PARAM_SERVLET_CONTEXT_PROVIDER);
          
          if (applicationName == null)
              throw new PortletException("Portlet " + config.getPortletName()
                      + " is incorrectly configured. Init parameter "
                      + PARAM_APPLICATION + " not specified");
            
          if (contextProviderClassName == null)
              throw new PortletException("Portlet " + config.getPortletName()
                      + " is incorrectly configured. Init parameter "
                      + PARAM_SERVLET_CONTEXT_PROVIDER + " not specified");
          
          if (contextProviderClassName != null)
          {
              try
              {
                  Class clazz = Class.forName(contextProviderClassName);
                  if (clazz != null)
                  {
                      Object obj = clazz.newInstance();
                      if (PHPServletContextProvider.class.isInstance(obj))
                          servletContextProvider = (PHPServletContextProvider) obj;
                      else
                          throw new PortletException("class not found");
                  }
              } catch (Exception e)
              {
                  if (e instanceof PortletException)
                      throw (PortletException) e;
                  e.printStackTrace();
                  throw new PortletException("Cannot load", e);
              }
          }
       }	
      
      public void doView(RenderRequest request, RenderResponse response)
      throws PortletException, IOException
  	{
        	ServletContext		servletContext	= servletContextProvider.getServletContext(this);
      	HttpServletRequest	httpRequest		= servletContextProvider.getHttpServletRequest(this, request);
      	HttpServletResponse httpResponse	= servletContextProvider.getHttpServletResponse(this, response);
      	
      	// if any of the above is null throw an error
      	if ( servletContext == null ||httpResponse == null || httpRequest == null )
      	{
      		httpResponse.getWriter().println("<p><b>Fatal error: Servlet Request/Response is missing!</b></p>");
      		return;
      	}
      	// Make sure the application Name is configured before doing any processing
      	if (this.applicationName == null || applicationName.length() == 0)
      	{
      		httpResponse.getWriter().println("<p><b>Configuration error!</b><br>Please make sure that the application Name is configured</p>");
      		return;
      	}
      	
      	//initialize PHP engine
      	if ( phpServletImpl == null)
      	{
      		try
  			{
      		phpServletImpl = new com.itgroundwork.portlet.php.servlet();
      		if (phpServletImpl != null )
      			phpServletImpl.init(servletConfig);
  			}
      		catch(ServletException se)
  			{
      			httpResponse.getWriter().println("<p><b>Initializationof PHP servlet failed!</b> Error: " + se.getMessage() + "</p>");
  			}
      	}
      	
      	/**
           * The portlet can have the following three stages
           * 1) First time accessed from the portal. No query parameters. Show info page
           * 2) Has the php-file query but no user. Add user than redirect it to itself
           * 2) User and php-file are defined run the php-servlet
           */
      	
        	String userName = "anon";	//default not logged in
      	Principal userPrincipal = request.getUserPrincipal();
      	if (userPrincipal != null )
      		userName = userPrincipal.getName();
          
          boolean bShowInfoPage = false;
          String	cookieValue = null;
          
          String reqQuery = httpRequest.getQueryString();
          String contextPath = servletContext.getRealPath(httpRequest.getServletPath());
          
          // Take portal out of the context. This will point to the root of the application
          String rootContextPath = contextPath.substring(0, contextPath.lastIndexOf("portal") ) ;
          
          // First time call or reinvoked from outside won't have the query string properly initialized
          if ( reqQuery == null || (reqQuery.indexOf("php-file=") == -1))
          {
          	// Check if the php was initialized (called once to the php servlet)
          	if (lastContextPath != null)
          	{
          		//com.itgroundwork.portlet.php.servlet phpServletImpl = new com.itgroundwork.portlet.php.servlet();
      	        try
      			{	
      		        if (phpServletImpl != null )
      		        {    		    		 				
  		 				phpServletImpl.setAdjustedURI(lastURI);
  		 				phpServletImpl.setAdjustedQuery(lastQuery);
  		 				
  		 				phpServletImpl.service(httpRequest, httpResponse,lastContextPath);
  		 				
      				}
      			}
  	    		catch( ServletException se)
  				{
  	    			httpResponse.getWriter().println("<P><B>Error in PHP servlet " + se.getMessage() + "</B></P><BR>");
  				}
  	    		
      			// Show the portlet				    
  			    return;
          	}
          	else
          	{
          		bShowInfoPage = true;
          	}
          }
          else
          {        	
  	    	// Search for the start php file
  	    	String queryArg = "php-file=";
  	    	        		    	
      		int index = reqQuery.indexOf(queryArg);
      		int sepIndex = reqQuery.indexOf('&', index);
      		String phpStartFile;
      		
      		// get name of the file to start
      		if (sepIndex != -1)
      		{
      			// Multiple query strings
      			phpStartFile = reqQuery.substring(index + queryArg.length(), sepIndex );
      		}
      		else
      		{
      			// Only query string
      			phpStartFile = reqQuery.substring(index + queryArg.length() );
      		}
      		
      		// Create an instance of the PHP servlet
      		try
  			{		
  				if (phpServletImpl != null )
  				{
  					// Make sure that the request is destined for this implementation of the portlet
  					queryArg = "appname=";
  					int i = reqQuery.indexOf(queryArg);
  		    		int ii = reqQuery.indexOf('&', i);
  		    		String reqAppName = null;
  						
  		    		if (ii != -1)
  		    		{
  		    			// Multiple query strings
  		    			reqAppName = reqQuery.substring(i + queryArg.length(), ii );
  		    		}
  		    		else
  		    		{
  		    			// Only query string
  		    			reqAppName = reqQuery.substring(i + queryArg.length() );
  		    		}
  		    	
  		    		if ((applicationName.compareToIgnoreCase(reqAppName) == 0) || (reqAppName.compareToIgnoreCase("test") == 0) )
  		    		{
  		    			// New request for this portlet render it for the new content
  						String adjURI = "/PHP/" + phpStartFile;
  						
  						String phpContext = rootContextPath;					
  						phpContext += phpStartFile;
  						
  						rootContextPath = phpContext;
  												
  						// Call into the php library
  						phpServletImpl.setAdjustedURI(adjURI);
  						phpServletImpl.setAuthenticatedUser(userName);
  						phpServletImpl.setAdjustedQuery(reqQuery);
  						phpServletImpl.service(httpRequest, httpResponse,rootContextPath);
  						
  						// Save last executed request info so that we remember when it was last called
  						lastQuery = reqQuery;
  						lastContextPath = rootContextPath;
  						lastURI = adjURI;
  						
  		    		}
  		    		else
  		    		{
  		    			// Not for this application just refresh the content
  		    			if ( lastURI == null || lastURI.length() == 0)
  		    			{
  		    				bShowInfoPage = true;
  		    			}
  		    			else
  		    			{
  		    				phpServletImpl.setAdjustedURI(lastURI);
  		    				phpServletImpl.setAdjustedQuery(lastQuery);
  		 				
  		    				phpServletImpl.service(httpRequest, httpResponse,lastContextPath);
  		    			}
  		    		}
  				}
  				else
  				{
  					httpResponse.getWriter().println("<br/><b>Error in PHP servlet. Couldn't create instance of net.php.servlet</b>" );
  				}
  			}
      		catch( ServletException se)
  			{
      			httpResponse.getWriter().println("<P><B>Error in PHP servlet.Servlet Exception: " + se.getMessage() + "</B></P><BR>");
      			throw new PortletException(se);
  			}
  			catch (IOException e)
  			{
  				httpResponse.getWriter().println("<P><B>Error in PHP servlet. IO Exception " + e.getMessage() + "</B></P><BR>");
  			}
          }
          
          if (bShowInfoPage == true)
          {
          	// Display the info page
          	PortletContext context = getPortletContext();
          	PortletRequestDispatcher rd = context.getRequestDispatcher("/WEB-INF/php-setup.jsp");
              rd.include(request, response);        
              
              // Add the information the demo application
          	String portletIDQuery = "&php-portletid=" + this.portletID;
          	
          	String uri =  httpRequest.getRequestURI();
          	
          	StringBuffer reqURL = HttpUtils.getRequestURL(httpRequest);
          	String rootURL = reqURL.toString().substring(0, reqURL.toString().lastIndexOf("portal")+6 );
          	       	
          	// Test page
          	StringBuffer servletURL = new StringBuffer();
          	StringBuffer href = new StringBuffer();
          	
          	servletURL.append("http://").append(httpRequest.getServerName()).append(":").append(httpRequest.getServerPort());
          	href.append(servletURL.toString()).append("/PHP/test.php");
          	href.append("?caller-context=").append(uri).append("&appname=test&calling-user=").append(userName);
          	String testURL = href.toString();
          	        	
          	// URL to Machine database sample application
          	href.delete(0,href.length());
          	href.append(servletURL.toString()).append("/PHP/").append(applicationName).append("/index.php");
          	href.append("?caller-context=").append(uri).append("&appname=").append(applicationName).append("&calling-user=").append(userName).append(portletIDQuery);
          	String mdbURL = href.toString();
          	
          	// URL to database install
          	href.delete(0,href.length());
          	href.append(servletURL.toString()).append("/PHP/").append(applicationName).append("/install.php");
          	href.append("?caller-context=").append(uri).append("&appname=").append(applicationName).append("&calling-user=").append(userName).append(portletIDQuery);
          	String mdInstall = href.toString();
          	      	
            	httpResponse.getWriter().println("<p><b>Welcome to the PHP DEMO portlet</b><p>");
          	httpResponse.getWriter().println("<p>The links below start some PHP applications inside a portlet<br>");
          	httpResponse.getWriter().println("The test portlet takes over the whole screen but remains still inside the portlet<br>");
          	httpResponse.getWriter().println("The Machine Database demo shows you several screens allowing to update data in the database. The database connection info is defined in hosts/conf/config.php<BR>Current configuration: Database=hosts, User =root</P>");
          	httpResponse.getWriter().println("<ul><li><a href=" +testURL + ">PHP test page</li>");
          	httpResponse.getWriter().println("<li><a href=" +mdbURL + ">Enter Machine database</li>");
          	httpResponse.getWriter().println("<li><a href=" + mdInstall + ">Machine DB Install</a></li></ul></P>");
          }
  	}
  }
  
  
  
  1.1                  jakarta-jetspeed-2/applications/php/src/java/org/apache/jetspeed/portlets/php/PHPServletContextProvider.java
  
  Index: PHPServletContextProvider.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.portlets.php;
  
  import javax.portlet.GenericPortlet;
  import javax.portlet.PortletRequest;
  import javax.portlet.PortletResponse;
  import javax.servlet.ServletContext;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * PHPServletContextProvider Interface
   * 
   * @version $Id: PHPServletContextProvider.java,v 1.1 2004/07/21 17:47:06 rogerrut Exp $
   */
  public interface PHPServletContextProvider 
  {
      ServletContext getServletContext(GenericPortlet portlet);
  
      HttpServletRequest getHttpServletRequest(GenericPortlet portlet, PortletRequest request);
  
      HttpServletResponse getHttpServletResponse(GenericPortlet portlet, PortletResponse response);
  }
  
  
  
  1.1                  jakarta-jetspeed-2/applications/php/src/java/org/apache/jetspeed/portlets/php/phpRedirectorServlet.java
  
  Index: phpRedirectorServlet.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.portlets.php;
  
  import javax.servlet.http.HttpServlet;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.ServletConfig;
  import javax.servlet.http.HttpSession;
  import java.io.IOException;
  import javax.servlet.http.HttpUtils;
  
  import java.util.Hashtable;
  
  /**
   * Servlet that redirects calls to PHP files to the PHPPOrtlet that
   * initiated the PHP application.
   *
   * @author <a href="mailto:rogerrut@apache.org">Roger Ruttimann</a>
   * @version $Id: phpRedirectorServlet.java,v 1.1 2004/07/21 17:47:06 rogerrut Exp $
   */
  public class phpRedirectorServlet extends HttpServlet {
  	
  	// Class variables
  	Hashtable session2Context = new Hashtable();
  	
  	// Implement API's
  	
  	public void init(ServletConfig config)
  	  throws ServletException {
  	    super.init(config);
  	}
  	
  	public void destroy() {
  	    
  	    super.destroy();
  	  }
  	
  	public void service(HttpServletRequest request, HttpServletResponse response)
  	  throws ServletException {
  	    String servletPath = request.getServletPath();
  	    String contextPath = getServletContext().getRealPath(servletPath);
  	    
      	// Extract the php file and add it to the query string
      	StringBuffer reqURL = HttpUtils.getRequestURL(request);
      	
  	    String cookieValue = null;
  	    String requestQuery = request.getQueryString();
  	    
  	    String CALLER_CONTEXT = "caller-context=";
  	    String USERNAME = "calling-user=";
  	    String APPNAME = "appname=";
  	    String PORTLETID = "php-portletid=";
  	    String	applicationName = null;
  	    String	callingUser = null;
  	    String	callerContextPath = null;
  	    String	portletID = null;
  	    
  	    /**
  	     * The redirectorServlet only works with requests coming from the portal. The portal context
  	     * is defined in the query string "caller-context". It will be added to a lookup map for any
  	     * further requests with the same session id. If the session doesn't exist and no caller context
  	     * query is defined just display an error message
  	     */
  	    
  	    // Read the header info
  	    HttpSession currentSession = request.getSession();
          if (currentSession != null)
  		{
          	cookieValue = currentSession.getId();		
  		}
          	
  		// if the cookie is undefined throw an error.
  		if ( cookieValue == null)
  		{
  			try
  			{
  	    		// Cookie missing can't continue
  	    		response.getWriter().println("<br/><b>Error in phpRedirectorServlet servlet. Didn't find cookie in request header</b>" );
  			}
  	    	catch (IOException ioe)
  			{
  	    		//Write to the console
  	    		System.out.println("Exception while writing to HTTPServletRespone obj " + ioe.getMessage());
  	    		
  			}
  	    	
  	    	throw new ServletException("no cookie");
  	    	
  		}
  	    
  	    /*
  	     * Extract the application name out of the URL. The appname and the cookies are the unique
  	     * keys to extract the context info
  	     */
  		
  		String tmpAppName = reqURL.substring(reqURL.indexOf("PHP/")+4, reqURL.indexOf(".php"));
  		int nIndexSlash = tmpAppName.lastIndexOf("/");
  		if ( nIndexSlash == -1 ) 
  			applicationName = tmpAppName;	//Just file name no namespace for application
  		else
  			applicationName = tmpAppName.substring(0, nIndexSlash);
  		
      
  	    // Redirect the incoming request to the portlet handling class
  	    if (requestQuery == null || requestQuery.indexOf(CALLER_CONTEXT) == -1 )
  	    {	
  	    	// Check if a context exists for a given session
  	    	UserContextInfo info = (UserContextInfo)session2Context.get(cookieValue+applicationName);
  	    	
  	    	callerContextPath = info.getCallerContext();
  	    	callingUser = info.getUserName();
  	    	//applicationName = info.getApplicationName();
  	    		    	
  	    	
  	    	// Unknown request -- Not an initial call (context) or navigate inside a portlet (session id)
  	    	if ( callerContextPath == null)
  	    	{
  		    	try
  				{
  		    		// Won't work in this context. Display an error
  		    		response.getWriter().println("<br/><b>Error in phpRedirectorServlet servlet. Couldn't find query string for " + CALLER_CONTEXT + "</b>" );
  				}
  		    	catch (IOException ioe)
  				{
  		    		//Write to the console
  		    		System.out.println("Exception while writing to HTTPServletRespone obj " + ioe.getMessage());
  		    		
  				}
  		    	
  		    	// Can't continue
  		    	//return;
  		    	throw new ServletException("no context path found. SessionID[" + cookieValue +"]");
  	    	}
  	    }
  	    else
  	    {
  		    //Extract the context path
  	    	callerContextPath = requestQuery.substring(requestQuery.indexOf(CALLER_CONTEXT) + CALLER_CONTEXT.length() );
  	    	int indSep = callerContextPath.indexOf('&');
  	    	if ( indSep != -1)
  	    	{
  	    		callerContextPath = callerContextPath.substring(0, indSep);
  	    	}
  	    	
  	    	// Extract the user name
  	    	callingUser = requestQuery.substring(requestQuery.indexOf(USERNAME) + USERNAME.length() );
  	    	if (callingUser != null)
  	    	{
  	    		indSep = callingUser.indexOf('&');
  		    	if ( indSep != -1)
  		    	{
  		    		callingUser = callingUser.substring(0, indSep);
  		    	}
  	    	}
  	    	
  		    	
  	    	//Extract PortletID Name from the query string
  		    portletID = requestQuery.substring(requestQuery.indexOf(PORTLETID) + PORTLETID.length() );
  	    	if (portletID != null)
  	    	{
  	    		indSep = portletID.indexOf('&');
  		    	if ( indSep != -1)
  		    	{
  		    		portletID = portletID.substring(0, indSep);
  		    	}
  	    	}
  		    	
  	    	// Store the information in a struct that gets stored in the hasmap
  	    	UserContextInfo info = new UserContextInfo(callerContextPath, callingUser, applicationName, portletID);
  	    	
  	    	//Store the caller context and the session ID in the Session2Context hash. This will be used to
  	    	// redirect future calls to the servlet to the same portlet based on the session ID and the appname
  	    	session2Context.put( cookieValue+applicationName, info);
  	    }
  	    
  	    // Got caller context path.
  	    //	Update URL and query and send it back to portlet
  	   	    	
      	String URI = request.getRequestURI();
      	
      	String phpFile = reqURL.substring( reqURL.lastIndexOf(applicationName), reqURL.indexOf(".php") + 4);
      	
      	if (requestQuery == null || requestQuery.length() == 0)
      		requestQuery = "php-file=";
      	else
      		requestQuery += "&php-file=";
      	
      	requestQuery += phpFile;
      	
      	//Add user to query if it isn't already defined
      	if ( requestQuery.indexOf(USERNAME) == -1)
      	{
  	    	requestQuery += "&";
  	    	requestQuery += USERNAME;
  	    	requestQuery += callingUser;
      	}
      	
      	// Add user to query if it isn't already defined
      	if ( requestQuery.indexOf(APPNAME) == -1)
      	{
  	    	requestQuery += "&";
  	    	requestQuery += APPNAME;
  	    	requestQuery += applicationName;
      	}
      		
      	/** Build the portal url
      	 * 	Use caller server/port add caller context and query
      	 */
      	
  	    StringBuffer redirectURLBuffer = new StringBuffer();  
  	    redirectURLBuffer.append("http://").append(request.getServerName()).append(":").append(request.getServerPort()).append(callerContextPath).append("?").append(requestQuery);
  	     	    
  	    try
  		{
  	    	response.sendRedirect(redirectURLBuffer.toString() );
  		}
  	    catch (IOException ioe)
  		{
  	    	// Write to the console
  	    	System.out.println("Exception while redirecting to: " + redirectURLBuffer + ioe.getMessage());
  		}
   
  	}	
  }
  
  
  /**
   *
   * UserContextInfo class.
   * Stores information about the initial session
   */
  class UserContextInfo
  {
  	private String callerContext = null;
  	private	String userName = null;
  	private String applicationName = null;
  	private String portletID	= null;
  	
  	public UserContextInfo(String callerContext, String userName, String appName, String portletID)
  	{
  		this.callerContext		=	callerContext;
  		this.userName			=	userName;
  		this.applicationName	=	appName;
  		this.portletID 			=	portletID;
  	}
  	
  	public void setCallerContext(String callerContext)
  	{
  		this.callerContext = callerContext;
  	}
  	
  	public String getCallerContext()
  	{
  		return this.callerContext;
  	}
  	
  	public void setUserName(String userName)
  	{
  		this.userName = userName;
  	}
  	
  	public String getUserName()
  	{
  		return this.userName;
  	}
  	
  	public void setApplicationName(String appName)
  	{
  		this.applicationName = appName;
  	}
  	
  	public String getApplicationName()
  	{
  		return this.applicationName;
  	}
  	
  	public void setPortletID(String portletID)
  	{
  		this.portletID = portletID;
  	}
  	
  	public String getPortletID()
  	{
  		return this.portletID;
  	}
  	
  }
  
  
  
  1.1                  jakarta-jetspeed-2/applications/php/src/java/org/apache/jetspeed/portlets/php/ServletConfigImpl.java
  
  Index: ServletConfigImpl.java
  ===================================================================
  /*
   * Copyright 2000-2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.portlets.php;
  
  import java.util.Enumeration;
  
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  import javax.portlet.PortletConfig;
  
  /**
  * ServletConfigImpl Wrapper around PortletConfig
  * 
  * @author <a href="mailto:rogerrut@apache.org">Roger Ruttimann</a>
  * @version $Id: ServletConfigImpl.java,v 1.1 2004/07/21 17:47:06 rogerrut Exp $
  */
  class ServletConfigImpl implements ServletConfig
  {
      private PortletConfig config;
      private ServletContext context = null;
      public ServletConfigImpl(PortletConfig config)
      {
          this.config = config;
      }
      public String getInitParameter(String arg0)
      {
          return config.getInitParameter(arg0);
      }
      public Enumeration getInitParameterNames()
      {
          return config.getInitParameterNames();
      }
      public synchronized ServletContext getServletContext()
      {
          
          return context;
      }
      public String getServletName()
      {
          return config.getPortletName();
      }
      public String toString()
      {
          return config.toString();
      }
  }
  
  
  1.1                  jakarta-jetspeed-2/applications/php/src/webapp/WEB-INF/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                           "http://java.sun.com/dtd/web-app_2_3.dtd">
  <!--
  Copyright 2004 The Apache Software Foundation
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->
  <web-app>
   <display-name>PHP Portlets</display-name>
   <description>PHP Portlets</description>
   <servlet>
  	    <servlet-name>
  	      jetspeed-php
  	    </servlet-name>
  	    <servlet-class>
  	      org.apache.jetspeed.portlets.php.phpRedirectorServlet
  	    </servlet-class>
  	  </servlet>
  	  
  	  <servlet-mapping>
  	    <servlet-name>
  	      jetspeed-php
  	    </servlet-name>
  	    <url-pattern>
  	      *.php
  	    </url-pattern>
  	  </servlet-mapping>
  	  
  	  <servlet>
      <servlet-name>JetspeedContainer</servlet-name>
      <display-name>Jetspeed Container</display-name>
      <description>MVC Servlet for Jetspeed Portlet Applications</description>
      <servlet-class>org.apache.jetspeed.container.JetspeedContainerServlet</servlet-class>
    </servlet>
  
    <servlet-mapping>
       <servlet-name>
          JetspeedContainer
       </servlet-name>
       <url-pattern>
         /container/*
       </url-pattern>
    </servlet-mapping>
  </web-app>
  
  
  
  
  
  
  
  
  1.1                  jakarta-jetspeed-2/applications/php/src/webapp/WEB-INF/jetspeed-portlet.xml
  
  Index: jetspeed-portlet.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
  Copyright 2004 The Apache Software Foundation
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->
  <portlet-app id="PHP" version="1.0" 
      xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" 
      xmlns:js="http://portals.apache.org/jetspeed" 
      xmlns:dc="http://www.purl.org/dc">
      
      <dc:title>PHP Portlets</dc:title>
      <dc:title xml:lang="en">PHP Portlets</dc:title>
      <dc:creator>J2 Team</dc:creator>
      
      <portlet>
          <portlet-name>php-demo</portlet-name>
          <dc:title>PHP Demo Portlet</dc:title>
          <dc:creator>J2 Team</dc:creator>
      </portlet>
      
      
  
  </portlet-app>
  


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org