View Javadoc

1   /*
2    * $Id: LinkTag.java 130 2004-11-28 13:00:44Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.taglib.util;
24  
25  import javax.servlet.jsp.tagext.TagSupport;
26  import javax.servlet.jsp.JspWriter;
27  import javax.servlet.http.HttpServletRequest;
28  import java.io.IOException;
29  
30  import org.talika.tarsis.Globals;
31  
32  /**
33   * Implementation of <util:link> tag.
34   *
35   * @author  Jose M. Palomar
36   * @version $Revision: 130 $
37   */
38  public class LinkTag extends TagSupport {
39  
40      // Fields
41      /**
42       * <code>command</code> attribute.
43       */
44      private String command;
45  
46      // Methods
47      /**
48       * Process the start tag for this instance.
49       *
50       * @return int SKIP_BODY.
51       * @see javax.servlet.jsp.tagext.Tag#doStartTag()
52       */
53      public int doStartTag() {
54  
55          try {
56  
57              JspWriter out = pageContext.getOut();
58              HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
59  
60              out.print(request.getContextPath());
61              out.print(Globals.CONTROLLER_SERVLET);
62              if (!command.startsWith("/")) {
63                  out.print("/");
64              }
65              out.print(command);
66  
67          }
68          catch (IOException ioe) {
69              // Bad luck
70          }
71  
72          return SKIP_BODY;
73  
74      }
75  
76      /**
77       * Sets <code>command</code> attribute value.
78       *
79       * @param command String <code>command</code> attribute value.
80       */
81      public void setCommand(String command) {
82          this.command = command;
83      }
84  
85      /**
86       * Called on a Tag handler to release state.
87       *
88       * @see javax.servlet.jsp.tagext.Tag#release()
89       */
90      public void release() {
91  
92          super.release();
93  
94          this.command = null;
95  
96      }
97  
98  }