/*
 * 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-03 Eric J. Bowersox/Silverwrist Design Studios.  All Rights Reserved.
 * 
 * Contributor(s): 
 */
package com.silverwrist.venice.content;

import java.util.*;
import com.silverwrist.dynamo.velocity.VelocityParamSupplier;
import com.silverwrist.dynamo.velocity.VelocityRenderable;
import com.silverwrist.venice.frame.FramedContent;

/**
 * A "view object" that implements a rendering of a Velocity template, with parameters, inside of the standard
 * Venice frame.
 *
 * @author Eric J. Bowersox &lt;erbo@silcom.com&gt;
 * @version X
 */
public class VelocityView implements VelocityRenderable, FramedContent
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private String m_title;                         // title for the page
  private String m_templ;                         // name of template resource to use
  private Hashtable m_params = new Hashtable();   // parameters to give to Velocity
  private String m_menu_sel = null;               // menu selector for the page
  private String m_qid = null;                    // quick ID for the page

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

  /**
   * Constructs a new <CODE>VelocityView</CODE>.
   *
   * @param title Title to use for the page.
   * @param templ Name of the resource from which the Velocity template will be loaded.
   */
  public VelocityView(String title, String templ)
  {
    m_title = title;
    m_templ = templ;

  } // end constructor

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

  /**
   * Returns the value of a parameter set on the object.
   *
   * @param key The name of the parameter to look up.
   * @return The parameter's value, or <CODE>null</CODE> if the parameter was not set.
   */
  public Object getParameter(String key)
  {
    return m_params.get(key);

  } // end getParameter

  /**
   * Returns a <CODE>java.util.Collection</CODE> of all parameter names currently defined on this object.
   *
   * @return A collection of all parameter names currently defined.
   */
  public Collection getParameterNames()
  {
    HashSet rc = new HashSet(m_params.keySet());
    return Collections.unmodifiableSet(rc);

  } // end getParameterNames

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

  /**
   * Returns the MIME type of the output to be rendered.  Usually, this will be "text/html".
   *
   * @return The MIME type of the output.
   */
  public String getMimeType()
  {
    return "text/html";

  } // end getMimeType

  /**
   * Returns the resource name of the Velocity template to be used in rendering this object.  This pathname
   * is interpreted relative to the "resource root path" specified in the Velocity renderer's configuration.
   * The template engine loads it via the standard
   * {@link com.silverwrist.dynamo.iface.ResourceProvider ResourceProvider}, and then applies the parameters
   * contained in this object to it.
   *
   * @return The resource pathname of the Velocity template to use.
   */
  public String getTemplateName()
  {
    return m_templ;

  } // end getTemplateName

  /*--------------------------------------------------------------------------------
   * Implementations from interface FramedContent
   *--------------------------------------------------------------------------------
   */

  /**
   * Returns the desired menu selector for this page.  The <EM>menu selector</EM> is a string that specifies
   * which menu is to be displayed on the left menu bar, in addition to the "global menu."  This value may
   * be <CODE>null</CODE>, in which case the current menu selector is not changed.
   *
   * @return The desired menu selector.
   */
  public String getMenuSelector()
  {
    return m_menu_sel;

  } // end getMenuSelector

  /**
   * Returns the desired title for the page.  This title is concatenated with the <EM>site title</EM> (set in
   * global properties) to form the actual page title that gets sent to the browser.
   *
   * @return The desired page title.
   */
  public String getPageTitle()
  {
    return m_title;

  } // end getPageTitle

  /**
   * Returns the desired quick ID for the page.  The <EM>page quick ID</EM> is a small text string which can be used
   * to "tag" the page with a unique identifier, for use with external tools such as offsite hit counters.
   * If this value is <CODE>null</CODE>, the quick ID is not used for this page.
   *
   * @return The desired page quick ID.
   */
  public String getPageQID()
  {
    return m_qid;

  } // end getPageQID

  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  /**
   * Sets the value of a parameter on the object.
   *
   * @param key The name of the parameter to set.
   * @param value The value of the parameter to set, or <CODE>null</CODE> to remove the parameter.
   */
  public void setParameter(String key, Object value)
  {
    if (value!=null)
      m_params.put(key,value);
    else
      m_params.remove(key);

  } // end getParameter

  /**
   * Sets the resource name of the Velocity template to use for rendering this object.
   *
   * @param name The resource name of the Velocity template.
   */
  public void setTemplateName(String name)
  {
    m_templ = name;

  } // end setTemplateName

  /**
   * Sets the desired menu selector for this page.
   *
   * @param s The desired menu selector for the page.
   */
  public void setMenuSelector(String s)
  {
    m_menu_sel = s;

  } // end setMenuSelector

  /**
   * Sets the desired title for this page.
   *
   * @param s The desired title for the page.
   */
  public void setPageTitle(String s)
  {
    m_title = s;

  } // end setPageTitle

  /**
   * Sets the desired quick ID for this page.
   *
   * @param s The desired quick ID for the page.
   */
  public void setPageQID(String s)
  {
    m_qid = s;

  } // end setPageQID

} // end class VelocityView
