001: /**
002: * $Id: LinkTag.java,v 1.7 2005/09/21 10:53:26 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: /**
029: * <util:link> tag implementation.
030: *
031: *
032: * @author John Saare
033: * @version 1.0, 03/08/2001
034: */
035: public class LinkTag extends BaseBodyTagSupport {
036:
037: private String tagStart = null;
038: private String tagEnd = null;
039:
040: private static Logger logger = PortalLogger
041: .getLogger(LinkTag.class);
042:
043: /**
044: * Called at the beginning of a tag...
045: *
046: * @return what to do next
047: */
048: public int doStartTag() throws JspTagException {
049: return (EVAL_BODY_TAG);
050: }
051:
052: /**
053: * Called after the tag body has been processed...
054: *
055: * @return what to do next
056: */
057: public int doAfterBody() throws JspException {
058: BodyContent body = getBodyContent();
059: try {
060: JspWriter out = body.getEnclosingWriter();
061: out.print(tagStart);
062: //out.print(stripLineBreak(body.getString()));
063: out.print(body.getString());
064: out.print(tagEnd);
065: body.clearBody();
066: } catch (Exception e) {
067: if (logger.isLoggable(Level.SEVERE)) {
068: LogRecord rec = new LogRecord(Level.SEVERE,
069: "PSMA_CSPWTU0002");
070: rec.setThrown(e);
071: String[] param = { "doAfterBody" };
072: rec.setParameters(param);
073: rec.setLoggerName(logger.getName());
074: logger.log(rec);
075: }
076:
077: throw new JspException(this .getClass().getName()
078: + ".doAfterBody() failed.");
079: }
080: return (SKIP_BODY);
081: }
082:
083: /**
084: * Called upon completion of usage of this class instance...
085: *
086: */
087: public void release() {
088: super .release();
089: tagStart = null;
090: tagEnd = null;
091: }
092:
093: /**
094: * "tagstart" attribute set method...
095: *
096: * @param s attribute value.
097: */
098: public void settagstart(String s) {
099: tagStart = Util.evalAttribute(pageContext, s);
100: }
101:
102: /**
103: * "tagend" attribute set method...
104: *
105: * @param s attribute value.
106: */
107: public void settagend(String s) {
108: tagEnd = Util.evalAttribute(pageContext, s);
109: }
110:
111: private String stripLineBreak(String s) {
112: char[] srcArray = s.toCharArray();
113: int srcLen = s.length();
114: char[] dstArray = new char[srcLen];
115: int srcIndex, dstIndex;
116:
117: for (srcIndex = 0, dstIndex = 0; srcIndex < srcLen; srcIndex++) {
118: char c = srcArray[srcIndex];
119: if (c != 10 && c != 13) {
120: dstArray[dstIndex++] = c;
121: }
122: }
123:
124: if (dstIndex == 0) {
125: return new String();
126: }
127:
128: return new String(dstArray, 0, dstIndex);
129: }
130:
131: }
|