package examples.htmlkona;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import weblogic.html.*;
/**
* This servlet illustrates how to build elements with htmlKona that
* appear on an HTML page.
*
* @author Copyright (c) 1996-98 by WebLogic, Inc. All Rights Reserved.
* @author Copyright (c) 1999 by BEA WebXpress, Inc. All Rights Reserved.
*/
public class SimplePage extends HttpServlet {
public synchronized void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
try {
res.setStatus(HttpServletResponse.SC_OK);
res.setContentType("text/html");
ServletPage hp = getDefaultPage();
hp.getBody()
.removeElementAt("line3")
.replaceElementAt(new HeadingElement("This is a heading", 2), "heading")
.replaceElementAt("This is the ", "body")
.insertElementAt("This is the first part of the body", "body")
.insertElementAt(MarkupElement.BeginParagraph, "body");
String str = hp.getBody()
.getElementAt("body").toString() + "second part of the body";
hp.getBody()
.replaceElementAt(new ItalicElement(str), "body");
hp.output(res.getOutputStream());
}
catch (Exception e) {
defaults.showException(e, res.getOutputStream());
}
}
public static ServletPage getDefaultPage() {
ServletPage page = new ServletPage();
page.getHead()
.addElement(new TitleElement("Simple Page"));
page.getBodyElement()
.setAttribute(BodyElement.bgColor, HtmlColor.white);
page.getBody()
.addElement(MarkupElement.BeginCenter)
.addElement("heading", "")
.addElement(MarkupElement.EndCenter)
.addElement("line1", MarkupElement.HorizontalLine)
.addElement("body", "")
.addElement("line2", MarkupElement.HorizontalLine)
.addElement("line3", MarkupElement.HorizontalLine)
.addElement(new AnchorElement("http://www.weblogic.com/",
"Copyright © 1996-1999, BEA Systems, Inc. "
+ "All Rights Reserved."))
.addElement(MarkupElement.BeginParagraph);
return page;
}
}