Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/opencms/flex/jsp/CmsJspTagLink.java


1   /*
2    * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/jsp/Attic/CmsJspTagLink.java,v $
3    * Date   : $Date: 2003/05/13 13:18:20 $
4    * Version: $Revision: 1.10.2.1 $
5    *
6    * This library is part of OpenCms -
7    * the Open Source Content Mananagement System
8    *
9    * Copyright (C) 2002 - 2003 Alkacon Software (http://www.alkacon.com)
10   *
11   * This library is free software; you can redistribute it and/or
12   * modify it under the terms of the GNU Lesser General Public
13   * License as published by the Free Software Foundation; either
14   * version 2.1 of the License, or (at your option) any later version.
15   *
16   * This library is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19   * Lesser General Public License for more details.
20   *
21   * For further information about Alkacon Software, please see the
22   * company website: http://www.alkacon.com
23   *
24   * For further information about OpenCms, please see the
25   * project website: http://www.opencms.org
26   * 
27   * You should have received a copy of the GNU Lesser General Public
28   * License along with this library; if not, write to the Free Software
29   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30   */
31  
32  package com.opencms.flex.jsp;
33  
34  import com.opencms.flex.cache.CmsFlexController;
35  import com.opencms.util.LinkSubstitution;
36  
37  import javax.servlet.ServletRequest;
38  import javax.servlet.jsp.JspException;
39  
40  /**
41   * Implements the <code>&lt;cms:link&gt;[filename]&lt;/cms:link&gt;</code> 
42   * tag to add OpenCms managed links to a JSP page, required for link
43   * management and the static 
44   * export to work properly.<p>
45   *
46   * @author  Alexander Kandzior (a.kandzior@alkacon.com)
47   * @version $Revision: 1.10.2.1 $
48   */
49  public class CmsJspTagLink extends javax.servlet.jsp.tagext.BodyTagSupport {
50   
51      /**
52       * @see javax.servlet.jsp.tagext.Tag#doEndTag()
53       * @return EVAL_PAGE
54       */
55      public int doEndTag() throws JspException {
56          
57          ServletRequest req = pageContext.getRequest();
58          
59          // This will always be true if the page is called through OpenCms 
60          if (CmsFlexController.isCmsRequest(req)) {
61              try {
62                  // Get link-string from the body and reset body 
63                  String link = this.getBodyContent().getString();                          
64                  this.getBodyContent().clear();            
65                  // Calculate the link substitution
66                  String newlink = linkTagAction(link, req);
67                  // Write the result back to the page                
68                  this.getBodyContent().print(newlink);
69                  this.getBodyContent().writeOut(pageContext.getOut());
70  
71              } catch (Exception ex) {
72                  System.err.println("Error in Jsp 'link' tag processing: " + ex);
73                  System.err.println(com.opencms.util.Utils.getStackTrace(ex));
74                  throw new JspException(ex);
75              }            
76          }
77          return EVAL_PAGE;        
78      }
79      
80      /**
81       * Internal action method.<p>
82       * 
83       * Calulates a link using the OpenCms link export rules.<p>
84       * 
85       * @param link the link that should be calculated, can be relative or absolute
86       * @param req the current request
87       * @return the calculated link
88       * 
89       * @see com.opencms.util.LinkSubstitution#getLinkSubstitution(CmsObject, String)
90       */
91      public static String linkTagAction(String link, ServletRequest req) {
92          CmsFlexController controller = (CmsFlexController)req.getAttribute(CmsFlexController.ATTRIBUTE_NAME);
93          if (link.indexOf(':') >= 0) {
94              return LinkSubstitution.getLinkSubstitution(controller.getCmsObject(), link);
95          } else {
96              return LinkSubstitution.getLinkSubstitution(controller.getCmsObject(), controller.getCurrentRequest().toAbsolute(link));
97          }        
98      }
99  }