<commit_before>package org.jasig.portal;

import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.http.*;

import java.io.*;
import java.util.*;
import java.net.URLEncoder;
import org.jasig.portal.layout.*;

/**
 * Methods to accompany dispatch.jsp
 * @author <NAME>
 * @version $Revision$
 */
public class DispatchBean extends GenericPortalBean
{    
  private static final String sDispatchChannel = "dispatchChannel";
    
  /**
   * Returns the current channel and stores it in the session
   * until DispatchBean.finish () is called by the channel
   * @param the servlet request object
   * @return the channel to call
   */
  public IChannel getChannel (HttpServletRequest req)
  {
    org.jasig.portal.IChannel ch = null;
    
    try
    {
      HttpSession session = req.getSession (false);
      ILayoutBean layoutBean = (ILayoutBean) session.getAttribute ("layoutBean");
      ch = (org.jasig.portal.IChannel) session.getAttribute (sDispatchChannel);

      if (ch == null)
      {
        String sChannelID = req.getParameter ("channelID");
        
        if (sChannelID != null)
        {
          ch = layoutBean.getChannelInstance (sChannelID);
          session.setAttribute (sDispatchChannel, ch);
        }
        else
          Logger.log (Logger.ERROR, "To dispatch properly, a channel ID must be included in the query string in the form: \"...&channelID=...\"");
      }
    }
    catch (Exception e)
    {
      Logger.log (Logger.ERROR, e);
    }
    return ch;
  }
 
  /**
   * This method should be called by a channel when it wants
   * to return to layout.jsp
   * @param the servlet request object
   */
  public static void finish (HttpServletRequest req, HttpServletResponse res)
  {
    try
    {
      HttpSession session = req.getSession (false);
      session.removeAttribute (sDispatchChannel);
      res.sendRedirect ("layout.jsp");
    }
    catch (Exception e)
    {
      Logger.log (Logger.ERROR, e);
    }
  }    
  
  /**
   * Builds a url used to send control back to a particular
   * method of a channel
   * @param the name of the channel's method to call
   * @param the channel config object
   * @return a url used to call a method in a channel
   */
  public static String buildURL (String sMethodName, ChannelConfig chConfig)
  {
    try
    {
      return buildURL (sMethodName, chConfig.getChannelID ());
    }
    catch (Exception e)
    {
      Logger.log (Logger.ERROR, e);
    }
    return null;
  } 
  
  /**
   * Builds a url used to send control back to a particular
   * method of a channel
   * @param the name of the channel's method to call
   * @param the channel's ID
   * @return a url used to call a method in a channel
   */
  public static String buildURL (String sMethodName, String sChannelID)
  {
    try
    {
      StringBuffer sbURL = new StringBuffer ("dispatch.jsp");
      sbURL.append ("?method=");
      sbURL.append (URLEncoder.encode (sMethodName));
      sbURL.append ("&channelID=");
      sbURL.append (URLEncoder.encode (sChannelID));
      return sbURL.toString ();
    }
    catch (Exception e)
    {
      Logger.log (Logger.ERROR, e);
    }
    return null;
  }   
  
}<commit_msg>Removed caching of dispatched channel.  Every link to dispatch.jsp should now be made using DispatchBean.buildURL().<commit_after>package org.jasig.portal;

import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.http.*;

import java.io.*;
import java.util.*;
import java.net.URLEncoder;
import org.jasig.portal.layout.*;

/**
 * Methods to accompany dispatch.jsp
 * @author <NAME>
 * @version $Revision$
 */
public class DispatchBean extends GenericPortalBean
{    
  /**
   * Returns an instance of the current channel
   * @param the servlet request object
   * @return the channel to call
   */
  public IChannel getChannel (HttpServletRequest req)
  {
    org.jasig.portal.IChannel ch = null;
    
    try
    {
      HttpSession session = req.getSession (false);
      ILayoutBean layoutBean = (ILayoutBean) session.getAttribute ("layoutBean");
      String sChannelID = req.getParameter ("channelID");
        
      if (sChannelID != null)
        ch = layoutBean.getChannelInstance (sChannelID);
      else
        Logger.log (Logger.ERROR, "To dispatch properly, a channel ID must be included in the query string in the form: \"...&channelID=...\"");
    }
    catch (Exception e)
    {
      Logger.log (Logger.ERROR, e);
    }
    return ch;
  }
 
  /**
   * This method should be called by a channel when it wants
   * to return to layout.jsp
   * @param the servlet request object
   */
  public static void finish (HttpServletRequest req, HttpServletResponse res)
  {
    try
    {
      res.sendRedirect ("layout.jsp");
    }
    catch (Exception e)
    {
      Logger.log (Logger.ERROR, e);
    }
  }    
  
  /**
   * Builds a url used to send control back to a particular
   * method of a channel
   * @param the name of the channel's method to call
   * @param the channel config object
   * @return a url used to call a method in a channel
   */
  public static String buildURL (String sMethodName, ChannelConfig chConfig)
  {
    try
    {
      return buildURL (sMethodName, chConfig.getChannelID ());
    }
    catch (Exception e)
    {
      Logger.log (Logger.ERROR, e);
    }
    return null;
  } 
  
  /**
   * Builds a url used to send control back to a particular
   * method of a channel
   * @param the name of the channel's method to call
   * @param the channel's ID
   * @return a url used to call a method in a channel
   */
  public static String buildURL (String sMethodName, String sChannelID)
  {
    try
    {
      StringBuffer sbURL = new StringBuffer ("dispatch.jsp");
      sbURL.append ("?method=");
      sbURL.append (URLEncoder.encode (sMethodName));
      sbURL.append ("&channelID=");
      sbURL.append (URLEncoder.encode (sChannelID));
      return sbURL.toString ();
    }
    catch (Exception e)
    {
      Logger.log (Logger.ERROR, e);
    }
    return null;
  }   
  
}
{'fraction_non_alphanumeric': 0.10203743581248964, 'fraction_numerical': 0.0, 'mean_word_length': 2.566450088600118, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '811756', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1780, 'n_words': 592}