Source code: com/opencms/flex/CmsDumpLoader.java
1 /*
2 * File : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/Attic/CmsDumpLoader.java,v $
3 * Date : $Date: 2003/05/13 13:18:20 $
4 * Version: $Revision: 1.12.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;
33
34 import com.opencms.boot.I_CmsLogChannels;
35 import com.opencms.core.A_OpenCms;
36 import com.opencms.core.CmsException;
37 import com.opencms.file.CmsFile;
38 import com.opencms.file.CmsObject;
39 import com.opencms.file.CmsResource;
40 import com.opencms.flex.cache.CmsFlexCache;
41 import com.opencms.flex.cache.CmsFlexController;
42 import com.opencms.flex.cache.CmsFlexRequest;
43 import com.opencms.flex.cache.CmsFlexResponse;
44
45 import java.io.IOException;
46
47 import javax.servlet.ServletException;
48 import javax.servlet.ServletRequest;
49 import javax.servlet.ServletResponse;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.servlet.http.HttpServletResponse;
52
53
54 /**
55 * Dump loader for binary or other unprocessed resource types.<p>
56 *
57 * This loader is used to deliver static sub-elements of pages processed
58 * by other loaders.
59 *
60 * @author Alexander Kandzior (a.kandzior@alkacon.com)
61 * @version $Revision: 1.12.2.1 $
62 */
63 public class CmsDumpLoader extends com.opencms.launcher.CmsDumpLauncher implements I_CmsResourceLoader {
64
65 /** The CmsFlexCache used to store generated cache entries in */
66 private static CmsFlexCache m_cache;
67
68 /** Flag for debugging output. Set to 9 for maximum verbosity. */
69 private static final int DEBUG = 0;
70
71 /**
72 * The constructor of the class is empty and does nothing.<p>
73 */
74 public CmsDumpLoader() {
75 // NOOP
76 }
77
78 /**
79 * Destroy this ResourceLoder, this is a NOOP so far.<p>
80 */
81 public void destroy() {
82 // NOOP
83 }
84
85 /**
86 * Return a String describing the ResourceLoader,
87 * which is <code>"A simple dump loader that extends from com.opencms.launcher.CmsDumpLauncher"</code><p>
88 *
89 * @return a describing String for the ResourceLoader
90 */
91 public String getResourceLoaderInfo() {
92 return "A simple dump loader that extends from com.opencms.launcher.CmsDumpLauncher";
93 }
94
95 /**
96 * Initialize the ResourceLoader,
97 * not much done here, only the FlexCache is initialized for dump elements.<p>
98 *
99 * @param openCms an OpenCms object to use for initalizing
100 */
101 public void init(A_OpenCms openCms) {
102 m_cache = (CmsFlexCache)A_OpenCms.getRuntimeProperty(C_LOADER_CACHENAME);
103
104 if (I_CmsLogChannels.C_LOGGING && A_OpenCms.isLogging(I_CmsLogChannels.C_FLEX_LOADER))
105 A_OpenCms.log(I_CmsLogChannels.C_FLEX_LOADER, this.getClass().getName() + " initialized!");
106 }
107
108
109 /**
110 * Basic top-page processing method for this I_CmsResourceLoader,
111 * this method is called if the page is called as a sub-element
112 * on a page not already loded with a I_CmsResourceLoader,
113 * which most often would be a I_CmsLauncher then.<p>
114 *
115 * @param cms the initialized CmsObject which provides user permissions
116 * @param file the requested OpenCms VFS resource
117 * @param req the original servlet request
118 * @param res the original servlet response
119 *
120 * @throws ServletException might be thrown in the process of including the JSP
121 * @throws IOException might be thrown in the process of including the JSP
122 *
123 * @see I_CmsResourceLoader
124 * @see com.opencms.launcher.I_CmsLauncher
125 * @see #service(CmsObject, CmsResource, CmsFlexRequest, CmsFlexResponse)
126 */
127 public void load(CmsObject cms, CmsFile file, HttpServletRequest req, HttpServletResponse res)
128 throws ServletException, IOException {
129 CmsFlexController controller = new CmsFlexController(cms, file, m_cache, req, res);
130 req.setAttribute(CmsFlexController.ATTRIBUTE_NAME, controller);
131 CmsFlexRequest f_req = new CmsFlexRequest(req, controller);
132 CmsFlexResponse f_res = new CmsFlexResponse(res, controller, false, false);
133 controller.pushRequest(f_req);
134 controller.pushResponse(f_res);
135 service(cms, file, f_req, f_res);
136 }
137
138 /**
139 * Does the job of dumping the contents of the requested file to the
140 * output stream, this method is called directly if the element is
141 * called as a sub-element from another I_CmsResourceLoader.<p>
142 *
143 * @param cms used to access the OpenCms VFS
144 * @param file the reqested JSP file resource in the VFS
145 * @param req the current request
146 * @param res the current response
147 *
148 * @throws ServletException might be thrown in the process of including the JSP
149 * @throws IOException might be thrown in the process of including the JSP
150 *
151 * @see com.opencms.flex.cache.CmsFlexRequestDispatcher
152 */
153 public void service(CmsObject cms, CmsResource file, ServletRequest req, ServletResponse res)
154 throws ServletException, IOException {
155 long timer1 = 0;
156 if (DEBUG > 0) {
157 timer1 = System.currentTimeMillis();
158 System.err.println("========== DumpLoader loading: " + file.getAbsolutePath());
159 }
160 try {
161 res.getOutputStream().write(cms.readFile(file.getAbsolutePath()).getContents());
162 } catch (CmsException e) {
163 System.err.println("Error in CmsDumpLoader: " + e.toString());
164 if (DEBUG > 0) System.err.println(com.opencms.util.Utils.getStackTrace(e));
165 throw new ServletException("Error in CmsDumpLoader processing", e);
166 }
167 if (DEBUG > 0) {
168 long timer2 = System.currentTimeMillis() - timer1;
169 System.err.println("========== Time delivering dump for " + file.getAbsolutePath() + ": " + timer2 + "ms");
170 }
171 }
172 }