View Javadoc

1   package be.dvw.administration.mvc.taglibs;
2   
3   import be.dvw.administration.mvc.navigation.LeftMenu;
4   import be.dvw.administration.mvc.navigation.LeftMenuXSLTImpl;
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   import org.dom4j.DocumentException;
8   import org.dom4j.io.OutputFormat;
9   import org.dom4j.io.XMLWriter;
10  
11  import javax.servlet.jsp.JspException;
12  import javax.servlet.jsp.tagext.BodyTagSupport;
13  import javax.xml.transform.TransformerException;
14  import java.io.IOException;
15  import java.io.UnsupportedEncodingException;
16  
17  /***
18   * Created by IntelliJ IDEA.
19   * User: Toon.Timbermont
20   * Date: Mar 22, 2005
21   * Time: 9:21:24 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  public class LeftMenuTag extends BodyTagSupport {
25  
26  
27      private static Log LOG = LogFactory.getLog(LeftMenuTag.class);
28      private String currentItem;
29  
30      /***
31       * Code executed when this tag is called
32       * @return  SKIP_BODY : this tag does not have a body;
33       * @throws javax.servlet.jsp.JspException
34       */
35      public int doStartTag() throws JspException {
36  
37          LOG.debug("Executing the LeftMenuTag for currentItem " + currentItem);
38          LeftMenu menu;
39          try {
40              menu = new LeftMenuXSLTImpl(currentItem);
41              OutputFormat format = OutputFormat.createPrettyPrint();
42              XMLWriter writer;
43              writer = new XMLWriter( pageContext.getOut() , format );
44              writer.write( menu.getCurrentMenu() );
45          } catch (DocumentException e) {
46              e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
47          } catch (TransformerException e) {
48              e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
49          } catch (UnsupportedEncodingException e) {
50              e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
51          } catch (IOException e) {
52              e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
53          }
54          return SKIP_BODY;
55      }
56  
57      /***
58       * Code executed when the tag reaches its end
59       * @return EVAL_PAGE : the rest of the page must be evaluated as well
60       * @throws JspException
61       */
62      public int doEndTag() throws JspException {
63          return EVAL_PAGE;
64      }
65  
66      /***
67       * Getter for the attribute currentItem
68       * @return
69       */
70      public String getCurrentItem() {
71          LOG.debug("Returning the currentItem " + currentItem);
72          return currentItem;
73      }
74  
75      /***
76       * Setter for the attribute currentItem
77       * @param currentItem
78       */
79      public void setCurrentItem(String currentItem) {
80          LOG.debug("Setting the currentItem to " + currentItem);
81          this.currentItem = currentItem;
82      }
83  
84  }