001: /**
002: * $Id: UrlTag.java,v 1.18 2005/09/21 10:53:45 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.iplanet.sso.*;
026: import com.iplanet.services.cdm.*;
027:
028: import com.sun.portal.log.common.PortalLogger;
029: import com.sun.portal.wireless.taglibs.base.*;
030: import com.sun.portal.wireless.taglibs.dispatcher.*;
031:
032: /**
033: * <util:url> tag implementation.
034: *
035: *
036: * @author John Saare
037: * @version 1.0, 03/08/2001
038: */
039: public class UrlTag extends UrlMaker {
040:
041: private static Logger logger = PortalLogger.getLogger(UrlTag.class);
042:
043: /**
044: * Called after the tag body has been processed...
045: *
046: * @return what to do next
047: */
048: public int doEndTag() throws JspException {
049: String finalUrl;
050:
051: try {
052: Compressor compressor = context.getCompressor();
053:
054: if (!deferLookup) {
055: if (path == null) {
056: finalUrl = computeUrl(true);
057: if ((compress) && (compressor != null)) {
058: finalUrl = compressor.compressURL(finalUrl);
059: }
060: } else {
061: finalUrl = computeUrl(false);
062: }
063: } else {
064: finalUrl = "/" + Compressor.getDispatcherServletName()
065: + "?comp=" + compName;
066: finalUrl += (context.getUrlAmpEntity()) ? "&" : "&";
067: finalUrl += "file=" + fileName;
068: }
069:
070: // Deal with dynamic parms?
071: if (path == null && dynamicParms != null) {
072:
073: // If static parms are present or compression has happened,
074: // i.e., a query string has begun...
075: if (staticParms != null
076: || (compress && (compressor != null) && compressor
077: .isCompressionEnabled())) {
078:
079: // Append dynamic parms with a '&'...
080: if (context.getUrlAmpEntity()) {
081: finalUrl = finalUrl + "&" + dynamicParms;
082: } else {
083: finalUrl = finalUrl + "&" + dynamicParms;
084: }
085:
086: // Else, there are no static parms and compression has not happened,
087: // i.e., a query string has not yet begun...
088: } else {
089:
090: // Append dynamic parms with a '?'...
091: finalUrl = finalUrl + "?" + dynamicParms;
092: }
093: }
094:
095: if (path == null) {
096: finalUrl = ((HttpServletRequest) pageContext
097: .getRequest()).getContextPath()
098: + finalUrl;
099: }
100:
101: SSOToken session = context.getSession();
102: if (includeSid && session != null) {
103: finalUrl = session.encodeURL(finalUrl);
104: }
105: } catch (Exception e) {
106: if (logger.isLoggable(Level.SEVERE)) {
107: LogRecord rec = new LogRecord(Level.SEVERE,
108: "PSMA_CSPWTU0002");
109: rec.setThrown(e);
110: String[] param = { "doAfterBody" };
111: rec.setParameters(param);
112: rec.setLoggerName(logger.getName());
113: logger.log(rec);
114: }
115:
116: throw new JspException(this .getClass().getName()
117: + ".doAfterBody() failed.");
118: }
119:
120: try {
121: JspWriter out = pageContext.getOut();
122: out.print(finalUrl);
123: } catch (Exception e) {
124: if (logger.isLoggable(Level.SEVERE)) {
125: LogRecord rec = new LogRecord(Level.SEVERE,
126: "PSMA_CSPWTU0002");
127: rec.setThrown(e);
128: String[] param = { "out.print()" };
129: rec.setParameters(param);
130: rec.setLoggerName(logger.getName());
131: logger.log(rec);
132: }
133:
134: throw new JspException(this .getClass().getName()
135: + ".doAfterBody() failed. out.print() failed.");
136: }
137:
138: return EVAL_PAGE;
139: }
140:
141: }
|