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.services.jsp.JspService;
26
27
28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
29 import org.apache.jetspeed.services.logging.JetspeedLogger;
30 import org.apache.jetspeed.util.URILookup;
31 import org.apache.jetspeed.om.registry.PortletEntry;
32 import org.apache.jetspeed.services.Registry;
33 import org.apache.jetspeed.portal.PortletURIManager;
34
35 /***
36 * Supporting class for the uriLookup tag.
37 * Returns the URL for the respective link
38 *
39 * @author <a href="mailto:ingo@raleigh.ibm.com">Ingo Schuster</a>
40 */
41 public class URILookupTag extends TagSupport
42 {
43 /***
44 * Static initialization of the logger for this class
45 */
46 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(URILookupTag.class.getName());
47
48 /***
49 * type parameter defines type of URI that is requested
50 */
51 private String type;
52
53 /***
54 * The setter for type parameter
55 */
56 public void setType(String type)
57 {
58 this.type = type;
59 }
60
61 public int doStartTag() throws JspException
62 {
63 RunData data = (RunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
64
65 try
66 {
67 String result = null;
68
69
70 if (type.equalsIgnoreCase( "Home" )) {
71 result = URILookup.getURI(URILookup.TYPE_HOME, URILookup.SUBTYPE_NONE, data);
72 }
73
74
75 if (type.equalsIgnoreCase( "Login" )) {
76 result = URILookup.getURI(URILookup.TYPE_LOGIN, URILookup.SUBTYPE_NONE, data);
77 }
78
79
80 if (type.equalsIgnoreCase( "Enrollment" )) {
81 result = URILookup.getURI(URILookup.TYPE_ENROLLMENT, URILookup.SUBTYPE_NONE, data);
82 }
83
84
85 if (type.equalsIgnoreCase( "Logout" )) {
86 result = URILookup.getURI(URILookup.TYPE_HOME, URILookup.SUBTYPE_LOGOUT, data);
87 }
88
89
90 if (type.equalsIgnoreCase( "Customize") ) {
91 result = URILookup.getURI(URILookup.TYPE_CUSTOMIZE, URILookup.SUBTYPE_NONE, data);
92 }
93
94
95 if (type.equalsIgnoreCase( "EditAccount" )) {
96 result = URILookup.getURI(URILookup.TYPE_EDIT_ACCOUNT, URILookup.SUBTYPE_NONE, data);
97 }
98
99
100 if (type.equalsIgnoreCase( "Applications" )) {
101 PortletEntry entry = null;
102 entry = (PortletEntry)Registry.getEntry( Registry.PORTLET, "Applications" );
103 result = PortletURIManager.getPortletMaxURI( entry, data ).toString();
104 }
105
106
107 if (type.equalsIgnoreCase( "BaseURL" )) {
108 result = URILookup.getWebAppBaseDirURI( data );
109 }
110
111 if (result != null) {
112 pageContext.getOut().print(result);
113 } else {
114 throw new Exception( "jetspeed-URILookup tag: Unknown parameter!");
115 }
116 }
117 catch (Exception e)
118 {
119 String message = "Error processing uriLookup-tag, parameter: "+ type;
120 logger.error(message, e);
121 try
122 {
123 data.getOut().print( "Error processing uriLookup-tag, parameter: "+ type);
124 }
125 catch(java.io.IOException ioe) {}
126 }
127 return EVAL_BODY_INCLUDE;
128 }
129
130 }