KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > jsp > tags > TemplateLinkTag


1 package org.apache.turbine.services.jsp.tags;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.IOException JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.PageContext JavaDoc;
22 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
23 import org.apache.turbine.services.jsp.JspService;
24 import org.apache.turbine.util.DynamicURI;
25 import org.apache.turbine.util.Log;
26 import org.apache.turbine.util.RunData;
27 import org.apache.turbine.util.template.TemplateLink;
28
29 /**
30  * Supporting class for the TemplateLink tag.
31  * Uses the TemplateLink class to construct a URI
32  *
33  * @author <a HREF="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>
34  * @version $Id: TemplateLinkTag.java,v 1.1.2.2 2004/05/20 03:03:07 seade Exp $
35  */

36 public class TemplateLinkTag extends TagSupport JavaDoc
37 {
38      /**
39       * template parameter defines the template to set
40       * mandatory parameter
41       */

42      private String JavaDoc template;
43
44      /**
45       * The setter for template parameter
46       */

47      public void setTemplate(String JavaDoc template)
48      {
49          this.template = template;
50      }
51
52      /**
53       * action parameter defines the action to set
54       * optional parameter
55       */

56      private String JavaDoc action;
57
58      /**
59       * The setter for screen parameter
60       */

61      public void setAction(String JavaDoc action)
62      {
63          this.action = action;
64      }
65
66      public int doStartTag() throws JspException JavaDoc
67      {
68          RunData data =
69              (RunData)pageContext.getAttribute(JspService.RUNDATA,
70                                                PageContext.REQUEST_SCOPE);
71
72          TemplateLink link = new TemplateLink( data );
73          DynamicURI uri = link.setPage( template );
74          if ( action != null ) uri = uri.setAction( action );
75
76          try
77          {
78              if (uri != null) {
79                  pageContext.getOut().print(uri.toString());
80              }
81          }
82          catch (Exception JavaDoc e)
83          {
84              String JavaDoc message =
85                  "Error processing TemplateLink-tag, parameter: template='"
86                  + template + "', action='" +action +"'";
87              Log.error(message, e);
88              try
89              {
90                  data.getOut().print( message );
91              }
92              catch(java.io.IOException JavaDoc ioe) {}
93          }
94
95          return EVAL_BODY_INCLUDE;
96      }
97
98 }
99
100
Popular Tags