package org.apache.jsp.sales.agenda;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import com.edeal.frontline.controller.actions.agenda.AgendaEntryList;
import com.edeal.frontline.controller.actions.agenda.AgendaEntry;
import com.edeal.frontline.navigation.FlRequest;
import com.edeal.frontline.*;
import org.json.JSONObject;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import org.json.JSONArray;

public final class json_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
      out.write("\n");
 

final org.apache.commons.logging.Log logger = org.apache.commons.logging.LogFactory.getLog(getClass());
FlRequest flRequest = new FlRequest(request);
FlContext context = flRequest.getContext();
AgendaEntryList list = (AgendaEntryList)flRequest.getAttribute("AgendaEntryList");
String actId = (String) session.getAttribute("actorID");
DateFormat dfs =  new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
JSONArray array = null;
if (list != null && list.size() > 0) {
array = new JSONArray();
	for (int i = 0; i < list.size();i++) {
		AgendaEntry entry = list.getEntryAt(i);
		String subject = entry.getSubject();
		//subject=(subject==null)?"":Utils.formatToJavascript(subject);
		String body = entry.getText();
		//body=(body==null)?"":" "+Utils.formatToJavascript(body);
		try {
			JSONObject obj = new JSONObject();
			obj.put("id", entry.getObjectID());
			obj.put("title", subject + ((body == null) ? "" : body));
			obj.put("start", dfs.format(entry.getBeginningDate()));
			obj.put("end", dfs.format(entry.getEndDate()));
			obj.put("allDay", new Boolean(false));
			obj.put("url", "javascript:show(\'Interaction\',\'" + entry.getObjectID() + "\');");
			obj.put("editable", actId.equalsIgnoreCase(flRequest.getParameter("actor")) ? new Boolean(true) : new Boolean(false));
			obj.put("description", entry.getIcon());
			obj.put("className", "class-" + entry.getCategory());
			array.put(obj);
	    } catch (Exception e) {
	     	logger.error("Exception occured in the Agenda JSON :" + e.getMessage());
	    }		 		
	} // for
}
 String json = array == null ? null : array.toString();
 logger.debug("json--------- : " + json);
      out.write('\n');
      out.print( json );
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else log(t.getMessage(), t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
