In the XML Grapher example, the code of the servlet can
be rewritten using the IlvManagerServletSupport
class
as follows:
package demo.xmlgrapher.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import java.io.*;
import ilog.views.*;
import ilog.views.servlet.*;
import demo.xmlgrapher.*;
public class XmlGrapherServlet extends HttpServlet
{
IlvManagerServletSupport servletSupport ;
class MySupport extends IlvManagerServletSupport {
private XmlGrapher xmlGrapher;
public MySupport(ServletConfig config) {
super();
xmlGrapher = new XmlGrapher();
String xmlfile = config.getInitParameter("xmlfile");
if (xmlfile == null)
xmlfile = config.getServletContext().getRealPath("/data/world.xml");
try {
xmlGrapher.setNetwork(new URL("file:" + xmlfile));
} catch (MalformedURLException ex) {
}
setVerbose(true);
}
public IlvManagerView getManagerView(HttpServletRequest request)
throws ServletException {
return xmlGrapher;
}
protected float getMaxZoomLevel(HttpServletRequest request,
IlvManagerView view) {
return 30;
}
}
/**
* Initializes the servlet.
*/
public void init(ServletConfig config) throws ServletException {
servletSupport = new MySupport(config);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
if (!servletSupport.handleRequest(request, response))
throw new ServletException("unknown request type");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
doGet(request, response);
}
}
This code creates a new servlet class, XmlGrapherServlet
,
that derives directly from the HttpServlet
class.
The doGet
method passes the requests to
an instance of the IlvManagerServletSupport
class.