boolean accepted = askToUser(event,msg);
event.setAccepted(accepted);
if (accepted && !event.isReadOnly())
{
ItsNatDocument itsNatDoc = event.getItsNatDocument();
final ClientDocument clientOwner = itsNatDoc.getClientDocumentOwner();
StringBuilder note = new StringBuilder();
note.append("alert(\"Dear user, you have accepted that another user can modify the document in server ");
note.append("in the same way you can. To help you almost instantaneously see ");
note.append("what the other user is doing, a timer has been added to update your page ");
note.append("each 3 seconds for 30 minutes\");");
clientOwner.addCodeToSend(note);
EventListener listener = new EventListener()
{
public void handleEvent(Event evt)
{
ItsNatTimerEvent timerEvt = (ItsNatTimerEvent)evt;
ItsNatTimerHandle handle = timerEvt.getItsNatTimerHandle();
long firstTime = handle.getFirstTime();
if ((new Date().getTime() - firstTime) > 30*60*1000) // 30 minutes
{
handle.cancel();
clientOwner.addCodeToSend("The timer for updating the client has finished");
}
}
};
ItsNatTimer timer = clientOwner.createItsNatTimer();
timer.schedule(null,listener,1000,3000);
}
}
}
if (!event.isAccepted())
{
ItsNatServletResponse response = event.getItsNatServletResponse();
ItsNatServlet servlet = response.getItsNatServlet();
@SuppressWarnings("unchecked")
Map<String,String[]> newParams = new HashMap<String,String[]>(servRequest.getParameterMap());
newParams.remove("itsnat_action"); // Removes: itsnat_action=attach_doc
newParams.put("itsnat_doc_name",new String[]{"feashow.ext.core.misc.remCtrlReqRejected"});
newParams.put("reason", msg); // submitted as array
servRequest = servlet.createServletRequest(servRequest, newParams);
servlet.processRequest(servRequest,response.getServletResponse());
}
}
else if (phase == ItsNatAttachedClientEvent.REFRESH)
{
ClientDocument observer = event.getClientDocument();
if (observer.getItsNatDocument().isInvalid())
{
observer.addCodeToSend("alert('Observed document was destroyed');");
}
else
{
long initTime = observer.getCreationTime();
long currentTime = System.currentTimeMillis();
long limitMilisec = 15*60*1000;
// 15 minutes (to avoid a long monitoring session)
if (currentTime - initTime > limitMilisec)
{
event.setAccepted(false);
observer.addCodeToSend("alert('Remote Control Timeout');\n");
}
}
}
// ItsNatAttachedClientEvent.LOAD & UNLOAD : nothing to do