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

Quick Search    Search Deep

Source code: com/opencms/launcher/CmsLinkLauncher.java


1   /*
2   * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/launcher/Attic/CmsLinkLauncher.java,v $
3   * Date   : $Date: 2003/01/20 23:59:23 $
4   * Version: $Revision: 1.16 $
5   *
6   * This library is part of OpenCms -
7   * the Open Source Content Mananagement System
8   *
9   * Copyright (C) 2001  The OpenCms Group
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 OpenCms, please see the
22  * OpenCms Website: http://www.opencms.org
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27  */
28  
29  package com.opencms.launcher;
30  
31  import com.opencms.core.A_OpenCms;
32  import com.opencms.core.CmsException;
33  import com.opencms.core.I_CmsConstants;
34  import com.opencms.file.CmsFile;
35  import com.opencms.file.CmsObject;
36  
37  import java.io.IOException;
38  import java.io.OutputStream;
39  
40  import javax.servlet.http.HttpServletResponse;
41  
42  /**
43   * OpenCms launcher class for starting template classes implementing
44   * the I_CmsDumpTemplate interface.
45   * This can be used for plain text files or files containing graphics.
46   * <P>
47   * If no other start template class is given, CmsDumpTemplate will
48   * be used to create output.
49   *
50   * @author Michael Emmerich
51   * @version $Revision: 1.16 $ $Date: 2003/01/20 23:59:23 $
52   */
53  public class CmsLinkLauncher extends A_CmsLauncher {
54  
55      /**
56       * The currently running OpenCms instance.
57       */
58      private A_OpenCms m_openCms;
59  
60      /**
61       * The html-code for returning the export file for external links
62       */
63      private static String C_EXPORTED_LINKHTML_01 = "<html><head><meta http-equiv="+'"'+"refresh"+'"'+" content="+'"'+"0; url=";
64      private static String C_EXPORTED_LINKHTML_02 = '"'+"></head><body></body></html>";
65  
66      /**
67       * Gets the ID that indicates the type of the launcher.
68       * @return launcher ID
69       */
70      public int getLauncherId() {
71          return C_TYPE_LINK;
72      }
73  
74      /**
75       * Unitary method to start generating the output.
76       * Every launcher has to implement this method.
77       * In it possibly the selected file will be analyzed, and the
78       * Canonical Root will be called with the appropriate
79       * template class, template file and parameters. At least the
80       * canonical root's output must be written to the HttpServletResponse.
81       *
82       * @param cms CmsObject Object for accessing system resources
83       * @param file CmsFile Object with the selected resource to be shown
84       * @param startTemplateClass Name of the template class to start with.
85       * @param openCms a instance of A_OpenCms for redirect-needs
86       * @throws CmsException
87       */
88      protected void launch(CmsObject cms, CmsFile file,
89                            String startTemplateClass,
90                            A_OpenCms openCms) throws CmsException {
91  
92          // get the current running OpenCms instance.
93          if(openCms == null) {
94              openCms = m_openCms;
95          }
96          String link = new String(file.getContents());
97          if(link == null || "".equals(link) || " ".equals(link)){
98              throw new CmsException(CmsException.C_NOT_FOUND);
99          }
100         if( link.startsWith("/") ) {
101             // internal link ...
102             CmsFile linkFile = cms.readFile(link);
103             openCms.showResource(cms, linkFile);
104         } else {
105             // redirect to external link ...
106             if (cms.getMode() != I_CmsConstants.C_MODUS_EXPORT){
107                 HttpServletResponse response =
108                     (HttpServletResponse)
109                         cms.getRequestContext().getResponse().getOriginalResponse();
110                 try {
111                     response.sendRedirect(link);
112                 } catch (IOException e) {
113                 }
114             } else {
115                 try{
116                     OutputStream responsestream = cms.getRequestContext().getResponse().getOutputStream();
117                     StringBuffer htmlStream = new StringBuffer(C_EXPORTED_LINKHTML_01);
118                     htmlStream.append(link);
119                     htmlStream.append(C_EXPORTED_LINKHTML_02);
120                     responsestream.write(htmlStream.toString().getBytes());
121                     responsestream.close();
122                 } catch (IOException e){
123                 }
124             }
125         }
126     }
127 
128     /**
129      * Sets the currently running OpenCms instance.
130      */
131     public void setOpenCms(A_OpenCms openCms) {
132         m_openCms = openCms;
133     }
134 }