Class CmsObjectWrapper
- java.lang.Object
-
- org.opencms.file.wrapper.CmsObjectWrapper
-
public class CmsObjectWrapper extends java.lang.Object
This class contains a subset of the methods ofCmsObject
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 theCmsObject
.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
Fields Modifier and Type Field Description static java.lang.String
ATTRIBUTE_NAME
The name of the attribute in theCmsRequestContext
where the current CmsObjectWrapper can be found.
-
Constructor Summary
Constructors Constructor Description CmsObjectWrapper(CmsObject cms, java.util.List<I_CmsResourceWrapper> wrappers)
Constructor with the CmsObject to wrap and the resource wrappers to use.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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<CmsProperty> 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 theCmsResourceFilter.DEFAULT
filter.CmsLock
getLock(CmsResource resource)
Returns the lock state for a specified resource.CmsRequestContext
getRequestContext()
Delegate method forCmsObject.getRequestContext()
.java.util.List<CmsResource>
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 forCmsObject.getSitePath(CmsResource)
.java.util.List<I_CmsResourceWrapper>
getWrappers()
Returns the configured resource wrappers used by this instance.void
lockResource(java.lang.String resourcename)
Locks a resource.void
lockResourceTemporary(java.lang.String resourceName)
Locks a resource temporarily.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.java.util.Map<java.lang.String,CmsProperty>
readProperties(java.lang.String path)
Reads the properties for a resource with a specific path, if it exists.CmsProperty
readPropertyObject(CmsResource resource, java.lang.String property, boolean search)
Delegate method forCmsObject.readPropertyObject(CmsResource, String, boolean)
.CmsResource
readResource(java.lang.String resourcename, CmsResourceFilter filter)
Reads a resource from the VFS, using the
filter.CmsResourceFilter.DEFAULT
CmsResource
readResource(CmsUUID structureID, CmsResourceFilter filter)
Delegate method forCmsObject.readResource(CmsUUID, CmsResourceFilter)
.CmsUser
readUser(CmsUUID userId)
Delegate method forCmsObject.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
setAddByteOrderMark(boolean addByteOrderMark)
Enables or disables the automatic adding of byte order marks to plaintext files.void
unlockResource(java.lang.String resourcename)
Unlocks a resource.CmsFile
writeFile(CmsFile resource)
Writes a resource to the OpenCms VFS, including it's content.void
writeProperties(java.lang.String path, java.util.Map<java.lang.String,CmsProperty> props)
Writes properties to the resource with the given path, if it exists
-
-
-
Field Detail
-
ATTRIBUTE_NAME
public static final java.lang.String ATTRIBUTE_NAME
The name of the attribute in theCmsRequestContext
where the current CmsObjectWrapper can be found.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsObjectWrapper
public CmsObjectWrapper(CmsObject cms, java.util.List<I_CmsResourceWrapper> wrappers)
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 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 wrongCmsIllegalArgumentException
- if thedestination
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 wrongCmsIllegalArgumentException
- if the givenresourcename
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<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:
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 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
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 forCmsObject.getRequestContext()
.- Returns:
- the current users request context
- See Also:
CmsObject.getRequestContext()
-
getResourcesInFolder
public java.util.List<CmsResource> 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 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:
I_CmsResourceWrapper.addResourcesToFolder(CmsObject, String, CmsResourceFilter)
,CmsObject.getResourcesInFolder(String, CmsResourceFilter)
-
getSitePath
public java.lang.String getSitePath(CmsResource resource)
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:
CmsObject.getSitePath(org.opencms.file.CmsResource)
-
getWrappers
public java.util.List<I_CmsResourceWrapper> 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:
CmsObject.lockResource(String)
-
lockResourceTemporary
public void lockResourceTemporary(java.lang.String resourceName) throws CmsException
Locks a resource temporarily.- Parameters:
resourceName
- the name of the resource to lock- Throws:
CmsException
- if something goes wrong
-
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)
-
readProperties
public java.util.Map<java.lang.String,CmsProperty> readProperties(java.lang.String path) throws CmsException
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, java.lang.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:
CmsObject.readPropertyObject(CmsResource, String, boolean)
-
readResource
public CmsResource readResource(CmsUUID structureID, CmsResourceFilter filter) throws CmsException
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:
CmsObject.readResource(CmsUUID, CmsResourceFilter)
-
readResource
public CmsResource readResource(java.lang.String resourcename, CmsResourceFilter filter) throws CmsException
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:
I_CmsResourceWrapper.readResource(CmsObject, String, CmsResourceFilter)
,CmsObject.readResource(String, CmsResourceFilter)
-
readUser
public CmsUser readUser(CmsUUID userId) throws CmsException
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:
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)
-
setAddByteOrderMark
public void setAddByteOrderMark(boolean addByteOrderMark)
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
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)
-
writeProperties
public void writeProperties(java.lang.String path, java.util.Map<java.lang.String,CmsProperty> props) throws CmsException
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
-
-