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