org.opencms.file.wrapper
Class CmsObjectWrapper

java.lang.Object
  extended by org.opencms.file.wrapper.CmsObjectWrapper

public class CmsObjectWrapper
extends java.lang.Object

This class contains a subset of the methods of CmsObject and uses the configured resource wrappers (I_CmsResourceWrapper) to change the view to the existing resources in the VFS.

Almost every method in this class iterates through the configured list of I_CmsResourceWrapper and calls the same method there. The first resource wrapper in the list which feels responsible for that action handles it and the iteration ends. So the resource wrappers should check in every method if it is responsible or not. Be careful if there are more than one resource wrapper for the same resource in the VFS, because the first in the list wins. If the iteration is finished and no resource wrapper felt responsible the default action is to call the method in the CmsObject.

It is possible to create an unchanged access to the resource in the VFS by creating a new instance of the CmsObjectWrapper with an empty list of resource wrappers.

Since:
6.2.4
Version:
$Revision: 1.13 $
Author:
Peter Bonrad

Field Summary
static java.lang.String ATTRIBUTE_NAME
          The name of the attribute in the CmsRequestContext where the current CmsObjectWrapper can be found.
 
Constructor Summary
CmsObjectWrapper(CmsObject cms, java.util.List wrappers)
          Constructor with the CmsObject to wrap and the resource wrappers to use.
 
