/*
 * 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.dynamo.velocity;

import java.io.*;
import com.silverwrist.util.*;
import com.silverwrist.dynamo.except.*;
import com.silverwrist.dynamo.iface.*;
import com.silverwrist.dynamo.util.*;

public class StdObject
{
  /*--------------------------------------------------------------------------------
   * Attributes
   *--------------------------------------------------------------------------------
   */

  private TextRenderControl m_control;
  private URLRewriter m_rewriter = null;

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

  StdObject(TextRenderControl control)
  {
    m_control = control;

  } // end constructor

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

  public String formatURL(String type, String url)
  {
    if (m_rewriter==null)
      m_rewriter = (URLRewriter)(m_control.queryService(URLRewriter.class));
    return m_rewriter.rewriteURL(type,url);

  } // end formatURL

  public String encodeHTML(String data)
  {
    return StringUtils.encodeHTML(data);

  } // end encodeHTML

  public String encodeURL(String data)
  {
    return StringUtils.encodeURL(data);

  } // end if

  public String renderObject(Object obj) throws IOException, RenderingException
  {
    BufferTextRenderControl bufctrl = new BufferTextRenderControl(m_control);
    bufctrl.renderSubObject(obj);
    return bufctrl.getData();

  } // end renderObject

  public String renderDialog(Dialog dlg) throws IOException, RenderingException
  {
    BufferTextRenderControl bufctrl = new BufferTextRenderControl(m_control);
    dlg.render(bufctrl);
    return bufctrl.getData();

  } // end renderDialog

  public String getStackTrace(Throwable t)
  {
    StringWriter wr = new StringWriter();
    PrintWriter wr2 = new PrintWriter(wr);
    t.printStackTrace(wr2);
    wr2.flush();
    return wr.toString();

  } // end getStackTrace

} // end class StdObject
