001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.loader; 029 030import org.opencms.configuration.I_CmsConfigurationParameterHandler; 031import org.opencms.file.CmsObject; 032import org.opencms.file.CmsResource; 033import org.opencms.main.CmsException; 034 035import java.io.IOException; 036import java.util.Locale; 037 038import javax.servlet.ServletException; 039import javax.servlet.ServletRequest; 040import javax.servlet.ServletResponse; 041import javax.servlet.http.HttpServletRequest; 042import javax.servlet.http.HttpServletResponse; 043 044/** 045 * This interface describes a resource loader for OpenCms, 046 * a class that can load a resource from the VFS, 047 * process it's contents and deliver the result to the user.<p> 048 * 049 * The I_CmsResourceLoader operates with Request and Response in 050 * much the same way as a standard Java web application.<p> 051 * 052 * This interface uses a standard servlet 053 * {@link javax.servlet.http.HttpServletRequestWrapper} / {@link javax.servlet.http.HttpServletResponseWrapper} 054 * that provide access to a special implementation of the {@link javax.servlet.RequestDispatcher}. 055 * The handling of the output written to the response is done by this 056 * dispatcher. The results are then passed back to OpenCms which 057 * will deliver them to the requesting user.<p> 058 * 059 * @since 6.0.0 060 * 061 * @see org.opencms.flex.CmsFlexRequest 062 * @see org.opencms.flex.CmsFlexResponse 063 * @see org.opencms.flex.CmsFlexRequestDispatcher 064 */ 065public interface I_CmsResourceLoader extends I_CmsConfigurationParameterHandler { 066 067 /** Request parameter to force element selection. */ 068 String PARAMETER_ELEMENT = "__element"; 069 070 /** 071 * Destroys this ResourceLoder.<p> 072 */ 073 void destroy(); 074 075 /** 076 * Dumps the processed content of the the requested file (and it's sub-elements) to a byte array.<p> 077 * 078 * Dumping the content is like calling "load" where the result is 079 * not written to the response stream, but to the returned byte array. 080 * Dumping is different from an export because the export might actually require 081 * that the content is handled or modified in a special way, or set special http headers.<p> 082 * 083 * Moreover, if the page type is template based, calling "dump" will not trigger the 084 * template but directly deliver the contents from the selected element.<p> 085 * 086 * @param cms used to access the OpenCms VFS 087 * @param resource the requested resource in the VFS 088 * @param element the element in the file to display 089 * @param locale the locale to display 090 * @param req the servlet request 091 * @param res the servlet response 092 * 093 * @return the content of the processed file 094 * 095 * @throws ServletException might be thrown by the servlet environment 096 * @throws IOException might be thrown by the servlet environment 097 * @throws CmsException in case of errors accessing OpenCms functions 098 */ 099 byte[] dump( 100 CmsObject cms, 101 CmsResource resource, 102 String element, 103 Locale locale, 104 HttpServletRequest req, 105 HttpServletResponse res) throws ServletException, IOException, CmsException; 106 107 /** 108 * Static exports the contents of the requested file and it's sub-elements.<p> 109 * 110 * During static export, the resource content may be written to 2 streams: 111 * The export stream, and the http response output stream. 112 * Which stream is actually used depends whether the export is in "on demand" 113 * or "after publish" mode. In "on demand" mode, the resource needs to 114 * be written both to the response stream and to the file stream. In 115 * "after publish" mode, it's usually only written to the file stream, 116 * but sometimes it's required to write to the response stream as well.<p> 117 * 118 * @param cms the initialized CmsObject which provides user permissions 119 * @param resource the requested OpenCms VFS resource 120 * @param req the servlet request 121 * @param res the servlet response 122 * 123 * @throws ServletException might be thrown in the process of including the sub element 124 * @throws IOException might be thrown in the process of including the sub element 125 * @throws CmsException in case something goes wrong 126 * @return the contents to export, or <code>null</code> if no export is required 127 */ 128 byte[] export(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res) 129 throws ServletException, IOException, CmsException; 130 131 /** 132 * Returns the id of the ResourceLoader.<p> 133 * 134 * @return the id of the ResourceLoader 135 */ 136 int getLoaderId(); 137 138 /** 139 * Returns a String describing the ResourceLoader.<p> 140 * 141 * @return a String describing the ResourceLoader 142 */ 143 String getResourceLoaderInfo(); 144 145 /** 146 * Signals if the loader implementation supports static export of resources.<p> 147 * 148 * @return true if static export is supported, false otherwise 149 */ 150 boolean isStaticExportEnabled(); 151 152 /** 153 * Signals if the loader implementation requires processing during static export of resources.<p> 154 * 155 * @return true if static export processing is required, false otherwise 156 */ 157 boolean isStaticExportProcessable(); 158 159 /** 160 * Signals if the loader implementation is usable for creating templates.<p> 161 * 162 * @return true if the loader implementation is usable for creating templates, false otherwise 163 */ 164 boolean isUsableForTemplates(); 165 166 /** 167 * Signals if a loader that supports templates must be invoked on the 168 * template URI or the resource URI.<p> 169 * 170 * @return true if the resource URI is to be used, false if the template URI is to be used 171 */ 172 boolean isUsingUriWhenLoadingTemplate(); 173 174 /** 175 * Basic top-page processing method for a I_CmsResourceLoader, 176 * this method is called if the page is called as a sub-element 177 * on a page not already loaded with a I_CmsResourceLoader.<p> 178 * 179 * @param cms the initialized CmsObject which provides user permissions 180 * @param resource the requested OpenCms VFS resource 181 * @param req the servlet request 182 * @param res the servlet response 183 * 184 * @throws ServletException might be thrown by the servlet environment 185 * @throws IOException might be thrown by the servlet environment 186 * @throws CmsException in case of errors accessing OpenCms functions 187 * 188 * @see #service(CmsObject, CmsResource, ServletRequest, ServletResponse) 189 */ 190 void load(CmsObject cms, CmsResource resource, HttpServletRequest req, HttpServletResponse res) 191 throws ServletException, IOException, CmsException; 192 193 /** 194 * Does the job of including the requested resource, 195 * this method is called directly if the element is 196 * called as a sub-element from another I_CmsResourceLoader.<p> 197 * 198 * @param cms used to access the OpenCms VFS 199 * @param resource the requested resource in the VFS 200 * @param req the servlet request 201 * @param res the servlet response 202 * 203 * @throws ServletException might be thrown by the servlet environment 204 * @throws IOException might be thrown by the servlet environment 205 * @throws CmsException in case of errors accessing OpenCms functions 206 * 207 * @see org.opencms.flex.CmsFlexRequestDispatcher 208 */ 209 void service(CmsObject cms, CmsResource resource, ServletRequest req, ServletResponse res) 210 throws ServletException, IOException, CmsException; 211}