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.ContentURI;
25  import org.apache.turbine.util.RunData;
26  import org.apache.turbine.services.jsp.JspService;
27  
28  // Jetspeed classes
29  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
30  import org.apache.jetspeed.services.logging.JetspeedLogger;
31  
32  /***
33   * Supporting class for the contentURI tag.
34   * Returns the URL for the given webapp relative URI
35   *
36   * @author <a href="mailto:raphael@apache.org">Raphaël Luta</a>
37   * @version $Id: ContentURITag.java,v 1.7 2004/02/23 03:59:40 jford Exp $
38   */
39  public class ContentURITag extends TagSupport 
40  {
41      /***
42       * Static initialization of the logger for this class
43       */    
44      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ContentURITag.class.getName());
45      
46      /***
47       * type parameter defines type of URI that is requested
48       */
49      private String href;
50  
51      /*** 
52       * The setter for type parameter
53       */
54      public void setHref(String href)
55      {
56          this.href = href;
57      }
58  
59      public int doStartTag() throws JspException 
60      {
61          RunData data = (RunData)pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);    
62          
63          String result = new ContentURI(data).getURI(this.href);
64  
65          try
66          {
67              if (result != null) {
68                  pageContext.getOut().print(result);
69              }
70          }
71          catch (Exception e)
72          {
73              String message = "Error processing contentUri-tag, parameter: "+ href;
74              logger.error(message, e);
75              try
76              {
77                  data.getOut().print( message );
78              }
79              catch(java.io.IOException ioe) {}    
80          }
81         
82          return EVAL_BODY_INCLUDE;
83      }
84  
85  }