public void processWithDocument(ItsNatAttachedClientEvent event) { int phase = event.getPhase(); if (phase == ItsNatAttachedClientEvent.REQUEST) { String[] msg = new String[1]; if (event instanceof ItsNatAttachedClientTimerEvent) { ItsNatAttachedClientTimerEvent timerEvent = (ItsNatAttachedClientTimerEvent) event; boolean accepted = (timerEvent.getRefreshInterval() >= 3000); event.setAccepted(accepted); if (!accepted) msg[0] = "Refresh interval too short: " + timerEvent.getRefreshInterval(); } else if (event instanceof ItsNatAttachedClientCometEvent) { event.setAccepted(true); } else // "none" refresh mode { event.setAccepted(true); } if (event.getWaitDocTimeout() > 30000) { event.setAccepted(false); msg[0] = "Too much time waiting for iframe/object/embed: " + event.getWaitDocTimeout(); } ItsNatServletRequest request = event.getItsNatServletRequest(); ServletRequest servRequest = request.getServletRequest(); 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 if (!event.isAccepted()) event.getItsNatEventListenerChain().stop(); // Not really necessary }
@Override public void handleEvent(Event evt) { StringBuilder code = new StringBuilder(); // Registramos antes de que se ejecute el auto-complete // Filtramos los eventos change generados por el navegador por el autocomplete code.append("var filter = function (evt)\n"); code.append("{\n"); code.append(" var evtList = evt.getListenerWrapper(); \n"); code.append(" if (!evtList.getType) return true;\n"); code.append( " return (evtList.getType() != \"change\");\n"); // Si devuelve false entonces no enviar al // servidor este evento code.append("};\n"); code.append("itsNatDoc.addGlobalEL(filter);\n"); code.append("var listener = function ()\n"); code.append("{\n"); code.append(" var itsNatDoc = arguments.callee.itsNatDoc;\n"); code.append( " itsNatDoc.removeGlobalEL(arguments.callee.filter);\n"); // Restauramos tras el auto // complete // Reconstuirmos así el objeto de utilidad response en fase load aunque ya no estamos en esa // fase // y evitamos así problemas de serialización si memorizáramos el objeto original como un // atributo (o por captura de contexto ocurre serialización indirecta) ResponseLoadStfulDocumentValid response = new ResponseLoadStfulDocumentValidFakeForOperaOld(clientDoc); ResponseDelegateStfulWebLoadDocImpl responseDeleg = (ResponseDelegateStfulWebLoadDocImpl) ResponseDelegateStfulLoadDocImpl.createResponseDelegateStfulLoadDoc(response); code.append(responseDeleg.rewriteClientUIControlProperties(true)); code.append("};\n"); code.append("listener.filter = filter;\n"); code.append("listener.itsNatDoc = itsNatDoc;\n"); code.append( "itsNatDoc.setTimeout(listener,0);"); // El listener se ejecutará *después* del // auto-complete ClientDocument clientDoc = ((ItsNatEvent) evt).getClientDocument(); clientDoc.addCodeToSend(code.toString()); // Antes de ejecutarse el rewriteClientUIControlProperties(), Opera hace el autofill }