KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.apache.jetspeed.services.jsp.tags;
2
3 /*
4  * Copyright 2000-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 javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.PageContext JavaDoc;
21 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
22
23 // Turbine Classes
24
import org.apache.turbine.util.RunData;
25 import org.apache.turbine.util.DynamicURI;
26 import org.apache.turbine.util.template.TemplateLink;
27 import org.apache.turbine.services.jsp.JspService;
28
29 // Jetspeed classes
30
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
31 import org.apache.jetspeed.services.logging.JetspeedLogger;
32
33 /**
34  * Supporting class for the TemplateLink tag.
35  * Uses the TemplateLink class to construct a URI
36  *
37  * @author <a HREF="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>
38  */

39 public class TemplateLinkTag extends TagSupport JavaDoc
40 {
41     /**
42      * Static initialization of the logger for this class
43      */

44     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(TemplateLinkTag.class.getName());
45     
46     /**
47      * template parameter defines the template to set
48      * mandatory parameter
49      */

50     private String JavaDoc template;
51
52     /**
53      * The setter for template parameter
54      */

55     public void setTemplate(String JavaDoc template)
56     {
57         this.template = template;
58     }
59
60     /**
61      * action parameter defines the action to set
62      * optional parameter
63      */

64     private String JavaDoc action;
65
66     /**
67      * The setter for screen parameter
68      */

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