View Javadoc

1   package org.apache.jetspeed.services.jsp.tags;
2   
3   /*
4    * Copyright 2000-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;
20  import javax.servlet.jsp.PageContext;
21  import javax.servlet.jsp.tagext.TagSupport;
22  
23  // Turbine Classes 
24  import org.apache.turbine.util.RunData;
25  import org.apache.turbine.services.jsp.JspService;
26  
27  // Jetsped Classes 
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              /* HOME */
70              if (type.equalsIgnoreCase( "Home" )) {
71                result = URILookup.getURI(URILookup.TYPE_HOME, URILookup.SUBTYPE_NONE, data);
72              }  
73  
74              /* LOGIN */
75              if (type.equalsIgnoreCase( "Login" )) {
76                result = URILookup.getURI(URILookup.TYPE_LOGIN, URILookup.SUBTYPE_NONE, data);
77              }  
78  
79              /* ENROLLMENT */
80              if (type.equalsIgnoreCase( "Enrollment" )) {
81                result = URILookup.getURI(URILookup.TYPE_ENROLLMENT, URILookup.SUBTYPE_NONE, data);
82              }  
83  
84              /* LOGOUT */
85              if (type.equalsIgnoreCase( "Logout" )) {
86                result = URILookup.getURI(URILookup.TYPE_HOME, URILookup.SUBTYPE_LOGOUT, data);
87              }  
88  
89              /* CUSTOMIZE */
90              if (type.equalsIgnoreCase( "Customize") ) {
91                result = URILookup.getURI(URILookup.TYPE_CUSTOMIZE, URILookup.SUBTYPE_NONE, data);
92              }  
93  
94              /* EDIT ACCOUNT */
95              if (type.equalsIgnoreCase( "EditAccount" )) {
96                result = URILookup.getURI(URILookup.TYPE_EDIT_ACCOUNT, URILookup.SUBTYPE_NONE, data);
97              }  
98  
99              /* APPLICATIONS */
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             /* BASE URL */
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 }