Method Summary
 void copyResource(java.lang.String source, java.lang.String destination, CmsResource.CmsResourceCopyMode siblingMode)
          Copies a resource.
 CmsResource createResource(java.lang.String resourcename, int type)
          Creates a new resource of the given resource type with empty content and no properties.
 CmsResource createResource(java.lang.String resourcename, int type, byte[] content, java.util.List properties)
          Creates a new resource of the given resource type with the provided content and properties.
 void deleteResource(java.lang.String resourcename, CmsResource.CmsResourceDeleteMode siblingMode)
          Deletes a resource given its name.
 boolean existsResource(java.lang.String resourcename)
          Checks the availability of a resource in the VFS, using the CmsResourceFilter.DEFAULT filter.
 CmsLock getLock(CmsResource resource)
          Returns the lock state for a specified resource.
 CmsRequestContext getRequestContext()
          Delegate method for CmsObject.getRequestContext().
 java.util.List getResourcesInFolder(java.lang.String resourcename, CmsResourceFilter filter)
          Returns all child resources of a resource, that is the resources contained in a folder.
 java.lang.String getSitePath(CmsResource resource)
          Delegate method for CmsObject.getSitePath(CmsResource).
 java.util.List getWrappers()
          Returns the configured resource wrappers used by this instance.
 void lockResource(java.lang.String resourcename)
          Locks a resource.
 void moveResource(java.lang.String source, java.lang.String destination)
          Moves a resource to the given destination.
 CmsFile readFile(java.lang.String resourcename, CmsResourceFilter filter)
          Reads a file resource (including it's binary content) from the VFS, using the specified resource filter.
 CmsProperty readPropertyObject(CmsResource resource, java.lang.String property, boolean search)
          Delegate method for CmsObject.readPropertyObject(CmsResource, String, boolean).
 CmsResource readResource(CmsUUID structureID, CmsResourceFilter filter)
          Delegate method for CmsObject.readResource(CmsUUID, CmsResourceFilter).
 CmsResource readResource(java.lang.String resourcename, CmsResourceFilter filter)
          Reads a resource from the VFS, using the CmsResourceFilter.DEFAULT filter.
 CmsUser readUser(CmsUUID userId)
          Delegate method for CmsObject.readUser(CmsUUID).
 java.lang.String restoreLink(java.lang.String path)
          Returns a link to an existing resource in the VFS.
 java.lang.String rewriteLink(java.lang.String path)
          Returns a link to a resource after it was wrapped by the CmsObjectWrapper.
 void unlockResource(java.lang.String resourcename)
          Unlocks a resource.
 CmsFile writeFile(CmsFile resource)
          Writes a resource to the OpenCms VFS, including it's content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTRIBUTE_NAME

public static final java.lang.String ATTRIBUTE_NAME
The name of the attribute in the CmsRequestContext where the current CmsObjectWrapper can be found.

See Also:
Constant Field Values
Constructor Detail

CmsObjectWrapper

public CmsObjectWrapper(CmsObject cms,
                        java.util.List wrappers)
Constructor with the CmsObject to wrap and the resource wrappers to use.

Parameters:
cms - the initialized CmsObject
wrappers - the configured wrappers to use (entries of type I_CmsResourceWrapper)
Method Detail

copyResource

public void copyResource(java.lang.String source,
                         java.lang.String destination,
                         CmsResource.CmsResourceCopyMode siblingMode)
                  throws CmsException,
                         CmsIllegalArgumentException
Copies a resource.

Iterates through all configured resource wrappers till the first returns true.

Parameters:
source - the name of the resource to copy (full path)
destination - the name of the copy destination (full path)
siblingMode - indicates how to handle siblings during copy
Throws:
CmsException - if something goes wrong
CmsIllegalArgumentException - if the destination argument is null or of length 0
See Also:
I_CmsResourceWrapper.copyResource(CmsObject, String, String, CmsResource.CmsResourceCopyMode), CmsObject.copyResource(String, String, CmsResource.CmsResourceCopyMode)

createResource

public CmsResource createResource(java.lang.String resourcename,
                                  int type)
                           throws CmsException,
                                  CmsIllegalArgumentException
Creates a new resource of the given resource type with empty content and no properties.

Parameters:
resourcename - the name of the resource to create (full path)
type - the type of the resource to create
Returns:
the created resource
Throws:
CmsException - if something goes wrong
CmsIllegalArgumentException - if the given resourcename is null or of length 0
See Also:
createResource(String, int, byte[], List)

createResource

public CmsResource createResource(java.lang.String resourcename,
                                  int type,
                                  byte[] content,
                                  java.util.List properties)
                           throws CmsException,
                                  CmsIllegalArgumentException
Creates a new resource of the given resource type with the provided content and properties.

Iterates through all configured resource wrappers till the first returns not null.

Parameters:
resourcename - the name of the resource to create (full path)
type - the type of the resource to create
content - the contents for the new resource
properties - the properties for the new resource
Returns:
the created resource
Throws:
CmsException - if something goes wrong
CmsIllegalArgumentException - if the resourcename argument is null or of length 0
See Also:
I_CmsResourceWrapper.createResource(CmsObject, String, int, byte[], List), CmsObject.createResource(String, int, byte[], List)

deleteResource

public void deleteResource(java.lang.String resourcename,
                           CmsResource.CmsResourceDeleteMode siblingMode)
                    throws CmsException
Deletes a resource given its name.

Iterates through all configured resource wrappers till the first returns true.

Parameters:
resourcename - the name of the resource to delete (full path)
siblingMode - indicates how to handle siblings of the deleted resource
Throws:
CmsException - if something goes wrong
See Also:
I_CmsResourceWrapper.deleteResource(CmsObject, String, CmsResource.CmsResourceDeleteMode), CmsObject.deleteResource(String, CmsResource.CmsResourceDeleteMode)

existsResource

public boolean existsResource(java.lang.String resourcename)
Checks the availability of a resource in the VFS, using the CmsResourceFilter.DEFAULT filter.

Here it will be first checked if the resource exists in the VFS by calling CmsObject.existsResource(String). Only if it doesn't exist in the VFS the method I_CmsResourceWrapper.readResource(CmsObject, String, CmsResourceFilter) in the configured resource wrappers are called till the first does not throw an exception or returns null.

Parameters:
resourcename - the name of the resource to check (full path)
Returns:
true if the resource is available

getLock

public CmsLock getLock(CmsResource resource)
                throws CmsException
Returns the lock state for a specified resource.

Iterates through all configured resource wrappers till the first returns not null.

Parameters:
resource - the resource to return the lock state for
Returns:
the lock state for the specified resource
Throws:
CmsException - if something goes wrong
See Also:
I_CmsResourceWrapper.getLock(CmsObject, CmsResource), CmsObject.getLock(CmsResource)

getRequestContext

public CmsRequestContext getRequestContext()
Delegate method for CmsObject.getRequestContext().

Returns:
the current users request context
See Also:
CmsObject.getRequestContext()

getResourcesInFolder

public java.util.List getResourcesInFolder(java.lang.String resourcename,
                                           CmsResourceFilter filter)
                                    throws CmsException
Returns all child resources of a resource, that is the resources contained in a folder.

First fetch all child resources from VFS by calling CmsObject.getResourcesInFolder(String, CmsResourceFilter). After that all resource wrapper are called I_CmsResourceWrapper.addResourcesToFolder(CmsObject, String, CmsResourceFilter) to have the chance to add additional resources to those already existing. In that list every resource is given to the appropriate resource wrapper (I_CmsResourceWrapper.wrapResource(CmsObject, CmsResource)) to have the possibility to change the existing resources. The matching resource wrapper for a resource is found by a call to I_CmsResourceWrapper.isWrappedResource(CmsObject, CmsResource).

Parameters:
resourcename - the full path of the resource to return the child resources for
filter - the resource filter to use
Returns:
a list of all child CmsResources
Throws:
CmsException - if something goes wrong
See Also:
I_CmsResourceWrapper.addResourcesToFolder(CmsObject, String, CmsResourceFilter), CmsObject.getResourcesInFolder(String, CmsResourceFilter)

getSitePath

public java.lang.String getSitePath(CmsResource resource)
Delegate method for CmsObject.getSitePath(CmsResource).

Parameters:
resource - the resource to get the adjusted site root path for
Returns:
the absolute resource path adjusted for the current site
See Also:
CmsObject.getSitePath(org.opencms.file.CmsResource)

getWrappers

public java.util.List getWrappers()
Returns the configured resource wrappers used by this instance.

Entries in list are from type I_CmsResourceWrapper.

Returns:
the configured resource wrappers for this instance

lockResource

public void lockResource(java.lang.String resourcename)
                  throws CmsException
Locks a resource.

Iterates through all configured resource wrappers till the first returns true.

Parameters:
resourcename - the name of the resource to lock (full path)
Throws:
CmsException - if something goes wrong
See Also:
I_CmsResourceWrapper.lockResource(CmsObject, String), CmsObject.lockResource(String)

moveResource

public void moveResource(java.lang.String source,
                         java.lang.String destination)
                  throws CmsException
Moves a resource to the given destination.

Iterates through all configured resource wrappers till the first returns true.

Parameters:
source - the name of the resource to move (full path)
destination - the destination resource name (full path)
Throws:
CmsException - if something goes wrong
See Also:
I_CmsResourceWrapper.moveResource(CmsObject, String, String), CmsObject.moveResource(String, String)

readFile

public CmsFile readFile(java.lang.String resourcename,
                        CmsResourceFilter filter)
                 throws CmsException
Reads a file resource (including it's binary content) from the VFS, using the specified resource filter.

Iterates through all configured resource wrappers till the first returns not null.

If the resource contains textual content and the encoding is UTF-8, then the byte order mask for UTF-8 is added at the start of the content to make sure that a client using this content displays it correctly.

Parameters:
resourcename - the name of the resource to read (full path)
filter - the resource filter to use while reading
Returns:
the file resource that was read
Throws:
CmsException - if the file resource could not be read for any reason
See Also:
I_CmsResourceWrapper.readFile(CmsObject, String, CmsResourceFilter), CmsObject.readFile(String, CmsResourceFilter)

readPropertyObject

public CmsProperty readPropertyObject(CmsResource resource,
                                      java.lang.String property,
                                      boolean search)
                               throws CmsException
Delegate method for CmsObject.readPropertyObject(CmsResource, String, boolean).

Parameters:
resource - the resource where the property is attached to
property - the property name
search - if true, the property is searched on all parent folders of the resource, if it's not found attached directly to the resource
Returns:
the required property, or CmsProperty.getNullProperty() if the property was not found
Throws:
CmsException - if something goes wrong
See Also:
CmsObject.readPropertyObject(CmsResource, String, boolean)

readResource

public CmsResource readResource(CmsUUID structureID,
                                CmsResourceFilter filter)
                         throws CmsException
Delegate method for CmsObject.readResource(CmsUUID, CmsResourceFilter).

Parameters:
structureID - the ID of the structure to read
filter - the resource filter to use while reading
Returns:
the resource that was read
Throws:
CmsException - if the resource could not be read for any reason
See Also:
CmsObject.readResource(CmsUUID, CmsResourceFilter)

readResource

public CmsResource readResource(java.lang.String resourcename,
                                CmsResourceFilter filter)
                         throws CmsException
Reads a resource from the VFS, using the CmsResourceFilter.DEFAULT filter.

Iterates through all configured resource wrappers till the first returns not null.

Parameters:
resourcename - The name of the resource to read (full path)
filter - the resource filter to use while reading
Returns:
the resource that was read
Throws:
CmsException - if the resource could not be read for any reason
See Also:
I_CmsResourceWrapper.readResource(CmsObject, String, CmsResourceFilter), CmsObject.readResource(String, CmsResourceFilter)

readUser

public CmsUser readUser(CmsUUID userId)
                 throws CmsException
Delegate method for CmsObject.readUser(CmsUUID).

Parameters:
userId - the id of the user to be read
Returns:
the user with the given id
Throws:
CmsException - if something goes wrong
See Also:
CmsObject.readUser(CmsUUID)

restoreLink

public java.lang.String restoreLink(java.lang.String path)
Returns a link to an existing resource in the VFS.

Because it is possible through the CmsObjectWrapper to create "virtual" resources, which can not be found in the VFS, it is necessary to change the links in pages as well, so that they point to resources which really exists in the VFS.

Iterates through all configured resource wrappers till the first returns not null.

Parameters:
path - the path to the resource
Returns:
the path for the resource which exists in the VFS
See Also:
rewriteLink(String), I_CmsResourceWrapper.restoreLink(CmsObject, String)

rewriteLink

public java.lang.String rewriteLink(java.lang.String path)
Returns a link to a resource after it was wrapped by the CmsObjectWrapper.

Because it is possible to change the names of resources inside the VFS by this CmsObjectWrapper, it is necessary to change the links used in pages as well, so that they point to the changed name of the resource.

For example: /sites/default/index.html becomes to /sites/default/index.html.jsp, because it is a jsp page, the links in pages where corrected so that they point to the new name (with extension "jsp").

Used for the link processing in the class CmsLink.

Iterates through all configured resource wrappers till the first returns not null.

Parameters:
path - the full path where to find the resource
Returns:
the rewritten link for the resource
See Also:
restoreLink(String), I_CmsResourceWrapper.rewriteLink(CmsObject, CmsResource)

unlockResource

public void unlockResource(java.lang.String resourcename)
                    throws CmsException
Unlocks a resource.

Iterates through all configured resource wrappers till the first returns true.

Parameters:
resourcename - the name of the resource to unlock (full path)
Throws:
CmsException - if something goes wrong
See Also:
I_CmsResourceWrapper.unlockResource(CmsObject, String), CmsObject.unlockResource(String)

writeFile

public CmsFile writeFile(CmsFile resource)
                  throws CmsException
Writes a resource to the OpenCms VFS, including it's content.

Iterates through all configured resource wrappers till the first returns not null.

Parameters:
resource - the resource to write
Returns:
the written resource (may have been modified)
Throws:
CmsException - if something goes wrong
See Also:
I_CmsResourceWrapper.writeFile(CmsObject, CmsFile), CmsObject.writeFile(CmsFile)