/*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (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.mozilla.org/MPL/>.
 * 
 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
 * language governing rights and limitations under the License.
 * 
 * The Original Code is the Venice Web Communities System.
 * 
 * The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
 * for Silverwrist Design Studios.  Portions created by Eric J. Bowersox are
 * Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.frame;

import java.util.*;
import com.silverwrist.dynamo.iface.*;
import com.silverwrist.dynamo.util.*;
import com.silverwrist.dynamo.velocity.VelocityParamSupplier;
import com.silverwrist.dynamo.velocity.VelocityRenderable;
import com.silverwrist.venice.VeniceNamespaces;
import com.silverwrist.venice.iface.*;

class FrameRendering implements VelocityRenderable
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private String m_templ;
  private VelocityParamSupplier m_base_params;
  private HashMap m_local_vars = new HashMap();

  /*--------------------------------------------------------------------------------
   * Constructor
   *--------------------------------------------------------------------------------
   */

  FrameRendering(FramedContent content, String templ, VelocityParamSupplier base_params, DynamoUser user,
		 String location, Boolean display_login, MenuRenderObject fixed_menu, String footer)
  {
    m_templ = templ;
    m_base_params = base_params;
    m_local_vars.put("content",content);
    m_local_vars.put("pagetitle",content.getPageTitle());
    m_local_vars.put("qid",content.getPageQID());
    m_local_vars.put("user",user);
    m_local_vars.put("unverified",
		     Boolean.valueOf(PropertyUtils.hasProperty(user,VeniceNamespaces.USER_SETTINGS_NAMESPACE,
							       "confirmation.number")));
    m_local_vars.put("location",location);
    m_local_vars.put("display_login",display_login);
    m_local_vars.put("fixed_menu",fixed_menu);
    m_local_vars.put("footer_text",footer);

  } // end constructor

  /*--------------------------------------------------------------------------------
   * Implementations from interface VelocityParamSupplier
   *--------------------------------------------------------------------------------
   */

  public Object getParameter(String key)
  {
    Object rc = m_local_vars.get(key);
    if (rc==null)
      rc = m_base_params.getParameter(key);
    return rc;

  } // end getParameter

  public Collection getParameterNames()
  {
    HashSet rc = new HashSet(m_local_vars.keySet());
    rc.addAll(m_base_params.getParameterNames());
    return Collections.unmodifiableSet(rc);

  } // end getParameterNames

  /*--------------------------------------------------------------------------------
   * Implementations from interface VelocityRenderable
   *--------------------------------------------------------------------------------
   */

  public String getMimeType()
  {
    return "text/html";

  } // end getMimeType

  public String getTemplateName()
  {
    return m_templ;

  } // end getTemplateName

} // end class FrameRendering
