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

import java.net.URLEncoder;
import java.util.*;
import org.w3c.dom.*;
import com.silverwrist.util.StringUtil;
import com.silverwrist.venice.core.*;
import com.silverwrist.venice.util.*;

public class ScriptLibrary
{
  /*--------------------------------------------------------------------------------
   * External operations
   *--------------------------------------------------------------------------------
   */

  public ConferenceContext castConferenceContext(Object o)
  {
    if (o instanceof ConferenceContext)
      return (ConferenceContext)o;
    throw new ClassCastException("ScriptLibrary.castConferenceContext: invalid cast");

  } // end castConferenceContext

  public ConferenceHotlistEntry castConferenceHotlistEntry(Object o)
  {
    if (o instanceof ConferenceHotlistEntry)
      return (ConferenceHotlistEntry)o;
    throw new ClassCastException("ScriptLibrary.castConferenceHotlistEntry: invalid cast");

  } // end castConferenceHotlistEntry

  public SideBoxDescriptor castSideBoxDescriptor(Object o)
  {
    if (o instanceof SideBoxDescriptor)
      return (SideBoxDescriptor)o;
    throw new ClassCastException("ScriptLibrary.castSideBoxDescriptor: invalid cast");

  } // end castSideBoxDescriptor

  public TopicMessageContext castTopicMessageContext(Object o)
  {
    if (o instanceof TopicMessageContext)
      return (TopicMessageContext)o;
    throw new ClassCastException("ScriptLibrary.castTopicMessageContext: invalid cast");

  } // end castTopicMessageContext

  public UserFound castUserFound(Object o)
  {
    if (o instanceof UserFound)
      return (UserFound)o;
    throw new ClassCastException("ScriptLibrary.castUserFound: invalid cast");

  } // end castUserSideBoxDescriptor

  public UserSideBoxDescriptor castUserSideBoxDescriptor(Object o)
  {
    if (o instanceof UserSideBoxDescriptor)
      return (UserSideBoxDescriptor)o;
    throw new ClassCastException("ScriptLibrary.castUserSideBoxDescriptor: invalid cast");

  } // end castUserSideBoxDescriptor

  public boolean[] createBooleanArray(int len)
  {
    return new boolean[len];

  } // end createBooleanArray

  public int[] createIntArray(int len)
  {
    return new int[len];

  } // end createIntArray

  public void done() throws ScriptExit
  {
    throw new ScriptExit();

  } // end done

  public boolean emptyString(String s)
  {
    return StringUtil.isStringEmpty(s);

  } // end emptyString

  public String encodeHTML(String s)
  {
    return StringUtil.encodeHTML(s);

  } // end encodeHTML

  public String encodeURL(String s)
  {
    return URLEncoder.encode(s);

  } // end encodeURL

  public String exceptionType(Object o) throws ScriptExit
  {
    if (o instanceof ScriptExit)
      throw (ScriptExit)o;   // rethrow ScriptExit exceptions
    if (o instanceof Throwable)
      return o.getClass().getName();
    else
      return null;

  } // end exceptionType

  public String join(List l, String separator)
  {
    return StringUtil.join(l,separator);

  } // end join

  public List splitList(String data, String delims)
  {
    return StringUtil.splitList(data,delims);

  } // end splitList

  public boolean validVeniceID(String s)
  {
    return IDUtils.isValidVeniceID(s);

  } // end validVeniceID

} // end class ScriptLibrary
