Class CmsObjectWrapper
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
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The name of the attribute in theCmsRequestContext
where the current CmsObjectWrapper can be found. -
Constructor Summary
ConstructorDescriptionCmsObjectWrapper
(CmsObject cms, List<I_CmsResourceWrapper> wrappers) Constructor with the CmsObject to wrap and the resource wrappers to use. -
Method Summary
Modifier and TypeMethodDescriptionvoid
copyResource
(String source, String destination, CmsResource.CmsResourceCopyMode siblingMode) Copies a resource.createResource
(String resourcename, int type) Creates a new resource of the given resource type with empty content and no properties.createResource
(String resourcename, int type, byte[] content, List<CmsProperty> properties) Creates a new resource of the given resource type with the provided content and properties.void
deleteResource
(String resourcename, CmsResource.CmsResourceDeleteMode siblingMode) Deletes a resource given its name.boolean
existsResource
(String resourcename) Checks the availability of a resource in the VFS, using theCmsResourceFilter.DEFAULT
filter.getLock
(CmsResource resource) Returns the lock state for a specified resource.Delegate method forCmsObject.getRequestContext()
.getResourcesInFolder
(String resourcename, CmsResourceFilter filter) Returns all child resources of a resource, that is the resources contained in a folder.getSitePath
(CmsResource resource) Delegate method forCmsObject.getSitePath(CmsResource)
.Returns the configured resource wrappers used by this instance.void
lockResource
(String resourcename) Locks a resource.void
lockResourceTemporary
(String resourceName) Locks a resource temporarily.void
moveResource
(String source, String destination) Moves a resource to the given destination.readFile
(String resourcename, CmsResourceFilter filter) Reads a file resource (including it's binary content) from the VFS, using the specified resource filter.readProperties
(String path) Reads the properties for a resource with a specific path, if it exists.readPropertyObject
(CmsResource resource, String property, boolean search) Delegate method forCmsObject.readPropertyObject(CmsResource, String, boolean)
.readResource
(String resourcename, CmsResourceFilter filter) Reads a resource from the VFS, using the
filter.CmsResourceFilter.DEFAULT
readResource
(CmsUUID structureID, CmsResourceFilter filter) Delegate method forCmsObject.readResource(CmsUUID, CmsResourceFilter)
.Delegate method forCmsObject.readUser(CmsUUID)
.restoreLink
(String path) Returns a link to an existing resource in the VFS.rewriteLink
(String path) Returns a link to a resource after it was wrapped by the CmsObjectWrapper.void
setAddByteOrderMark
(boolean addByteOrderMark) Enables or disables the automatic adding of byte order marks to plaintext files.void
unlockResource
(String resourcename) Unlocks a resource.Writes a resource to the OpenCms VFS, including it's content.void
writeProperties
(String path, Map<String, CmsProperty> props) Writes properties to the resource with the given path, if it exists
-
Field Details
-
ATTRIBUTE_NAME
The name of the attribute in theCmsRequestContext
where the current CmsObjectWrapper can be found.- See Also:
-
-
Constructor Details
-
CmsObjectWrapper
Constructor with the CmsObject to wrap and the resource wrappers to use.- Parameters:
cms
- the initialized CmsObjectwrappers
- the configured wrappers to use (entries of typeI_CmsResourceWrapper
)
-
-
Method Details
-
copyResource
public void copyResource(String source, 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 wrongCmsIllegalArgumentException
- if thedestination
argument is null or of length 0- See Also:
-
createResource
public CmsResource createResource(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 wrongCmsIllegalArgumentException
- if the givenresourcename
is null or of length 0- See Also:
-
createResource
public CmsResource createResource(String resourcename, int type, byte[] content, List<CmsProperty> 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 createcontent
- the contents for the new resourceproperties
- the properties for the new resource- Returns:
- the created resource
- Throws:
CmsException
- if something goes wrongCmsIllegalArgumentException
- if theresourcename
argument is null or of length 0- See Also:
-
deleteResource
public void deleteResource(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:
-
existsResource
Checks the availability of a resource in the VFS, using theCmsResourceFilter.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 methodI_CmsResourceWrapper.readResource(CmsObject, String, CmsResourceFilter)
in the configured resource wrappers are called till the first does not throw an exception or returnsnull
.- Parameters:
resourcename
- the name of the resource to check (full path)- Returns:
true
if the resource is available
-
getLock
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:
-
getRequestContext
Delegate method forCmsObject.getRequestContext()
.- Returns:
- the current users request context
- See Also:
-
getResourcesInFolder
public List<CmsResource> getResourcesInFolder(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 calledI_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 toI_CmsResourceWrapper.isWrappedResource(CmsObject, CmsResource)
.- Parameters:
resourcename
- the full path of the resource to return the child resources forfilter
- the resource filter to use- Returns:
- a list of all child
sCmsResource
- Throws:
CmsException
- if something goes wrong- See Also:
-
getSitePath
Delegate method forCmsObject.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:
-
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
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:
-
lockResourceTemporary
Locks a resource temporarily.- Parameters:
resourceName
- the name of the resource to lock- Throws:
CmsException
- if something goes wrong
-
moveResource
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:
-
readFile
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:
-
readProperties
Reads the properties for a resource with a specific path, if it exists.- Parameters:
path
- a VFS path- Returns:
- the map of properties for the resource
- Throws:
CmsException
- if something goes wrong
-
readPropertyObject
public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search) throws CmsException Delegate method forCmsObject.readPropertyObject(CmsResource, String, boolean)
.- Parameters:
resource
- the resource where the property is attached toproperty
- the property namesearch
- 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
if the property was not foundCmsProperty.getNullProperty()
- Throws:
CmsException
- if something goes wrong- See Also:
-
readResource
Delegate method forCmsObject.readResource(CmsUUID, CmsResourceFilter)
.- Parameters:
structureID
- the ID of the structure to readfilter
- 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:
-
readResource
Reads a resource from the VFS, using the
filter.CmsResourceFilter.DEFAULT
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:
-
readUser
Delegate method forCmsObject.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:
-
restoreLink
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
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:
-
setAddByteOrderMark
Enables or disables the automatic adding of byte order marks to plaintext files.- Parameters:
addByteOrderMark
- true if byte order marks should be added to plaintext files automatically
-
unlockResource
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:
-
writeFile
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:
-
writeProperties
Writes properties to the resource with the given path, if it exists- Parameters:
path
- the pathprops
- the properties to write- Throws:
CmsException
- if something goes wrong
-