001: /**
002: * $Id: EditTag.java,v 1.7 2005/09/21 10:53:16 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 java.util.*;
016: import java.util.logging.Level;
017: import java.util.logging.LogRecord;
018: import java.util.logging.Logger;
019:
020: import javax.servlet.jsp.*;
021: import javax.servlet.jsp.tagext.*;
022:
023: import com.sun.portal.log.common.PortalLogger;
024: import com.sun.portal.wireless.taglibs.base.*;
025:
026: public class EditTag extends BaseBodyTagSupport implements BeanHolder {
027:
028: private Edit edit;
029: private static Logger logger = PortalLogger
030: .getLogger(EditTag.class);
031:
032: /**
033: * Get the edit bean
034: *
035: * @return the collection tag bean
036: */
037: public Object getBean() {
038: return edit;
039: }
040:
041: /**
042: * Called at the beginning of a tag...
043: *
044: * @return what to do next
045: */
046: public int doStartTag() throws JspTagException {
047:
048: if (id != null) {
049: try {
050: UtilContext context = UtilContext
051: .getContext(pageContext);
052: edit = new Edit(context.getEscapeClassName());
053: pageContext.setAttribute(id, edit);
054: } catch (Exception e) {
055: logger.log(Level.SEVERE, "PSMA_CSPWTU0007", e);
056: throw new JspTagException(this .getClass().getName()
057: + ".doStartTag(): could not get context.");
058: }
059: } else if (name != null) {
060: edit = (Edit) pageContext.getAttribute(name);
061: if (edit == null) {
062: logger.log(Level.WARNING, "PSMA_CSPWTU0010", name);
063: throw new JspTagException(this .getClass().getName()
064: + ".doStartTag(): edit bean," + name
065: + ", does not exist.");
066: }
067: } else {
068: logger.warning("PSMA_CSPWTU0011");
069: throw new JspTagException(this .getClass().getName()
070: + ".doStartTag(): id or name must be specified.");
071: }
072: return (EVAL_BODY_TAG);
073: }
074:
075: /**
076: * Performs certain edits upon the BODY.
077: *
078: * Perform substitution if specified...
079: * THEN
080: * Perform truncation if specified...
081: * THEN...
082: * Perform XML-style char entity escaping, if specified.
083: *
084: * @return what to do next
085: */
086: public int doAfterBody() throws JspException {
087: BodyContent body = getBodyContent();
088: try {
089: String bodyString = body.getString();
090: int length = 0;
091: if (bodyString != null) {
092: length = bodyString.length();
093: }
094: if (length > 0) {
095: JspWriter out = body.getEnclosingWriter();
096: out.print(edit.editString(bodyString));
097: }
098: body.clearBody();
099: } catch (Exception e) {
100: if (logger.isLoggable(Level.SEVERE)) {
101: LogRecord rec = new LogRecord(Level.SEVERE,
102: "PSMA_CSPWTU0002");
103: rec.setThrown(e);
104: String[] param = { "doAfterBody" };
105: rec.setParameters(param);
106: rec.setLoggerName(logger.getName());
107: logger.log(rec);
108: }
109:
110: throw new JspException(this .getClass().getName()
111: + ".doAfterBody() failed.");
112: }
113: return (SKIP_BODY);
114: }
115:
116: /**
117: * Cleanup
118: */
119: public void release() {
120: super.release();
121: edit = null;
122: }
123: }
|