1 package com.instantbank.collections.main.web; 2 3 import java.io.IOException; 4 import javax.servlet.jsp.JspException; 5 import javax.servlet.jsp.tagext.TagSupport; 6 import org.w3c.dom.Node; 7 8 public class ValueOfElementTag extends TagSupport { 9 private Node element = null; 10 11 12 public void setElement(Node element) { 13 this.element = element; 14 } 15 16 17 public int doStartTag() throws JspException { 18 String value; 19 20 if(element.getNodeType() == Node.ELEMENT_NODE) { 21 value = getElementText(element); 22 } 23 else { 24 value = ""; 25 } 26 try { 27 pageContext.getOut().print(value); 28 } 29 catch(IOException e) { 30 throw new JspException(e.getMessage()); 31 } 32 return SKIP_BODY; 33 } 34 35 36 public void release() { 37 element = null; 38 } 39 40 41 public String getElementText(Node element) { 42 Node child = element.getFirstChild(); 43 String text = null; 44 45 if(child != null) { 46 text = child.getNodeValue(); 47 } 48 49 return text; 50 } 51 } 52