package examples.htmlkona;

import java.io.*;
import java.sql.*;
import java.util.*;
import weblogic.db.jdbc.*;
import weblogic.html.*;

/**
 * The defaults file has methods that many of the servlets in
 * this directory use for such things as connecting to a database
 * and finding directories. You can set up variables once here,
 * compile the entire directory, and not have to edit each
 * servlet.
 * 
 * @author Copyright (c) 1996-98 by WebLogic, Inc. All Rights Reserved.
 * @author Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
 */
public class defaults {

  /**** These routines are shared by all the examples in the examples. ****/

  public static java.sql.Connection login()
    throws java.sql.SQLException
  {
    Properties props = new Properties();

    // Change "scott" to a valid database username.
    props.put("user",     "scott");
    
    // Change "tiger" to a valid password for the user.
    props.put("password", "tiger");
    
    props.put("server",   defaults.server());
    // If you're connecting to a Sybase or MS SQL Server database, you
    // can add another property here for the database name, as in this
    // example: props.put("db", "mydatabase");
    
    // If you're not using WebLogic jDriver for Oracle, change the class name for
    // the driver.
    try {Class.forName("weblogic.jdbc.oci.Driver").newInstance();} catch (Exception e) {;}
    
    // If you're not using WebLogic jDriver for Oracle, change the URL for the
    // driver.
    java.sql.Connection conn = DriverManager.getConnection("jdbc:weblogic:oracle", props);
    return conn;
  }
  
  // Change the second argument to connection information to your
  // database. This may be vendor specific.
  public static final String server()  {
    return (String)System.getProperty("server", "your_server_name");
  }
  
  // Change the second argument to the URL prefix for your
  // WebLogic Server.
  public static final String prefix()  {
    return (String)System.getProperty("prefix", "http://localhost:7001/");
  }
  
  // Change the second argument to the directory location for the HTML
  // files used by the examples.
  public static final String fileloc() {
    return (String)System.getProperty("fileloc", "c:/weblogic/examples/");
  }
  
  public static final String imageloc() {
    return (String)System.getProperty("imageloc", "http://www.weblogic.com/docs/classdocs/images/");
  }
  
  public static void showException(Exception e, OutputStream out)
       throws IOException
  {
    ServletPage hp             = new ServletPage("An Exception occurred");
    ByteArrayOutputStream ostr = new ByteArrayOutputStream();
    e.printStackTrace(new PrintWriter(ostr));
    hp.getBody()
      .addElement(new HeadingElement("An Exception occurred:", 2))
      .addElement(new LiteralElement(ostr.toString()));
    hp.output(out);
  }
  
  public static void setPageDefaults() {
    TableCaptionElement.default_align = AlignType.top;
    TableElement.default_caption      = new TableCaptionElement("");
    TableElement.default_border       = 4;
    TableElement.default_cellspacing  = 2;
    TableElement.default_cellpadding  = 2;
    TableElement.default_width        = "100%";  
  }
}



