01: /*
02: *
03: * $Id: MsgFragmentTag.java,v 1.5 2005/09/21 10:53:35 dg154973 Exp $
04: * Copyright 2005 Sun Microsystems, Inc. All
05: * rights reserved. Use of this product is subject
06: * to license terms. Federal Acquisitions:
07: * Commercial Software -- Government Users
08: * Subject to Standard License Terms and
09: * Conditions.
10: *
11: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
12: * are trademarks or registered trademarks of Sun Microsystems,
13: * Inc. in the United States and other countries.
14: * MsgFragmentTag.java
15: *
16: * Created on February 25, 2005, 10:11 AM
17: */
18:
19: package com.sun.portal.wireless.taglibs.util;
20:
21: import java.io.IOException;
22: import javax.servlet.jsp.JspException;
23: import javax.servlet.jsp.JspWriter;
24: import javax.servlet.jsp.tagext.BodyContent;
25: import javax.servlet.jsp.tagext.BodyTagSupport;
26:
27: import java.util.logging.Level;
28: import java.util.logging.Logger;
29:
30: import com.sun.portal.log.common.PortalLogger;
31:
32: /**
33: * MessageFormatTag marks the messagetag for formatting
34: * It should have a unique id. The id will be used as
35: * place holder in MsgFormatTag class for formatting the
36: * message
37: * @author senthils
38: */
39: public class MsgFragmentTag extends BodyTagSupport {
40:
41: private static Logger logger = PortalLogger
42: .getLogger(MsgFragmentTag.class);
43:
44: /**
45: * Initialization of id property.
46: */
47: private java.lang.String id;
48: private MsgFmtTag f = null;
49:
50: /** Creates a new instance of MsgFragmentTag */
51: public MsgFragmentTag() {
52: super ();
53: }
54:
55: public int doStartTag() throws JspException {
56: f = (MsgFmtTag) findAncestorWithClass(this , MsgFmtTag.class);
57: return EVAL_BODY_BUFFERED;
58: }
59:
60: public int doEndTag() throws JspException {
61: f = null;
62: return EVAL_PAGE;
63: }
64:
65: public int doAfterBody() throws JspException {
66: try {
67: BodyContent bodyContent = getBodyContent();
68: JspWriter out = bodyContent.getEnclosingWriter();
69: writeTagBodyContent(out, bodyContent);
70: } catch (Exception ex) {
71: handleBodyContentException(ex);
72: }
73: return SKIP_BODY;
74: }
75:
76: /**
77: * Handles exception from processing the body content.
78: */
79: private void handleBodyContentException(Exception ex)
80: throws JspException {
81: // Since the doAfterBody method is guarded, place exception handing code here.
82: throw new JspException("error in tag MsgFragment: " + ex);
83: }
84:
85: private void writeTagBodyContent(JspWriter out,
86: BodyContent bodyContent) throws IOException {
87: String bodyStr = bodyContent.getString();
88: f.addFragment(id, bodyStr);
89: bodyContent.clearBody();
90: }
91:
92: public void setId(java.lang.String value) {
93: this.id = value;
94: }
95: }
|