001: /**
002: * $Id: ForwardTag.java,v 1.11 2005/09/21 10:53:19 dg154973 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.taglibs.util;
014:
015: import javax.servlet.jsp.*;
016: import javax.servlet.jsp.tagext.*;
017: import java.io.*;
018: import java.util.logging.Level;
019: import java.util.logging.LogRecord;
020: import java.util.logging.Logger;
021:
022: import javax.servlet.*;
023: import javax.servlet.http.*;
024:
025: import com.sun.portal.log.common.PortalLogger;
026: import com.sun.portal.wireless.taglibs.base.*;
027:
028: import com.iplanet.sso.*;
029:
030: /**
031: * <util:forward> tag implementation.
032: *
033: *
034: * @author John Saare
035: * @version 1.0, 04/16/2001
036: */
037: public class ForwardTag extends UrlMaker {
038:
039: private boolean urlAmpEntity = false;
040:
041: private static Logger logger = PortalLogger
042: .getLogger(ForwardTag.class);
043:
044: /**
045: * Called at the beginning of a tag...
046: * Must disable urlAmpEntity for forwards...
047: *
048: * @return what to do next
049: */
050: public int doStartTag() throws JspException {
051: /**
052: * The RequestDispatcher must do a clear() on the current stream, before
053: * doing a forward(). Currently the webserver code gets the
054: * original Response (NsHttpResponse) and calls a clearOutputStream()
055: * on it. This might get fixed when full support for filters is available.
056: * Till then we do the out.clear(). (Infact the code generated with
057: * <jsp:forward/> does this).
058: */
059: try {
060: JspWriter out = pageContext.getOut();
061: out.clear();
062: } catch (Exception e) {
063: if (logger.isLoggable(Level.INFO)) {
064: LogRecord rec = new LogRecord(Level.INFO,
065: "PSMA_CSPWTU0002");
066: rec.setThrown(e);
067: String[] param = { "out.clear()" };
068: rec.setParameters(param);
069: rec.setLoggerName(logger.getName());
070: logger.log(rec);
071: }
072: }
073:
074: int retVal = super .doStartTag();
075: urlAmpEntity = context.getUrlAmpEntity();
076: context.setUrlAmpEntity(false);
077: return retVal;
078: }
079:
080: /**
081: * Forward...
082: *
083: * @return what to do next
084: */
085: public int processForwardRequest() throws JspException {
086: String finalUrl;
087:
088: try {
089: finalUrl = computeUrl(false);
090: context.setUrlAmpEntity(urlAmpEntity);
091: pageContext.forward(finalUrl);
092: } catch (Exception e) {
093: context.setUrlAmpEntity(urlAmpEntity);
094: if (logger.isLoggable(Level.SEVERE)) {
095: LogRecord rec = new LogRecord(Level.SEVERE,
096: "PSMA_CSPWTU0002");
097: rec.setThrown(e);
098: String[] param = { "doAfterBody" };
099: rec.setParameters(param);
100: rec.setLoggerName(logger.getName());
101: logger.log(rec);
102: }
103: throw new JspException(this .getClass().getName()
104: + ".doAfterBody() failed.");
105: }
106:
107: return (SKIP_BODY);
108: }
109:
110: /**
111: * @return SKIP_PAGE
112: * because we dont want to be processing in "this" page after we return from
113: * the forwarded page. We need to do this for the MAPFilter to work, since
114: * the web-server calls a private close() method in its Response object and
115: * the Filters close() never gets called.
116: */
117: public int doEndTag() throws JspException {
118: processForwardRequest();
119: return (SKIP_PAGE);
120: }
121:
122: }
|