package com.simoncat.actions;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import com.simoncat.vo.Server;
import com.simoncat.beans.EventServerOutput;
import com.simoncat.beans.FinalScreenOutput;
import com.simoncat.Constants;
import java.util.Collection;
import java.util.ArrayList;
import com.simoncat.beans.XMLServers;
import com.simoncat.vo.HTMLFormField;
import java.util.Date;
import java.text.DateFormat;
import java.util.Locale;
public final class EventServerAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("1--->");
//HttpSession session = request.getSession();
System.out.println("2--->");
Server ss[];
XMLServers xmlserver = new XMLServers();
ss=xmlserver.readXmls("", this.getServlet().getServletContext());
System.out.println("3--->");
if(ss==null){
FinalScreenOutput fso = new FinalScreenOutput();
fso.setPageTitle ("Event Server [Finished]");
fso.setMessage ("No existen servidores para programar reinicios!");
if (Constants.xmlOutputOnly) {
request.setAttribute ("content", Constants.xmlContentType);
} else {
request.setAttribute ("content", Constants.htmlContentType);
request.setAttribute ("style", "confirm.xsl");
}
request.setAttribute ("form", fso);
return (mapping.findForward(Constants.XMLHandler));
}
// Now, let's prepare output
EventServerOutput iwao = new EventServerOutput();
iwao.setFormAction ("Schedule.do");
iwao.setFormMethod ("POST");
// HTML form's fields
Collection fco = new ArrayList();
//http://127.0.0.1:8080/mvx/EventServer.do?form=new&value=10/27/08&Submit=localhostl
String form_ = request.getParameter("form");
String value = request.getParameter("value");
Locale locale = new Locale("es","ES");
Date date = new Date(value);
String s1,s2;
s1 = DateFormat.getDateInstance(DateFormat.FULL).format(date);
s2 = DateFormat.getTimeInstance(DateFormat.FULL, locale).format(date);
// Saturday, February 16, 2002
iwao.setPageTitle ("Event Server:" + s1 + " " + s2);
HTMLFormField hff1 = new HTMLFormField();
hff1.setTitle ("value");
hff1.setName ("value");
hff1.setType ("hidden");
hff1.setSize ("25");
hff1.setValue (value);
fco.add (hff1);
HTMLFormField hff2 = new HTMLFormField();
hff2.setTitle ("form");
hff2.setName ("form");
hff2.setType ("hidden");
hff2.setSize ("25");
hff2.setValue ( form_ );
fco.add (hff2);
iwao.setFields(fco);
System.out.println("4");
Collection coo = new ArrayList();
for(int j=0;j<ss.length;j++)
coo.add (ss[j]);
System.out.println("5");
iwao.setServers(coo);
System.out.println("6");
if (Constants.xmlOutputOnly) {
request.setAttribute ("content", Constants.xmlContentType);
} else {
request.setAttribute ("content", Constants.htmlContentType);
request.setAttribute ("style", "eventServer.xsl");
}
System.out.println("7-->");
request.setAttribute ("form", iwao);
System.out.println("8-->");
return (mapping.findForward(Constants.XMLHandler));
}
}