001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.file.wrapper; 029 030import org.opencms.file.CmsFile; 031import org.opencms.file.CmsObject; 032import org.opencms.file.CmsProperty; 033import org.opencms.file.CmsResource; 034import org.opencms.file.CmsResource.CmsResourceCopyMode; 035import org.opencms.file.CmsResource.CmsResourceDeleteMode; 036import org.opencms.file.CmsResourceFilter; 037import org.opencms.lock.CmsLock; 038import org.opencms.main.CmsException; 039import org.opencms.main.CmsIllegalArgumentException; 040 041import java.util.List; 042 043/** 044 * Interface which is used by the {@link CmsObjectWrapper} to create a different view to the 045 * resources in the VFS.<p> 046 * 047 * It is possible to create "new" virtual resource in the view to the clients using the 048 * <code>CmsObjectWrapper</code> or to change the existing ones. For example adding the correct 049 * file extension for resources, because it is not always given that resources of type jsp have 050 * the extension ".jsp". A resource wrapper just could add this extension, so that clients can 051 * handle that resource correctly.<p> 052 * 053 * Each method in the implementing classes first have to check in every method if it is 054 * responsible for the action to execute, because the <code>CmsObjectWrapper</code> iterates 055 * through all configured resource wrappers and the first which feels responsible wins and the 056 * others won't even called.<p> 057 * 058 * @since 6.2.4 059 */ 060public interface I_CmsResourceWrapper { 061 062 /** 063 * Here it is possible to add additional (virtual) child resources to those already existing 064 * in the VFS.<p> 065 * 066 * @see CmsObjectWrapper#getResourcesInFolder(String, CmsResourceFilter) 067 * 068 * @param cms the current users OpenCms context 069 * @param resourcename the full path of the resource where to add the child resources for 070 * @param filter the resource filter to use 071 * 072 * @return a list of all additionaly child <code>{@link CmsResource}</code>s 073 * 074 * @throws CmsException if something goes wrong 075 */ 076 List<CmsResource> addResourcesToFolder(CmsObject cms, String resourcename, CmsResourceFilter filter) 077 throws CmsException; 078 079 /** 080 * If there is a configuration string for the wrapper, this method will be called with the configuration string 081 * before it is used.<p> 082 * 083 * Otherwise, it will not be called. 084 * 085 * @param configuration the configuration string for the wrapper 086 */ 087 void configure(String configuration); 088 089 /** 090 * Copies a resource.<p> 091 * 092 * First should be a check if the source and/or the destination are handled by this 093 * resource wrapper.<p> 094 * 095 * It is possible that the path in the source or in the destination are virtual paths and 096 * so has to be translated into valid paths existing in the VFS to copy the resource.<p> 097 * 098 * @see CmsObjectWrapper#copyResource(String, String, CmsResource.CmsResourceCopyMode) 099 * @see CmsObject#copyResource(String, String, CmsResource.CmsResourceCopyMode) 100 * 101 * @param cms the initialized CmsObject 102 * @param source the name of the resource to copy 103 * @param destination the name of the copy destination with complete path 104 * @param siblingMode indicates how to handle siblings during copy 105 * 106 * @return true if the copy action was handled by this resource wrapper otherwise false 107 * 108 * @throws CmsIllegalArgumentException if the <code>destination</code> argument is null or of length 0 109 * @throws CmsException if something goes wrong 110 */ 111 boolean copyResource(CmsObject cms, String source, String destination, CmsResourceCopyMode siblingMode) 112 throws CmsException, CmsIllegalArgumentException; 113 114 /** 115 * Creates a new resource of the given resource type 116 * with the provided content and properties.<p> 117 * 118 * First should be a check if the resourcename is handled by this 119 * resource wrapper.<p> 120 * 121 * It is possible that the path in the resourcename is a virtual path and 122 * so has to be translated into a valid path existing in the VFS to create the resource.<p> 123 * 124 * @see CmsObjectWrapper#createResource(String, int, byte[], List) 125 * @see CmsObject#createResource(String, int, byte[], List) 126 * 127 * @param cms the initialized CmsObject 128 * @param resourcename the name of the resource to create (full path) 129 * @param type the type of the resource to create 130 * @param content the content for the new resource 131 * @param properties the properties for the new resource 132 * 133 * @return the created resource or null if not handled by this resource wrapper 134 * 135 * @throws CmsException if something goes wrong 136 * @throws CmsIllegalArgumentException if the <code>source</code> argument is null or of length 0 137 */ 138 CmsResource createResource( 139 CmsObject cms, 140 String resourcename, 141 int type, 142 byte[] content, 143 List<CmsProperty> properties) 144 throws CmsException, CmsIllegalArgumentException; 145 146 /** 147 * Deletes a resource given its name.<p> 148 * 149 * First should be a check if the resourcename is handled by this 150 * resource wrapper.<p> 151 * 152 * It is possible that the path in the resourcename is a virtual path and 153 * so has to be translated into a valid path existing in the VFS to delete the resource.<p> 154 * 155 * @see CmsObjectWrapper#deleteResource(String, CmsResource.CmsResourceDeleteMode) 156 * @see CmsObject#deleteResource(String, CmsResource.CmsResourceDeleteMode) 157 * 158 * @param cms the initialized CmsObject 159 * @param resourcename the name of the resource to delete 160 * @param siblingMode indicates how to handle siblings of the deleted resource 161 * 162 * @return true if the delete action was handled by this resource wrapper otherwise false 163 * 164 * @throws CmsException if something goes wrong 165 */ 166 boolean deleteResource(CmsObject cms, String resourcename, CmsResourceDeleteMode siblingMode) throws CmsException; 167 168 /** 169 * Returns the lock for the resource.<p> 170 * 171 * First should be a check if the resource is handled by this 172 * resource wrapper.<p> 173 * 174 * It is possible that the path in the resource is a virtual path and 175 * so has to be translated into a valid path existing in the VFS to 176 * get the lock for the resource.<p> 177 * 178 * @see CmsObjectWrapper#getLock(CmsResource) 179 * @see CmsObject#getLock(CmsResource) 180 * 181 * @param cms the initialized CmsObject 182 * @param resource the resource to check the lock for 183 * 184 * @return the lock state of the resource or null if the action couldn't be handled by this resource wrapper 185 * 186 * @throws CmsException if something goes wrong 187 */ 188 CmsLock getLock(CmsObject cms, CmsResource resource) throws CmsException; 189 190 /** 191 * Is called to check if the given resource is handled by this wrapper.<p> 192 * 193 * @see CmsObjectWrapper#getResourcesInFolder(String, CmsResourceFilter) 194 * 195 * @param cms the initialized CmsObject 196 * @param res the resource to check 197 * 198 * @return true if the resource will be handled by the wrapper otherwise false 199 */ 200 boolean isWrappedResource(CmsObject cms, CmsResource res); 201 202 /** 203 * Locks a resource.<p> 204 * 205 * First should be a check if the resourcename is handled by this 206 * resource wrapper.<p> 207 * 208 * It is possible that the path in the resourcename is a virtual path and 209 * so has to be translated into a valid path existing in the VFS to lock the resource.<p> 210 * 211 * @see CmsObjectWrapper#lockResource(String) 212 * @see CmsObject#lockResource(String) 213 * 214 * @param cms the current users OpenCms context 215 * @param resourcename the name of the resource to lock (full path) 216 * @param temporary true if the resource should only be locked temporarily 217 * 218 * @return true if this request could be handled by this wrapper or false if not 219 * 220 * @throws CmsException if something goes wrong 221 */ 222 boolean lockResource(CmsObject cms, String resourcename, boolean temporary) throws CmsException; 223 224 /** 225 * Moves a resource to the given destination.<p> 226 * 227 * First should be a check if the source and/or the destination are handled by this 228 * resource wrapper.<p> 229 * 230 * It is possible that the path in the source or in the destination are virtual paths and 231 * so has to be translated into valid paths existing in the VFS to move the resource.<p> 232 * 233 * @see CmsObjectWrapper#moveResource(String, String) 234 * @see CmsObject#moveResource(String, String) 235 * 236 * @param cms the current cms context 237 * @param source the name of the resource to move 238 * @param destination the destination resource name 239 * 240 * @throws CmsException if something goes wrong 241 * @throws CmsIllegalArgumentException if the <code>source</code> argument is null or of length 0 242 * 243 * @return true if the move action was handled by this resource wrapper otherwise false 244 */ 245 boolean moveResource(CmsObject cms, String source, String destination) 246 throws CmsException, CmsIllegalArgumentException; 247 248 /** 249 * Reads a file resource (including it's binary content) from the VFS, 250 * using the specified resource filter.<p> 251 * 252 * First should be a check if the resourcename is handled by this 253 * resource wrapper.<p> 254 * 255 * It is possible that the path in the resourcename is a virtual path and 256 * so has to be translated into a valid path existing in the VFS to read the resource.<p> 257 * 258 * @see CmsObjectWrapper#readFile(String, CmsResourceFilter) 259 * @see CmsObject#readFile(String, CmsResourceFilter) 260 * 261 * @param cms the current users OpenCms context 262 * @param resourcename the name of the resource to read (full path) 263 * @param filter the resource filter to use while reading 264 * 265 * @return the file resource that was read or null if it could not be handled by this resource wrapper 266 * 267 * @throws CmsException if the file resource could not be read for any reason 268 */ 269 CmsFile readFile(CmsObject cms, String resourcename, CmsResourceFilter filter) throws CmsException; 270 271 /** 272 * Reads a resource from the VFS, using the specified resource filter.<p> 273 * 274 * First should be a check if the resourcename is handled by this 275 * resource wrapper.<p> 276 * 277 * It is possible that the path in the resourcename is a virtual path and 278 * so has to be translated into a valid path existing in the VFS to read the resource.<p> 279 * 280 * @see CmsObjectWrapper#readResource(String, CmsResourceFilter) 281 * @see CmsObject#readResource(String, CmsResourceFilter) 282 * 283 * @param cms the current users OpenCms context 284 * @param resourcename The name of the resource to read (full path) 285 * @param filter the resource filter to use while reading 286 * 287 * @return the resource that was read or null if it could not be handled by this resource wrapper 288 * 289 * @throws CmsException if the resource could not be read for any reason 290 */ 291 CmsResource readResource(CmsObject cms, String resourcename, CmsResourceFilter filter) throws CmsException; 292 293 /** 294 * Returns the link to a existing resource in the VFS for the uri.<p> 295 * 296 * Turns the virtual path into a real path to a resource in the VFS.<p> 297 * 298 * @see #rewriteLink(CmsObject, CmsResource) 299 * @see CmsObjectWrapper#restoreLink(String) 300 * 301 * @param cms the initialized CmsObject 302 * @param uri the (virtual) uri to be restored 303 * 304 * @return the uri where to find the resource in the VFS or null if the wrapper is not responsible 305 */ 306 String restoreLink(CmsObject cms, String uri); 307 308 /** 309 * Returns the link how it is for the resource after using this resource wrapper.<p> 310 * 311 * For example: in the VFS: "/sites/default/index.html" and this resource wrapper 312 * adds the extension "jsp" then link returned should be "/sites/default/index.html.jsp".<p> 313 * 314 * @see #restoreLink(CmsObject, String) 315 * @see CmsObjectWrapper#rewriteLink(String) 316 * 317 * @param cms the initialized CmsObject 318 * @param res the resource where to rewrite the path 319 * 320 * @return the rewritten path or null if the wrapper is not responsible 321 */ 322 String rewriteLink(CmsObject cms, CmsResource res); 323 324 /** 325 * Unlocks a resource.<p> 326 * 327 * First should be a check if the resourcename is handled by this 328 * resource wrapper.<p> 329 * 330 * It is possible that the path in the resourcename is a virtual path and 331 * so has to be translated into a valid path existing in the VFS to unlock the resource.<p> 332 * 333 * @see CmsObjectWrapper#unlockResource(String) 334 * @see CmsObject#unlockResource(String) 335 * 336 * @param cms the current users OpenCms context 337 * @param resourcename the name of the resource to unlock (full path) 338 * 339 * @return true if this request could be handled by this wrapper of false if not 340 * 341 * @throws CmsException if something goes wrong 342 */ 343 boolean unlockResource(CmsObject cms, String resourcename) throws CmsException; 344 345 /** 346 * Changes the given resource based on the implementation of this wrapper.<p> 347 * 348 * For example, some resource types like {@link org.opencms.file.types.CmsResourceTypeJsp} 349 * just get a <code>.jsp</code> extension, while other types like 350 * {@link org.opencms.file.types.CmsResourceTypeXmlPage} are "exploded" into a folder / 351 * file structure.<p> 352 * 353 * @see CmsObjectWrapper#getResourcesInFolder(String, CmsResourceFilter) 354 * 355 * @param cms the current users OpenCms context 356 * @param resource the resource to wrap 357 * 358 * @return a wrapped {@link CmsResource} object or <code>null</code> to not change the resource 359 */ 360 CmsResource wrapResource(CmsObject cms, CmsResource resource); 361 362 /** 363 * Writes a resource, including it's content.<p> 364 * 365 * First should be a check if the resource is handled by this 366 * resource wrapper.<p> 367 * 368 * It is possible that the path in the resource is a virtual path and 369 * so has to be translated into a valid path existing in the VFS to write the resource.<p> 370 * 371 * @see CmsObjectWrapper#writeFile(CmsFile) 372 * @see CmsObject#writeFile(CmsFile) 373 * 374 * @param cms the current cms context 375 * @param resource the resource to apply this operation to 376 * 377 * @return the written resource or null if the action could not be handled by this resource wrapper 378 * 379 * @throws CmsException if something goes wrong 380 */ 381 CmsFile writeFile(CmsObject cms, CmsFile resource) throws CmsException; 382}