/*
ItsNat Java Web Application Framework
Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
Author: Jose Maria Arranz Santamaria
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. See the GNU Affero General Public
License for more details. See the copy of the GNU Affero General Public License
included in this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.itsnat.impl.core.response;
import java.io.IOException;
import java.io.Writer;
import org.itsnat.core.SyncMode;
import org.itsnat.impl.core.ItsNatServletResponseImpl;
import org.itsnat.impl.core.listener.dom.OnBeforeUnloadListenerImpl;
import org.itsnat.impl.core.listener.dom.OnUnloadListenerImpl;
import org.itsnat.impl.core.html.ItsNatHTMLDocumentImpl;
import org.w3c.dom.events.EventTarget;
import org.w3c.dom.views.AbstractView;
/**
*
* @author jmarranz
*/
public class ResponseNormalLoadHTMLDocumentImpl extends ResponseNormalLoadDocumentImpl
{
/** Creates a new instance of ResponseNormalLoadHTMLDocumentImpl */
public ResponseNormalLoadHTMLDocumentImpl(ItsNatServletResponseImpl itsNatResponse)
{
super(itsNatResponse);
}
public void process(Writer out) throws IOException
{
ItsNatHTMLDocumentImpl itsNatDoc = (ItsNatHTMLDocumentImpl)itsNatResponse.getItsNatDocumentImpl();
// Caso de carga del documento por primera vez, el Document est recin creado
// Aadimos el unload cuanto antes pues as damos la oportunidad a que los listeners puedan quitarlo
// Curiosamente el load/unload ha de asociarse a la window no funciona asociando al elemento BODY
AbstractView view = itsNatDoc.getDefaultView();
if (itsNatDoc.isReferrerEnabled())
itsNatDoc.addEventListener((EventTarget)view,"beforeunload",OnBeforeUnloadListenerImpl.SINGLETON,false,SyncMode.SYNC);
// Si es necesario usar siempre el modo sncrono con unload para asegurar que llega al servidor
// sobre todo con FireFox, total es destruccin
// En FireFox a veces el unload se enva pero no llega al servidor en el caso de AJAX asncrono,
// la culpa la tiene quizs el enviar por red asncronamente algo en el proceso de destruccin de la pgina
// Curiosamente esto slo ocurre cuando se abre un visor Comet y se cierra la pgina principal.
// En teora "beforeunload" debera dar menos problemas que unload en FireFox
// pero sin embargo tambin ocurri con beforeunload asncrono.
itsNatDoc.addEventListener((EventTarget)view,"unload",OnUnloadListenerImpl.SINGLETON,false,SyncMode.SYNC);
dispatchRequestListeners();
String code = itsNatResponse.getCodeToSend();
String docCode;
if (itsNatDoc.isFastLoadMode())
docCode = itsNatDoc.serializeDocument();
else
docCode = itsNatDoc.getHTMLDocumentTemplateVersion().getSerializedOriginalDocument();
boolean loadScriptInline = itsNatDoc.isLoadScriptInline();
ResponseLoadHTMLDocSharedImpl.addScriptToLoadedDocument(docCode,code,out,loadScriptInline,false,itsNatResponse);
if (!itsNatDoc.isAJAXEnabled()) // No hay eventos y por tanto no hay posibilidad de unload
itsNatDoc.getItsNatSessionImpl().unregisterItsNatDocument(itsNatDoc);
}
}
|