package examples.htmlkona;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import weblogic.common.*;
import weblogic.html.*;

/**
 * This servlet shows how to use htmlKona Frames.
 * 
 * @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 SimpleFrame extends HttpServlet {

  public synchronized void service(HttpServletRequest req, HttpServletResponse res)
    throws IOException
  {
    try {
      res.setStatus(HttpServletResponse.SC_OK);
      res.setContentType("text/html");

      String name = req.getParameter("name");

      ServletPage hp   = new ServletPage();
      hp.getHead()
	.addElement(new TitleElement("Simple Frame"));
      String base = defaults.prefix() + "SimpleFrame";
      
      if ((name == null) || (name.equals(""))) {
        FrameSetElement fs = new FrameSetElement().setRows("30%,70%");
        fs.addElement(new FrameElement().setName("Frame1")
                                        .setSource(base + "?name=Frame1"));

        FrameSetElement fs2 = new FrameSetElement().setCols("50%,50%");
        fs2.addElement(new FrameElement().setName("Frame2")
                                         .setSource(base + "?name=Frame2"));
        fs2.addElement(new FrameElement().setName("Frame3")
                                         .setSource(base + "?name=Frame3"));
        fs.addElement(fs2);
        hp.setFrameSetElement(fs);
      }
      else
	hp.getBodyElement()
	  .setAttribute(BodyElement.bgColor, HtmlColor.white);
        hp.getBody()
          .addElement(new HeadingElement("This is " + name));

      hp.output(res.getOutputStream());
    }
    catch (Exception e) {
      defaults.showException(e, res.getOutputStream());
    }
  }

}
