001: /*
002: ItsNat Java Web Application Framework
003: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004: Author: Jose Maria Arranz Santamaria
005:
006: This program is free software: you can redistribute it and/or modify
007: it under the terms of the GNU Affero General Public License as published by
008: the Free Software Foundation, either version 3 of the License, or
009: (at your option) any later version. See the GNU Affero General Public
010: License for more details. See the copy of the GNU Affero General Public License
011: included in this program. If not, see <http://www.gnu.org/licenses/>.
012: */
013:
014: package org.itsnat.impl.core;
015:
016: import java.io.IOException;
017: import java.io.Writer;
018: import org.itsnat.core.ItsNatDocument;
019: import org.itsnat.core.event.ItsNatServletRequestListener;
020: import org.itsnat.core.ItsNatServletResponse;
021: import org.itsnat.core.ItsNatServlet;
022: import javax.servlet.ServletResponse;
023: import org.itsnat.core.ItsNatSession;
024: import org.itsnat.impl.core.client.ClientDocumentImpl;
025:
026: /**
027: *
028: * @author jmarranz
029: */
030: public abstract class ItsNatServletResponseImpl extends
031: ItsNatUserDataImpl implements ItsNatServletResponse {
032: protected ItsNatServletRequestImpl request;
033: protected ServletResponse response;
034: protected StringBuffer codeToSend = new StringBuffer();
035:
036: /**
037: * Creates a new instance of ItsNatServletResponseImpl
038: */
039: public ItsNatServletResponseImpl(ItsNatServletRequestImpl request,
040: ServletResponse response) {
041: super (false);
042:
043: this .request = request;
044: this .response = response;
045: }
046:
047: public ItsNatServletRequestImpl getItsNatServletRequestImpl() {
048: return request;
049: }
050:
051: public ServletResponse getServletResponse() {
052: return response;
053: }
054:
055: public Writer getWriter() throws IOException {
056: // Se supone que el encoding del response ya fue definido antes.
057: return response.getWriter();
058: }
059:
060: public abstract Writer getWriterGZip() throws IOException;
061:
062: public ItsNatDocumentImpl getItsNatDocumentImpl() {
063: return getItsNatServletRequestImpl().getItsNatDocumentImpl();
064: }
065:
066: public ItsNatDocument getItsNatDocument() {
067: return getItsNatDocumentImpl();
068: }
069:
070: public ItsNatServlet getItsNatServlet() {
071: return getItsNatServletImpl();
072: }
073:
074: public ItsNatServletImpl getItsNatServletImpl() {
075: return getItsNatServletRequestImpl().getItsNatServletImpl();
076: }
077:
078: public ItsNatSession getItsNatSession() {
079: return getItsNatServletSessionImpl();
080: }
081:
082: public ItsNatSessionImpl getItsNatServletSessionImpl() {
083: return getItsNatServletRequestImpl().getItsNatSessionImpl();
084: }
085:
086: public String getCodeToSend() {
087: ItsNatDocumentImpl itsNatDoc = getItsNatDocumentImpl();
088: if (itsNatDoc != null) // En el caso de proceso de back/forward button el documento no está definido pero necesitamos enviar código al servidor
089: {
090: ClientDocumentImpl listener = getItsNatServletRequestImpl()
091: .getClientDocumentImpl();
092: codeToSend.append(listener.getCodeToSendAndReset());
093: }
094: return codeToSend.toString();
095: }
096:
097: public void addCodeToSend(String newCode) {
098: // No se propaga a los observadores
099: codeToSend = new StringBuffer(getCodeToSend() + newCode);
100: }
101:
102: public abstract void preProcess();
103:
104: public void postProcess() {
105: }
106:
107: public void dispatchRequestListener(
108: ItsNatServletRequestListener listener) {
109: listener.processRequest(getItsNatServletRequestImpl(), this);
110: }
111: }
|