1 package org.apache.jetspeed.services.jsp.tags;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import javax.servlet.jsp.JspException;
20 import javax.servlet.jsp.PageContext;
21 import javax.servlet.jsp.tagext.TagSupport;
22
23
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
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
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 template;
51
52 /***
53 * The setter for template parameter
54 */
55 public void setTemplate(String template)
56 {
57 this.template = template;
58 }
59
60 /***
61 * action parameter defines the action to set
62 * optional parameter
63 */
64 private String action;
65
66 /***
67 * The setter for screen parameter
68 */
69 public void setAction(String action)
70 {
71 this.action = action;
72 }
73
74 public int doStartTag() throws JspException
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 e)
89 {
90 String 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 ioe) {}
97 }
98
99 return EVAL_BODY_INCLUDE;
100 }
101
102 }