/*
 * Licensed Materials - Property of Perforce Software, Inc. 
 * © Copyright Perforce Software, Inc. 2014, 2021 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */

package xmlgrapher.servlet;

import ilog.views.IlvManagerView;
import ilog.views.servlet.IlvManagerServlet;
import ilog.views.util.servlet.IlvParameterValidationListener;
import ilog.views.util.servlet.annotation.IlvServerActionParam;
import ilog.views.util.servlet.annotation.IlvServerActions;

import java.net.MalformedURLException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import xmlgrapher.XmlGrapher;

IlvServerActions(parameters = { IlvServerActionParam(actionName = IlvParameterValidationListener.ACTION_NAME, actionListener = MyServletParamValidationListener.class) })
public class XmlGrapherServlet extends IlvManagerServlet
{
  
  private XmlGrapher xmlGrapher;

  /**
   * Initializes the servlet.
   * Creates the Supervision component.
   */
  Override
  public void init(ServletConfig config) 
       throws ServletException 
  {
    super.init(config);

    xmlGrapher = new XmlGrapher();

    String xmlfile = config.getInitParameter("xmlfile");

    if (xmlfile == null) {
      xmlfile = "/data/world.xml";
    }
    
    try {
      xmlGrapher.setNetwork(config.getServletContext().getResource(xmlfile));
    } catch (MalformedURLException ex) {
    }
  }

  Override
  public IlvManagerView getManagerView(HttpServletRequest request) 
       throws ServletException
  {
    return xmlGrapher;
  }
  
 
  Override
  protected double getMaxZoomLevel(HttpServletRequest request, IlvManagerView view) {
    return 30;
  }
  
}