/* Copyright (c) 2001, 2002, Oracle Corporation.  All rights reserved.  */

package beans;

import java.io.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;

/**
 *  Book Service Java Bean
 * 
 */
public class BookServiceBean  
{
  private String m_isbn = null;
  private long m_timeToLive = 0; // Time to Live in mins (Default 0 min)
  private boolean debugMe = false;
  private boolean useCached = false;
  private String  submitStr = "Apply XSL transform";
  private String outputType = "HTML";  
  private Hashtable errors;
  private boolean applyXSL;


  /**
   * Constructor
   */
  public BookServiceBean()
  {
    errors = new Hashtable();
  }

 
  public long getTimeToLive() {return m_timeToLive; }

  public void setTimeToLive(String ttl)
  {
    if(ttl == null || ttl.trim().length() == 0)
      ttl = "0";
     m_timeToLive = new Long(ttl).longValue();
  }

  public void setTimeToLive(long ttl) { m_timeToLive = ttl; }
  
  public String getSubmitStr()
  {
    	if(applyXSL == false)
        submitStr = "Apply XSL transform";
      else
         submitStr = "How did we get this result ?";
      return submitStr;
  }

  public String getBaseUrl(HttpServletRequest request)
  {
    StringBuffer reqUrl = request.getRequestURL();
  	String baseUrl = reqUrl.substring(0,reqUrl.toString().lastIndexOf("/")+1);
    return baseUrl;
  }
  
  public void setSubmitStr(String newSubStr) { submitStr = newSubStr;}

  public String getOutputType()
  {
      if(applyXSL == false)
        outputType = "HTML";
      else
        outputType = "XSLT";
      return outputType;
  }

  public void setOutputType(String newOutputType)
  {
    outputType = newOutputType;
  }
  
  public boolean isApplyXsl() { return applyXSL; }

  public void setApplyXsl(String newApplyXSL)
  {
    applyXSL =  new Boolean(newApplyXSL).booleanValue();
  }

 public void setApplyXsl(boolean newApplyXSL)
  {
    applyXSL =  newApplyXSL;
  }
  
  public void setIsbn(String newIsbn)
  {
    if(newIsbn == null || newIsbn.equals("") == true)
    	errors.put("isbn","Enter a valid International Standerd Book Number (ISBN)");
    else
      m_isbn = newIsbn;
  }

  public String getIsbn() {return m_isbn; }
  public String getErrorMsg(String s) 
  {
    String errorMsg =(String)errors.get(s.trim());
    return (errorMsg == null) ? "":errorMsg;
  }

  public boolean getDebugMe()  {return debugMe; }

  public void setDebugMe(boolean debug) { debugMe = debug; }


}