Package org.opencms.file.wrapper
Class CmsResourceWrapperUtils
java.lang.Object
org.opencms.file.wrapper.CmsResourceWrapperUtils
Helper class with several methods used by different implementations of the
interface
I_CmsResourceWrapper
.It provides methods to add or remove file extensions to resources, to handle creating and writing property files and to add the byte order mask to UTF-8 byte contents.
- Since:
- 6.2.4
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The extension to use for the property file.static final String
Property name used for reading / changing the resource type.static final String
The prefix used for a shared property entry.static final String
The prefix used for a shared property entry.static final byte[]
The UTF-8 bytes to add to the beginning of text contents. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
addFileExtension
(CmsObject cms, String resourcename, String extension) Adds a file extension to the resource name.static byte[]
addUtf8Marker
(byte[] content) Adds the UTF-8 marker add the beginning of the byte array.static CmsFile
createPropertyFile
(CmsObject cms, CmsResource res, String path) Creates a virtual CmsFile with the individual and shared properties as content.static String
removeFileExtension
(CmsObject cms, String resourcename, String extension) Removes an added file extension from the resource name.static byte[]
removeUtf8Marker
(byte[] content) Removes the UTF-8 marker from the beginning of the byte array.static void
writePropertyFile
(CmsObject cms, String resourcename, byte[] content) Takes the content which should be formatted as a property file and set them as properties to the resource.
-
Field Details
-
EXTENSION_PROPERTIES
The extension to use for the property file.- See Also:
-
PROPERTY_RESOURCE_TYPE
Property name used for reading / changing the resource type.- See Also:
-
SUFFIX_PROP_INDIVIDUAL
The prefix used for a shared property entry.- See Also:
-
SUFFIX_PROP_SHARED
The prefix used for a shared property entry.- See Also:
-
UTF8_MARKER
The UTF-8 bytes to add to the beginning of text contents.
-
-
Method Details
-
addFileExtension
Adds a file extension to the resource name.If the file with the new extension already exists, an index count will be added before the final extension.
For example:
index.html.1.jsp
.- Parameters:
cms
- the actual CmsObjectresourcename
- the name of the resource where to add the file extensionextension
- the extension to add- Returns:
- the resource name with the added file extension
- See Also:
-
addUtf8Marker
Adds the UTF-8 marker add the beginning of the byte array.- Parameters:
content
- the byte array where to add the UTF-8 marker- Returns:
- the byte with the added UTF-8 marker at the beginning
-
createPropertyFile
public static CmsFile createPropertyFile(CmsObject cms, CmsResource res, String path) throws CmsException Creates a virtual CmsFile with the individual and shared properties as content.For example looks like this:
Title.i=The title of the resource set as individual property
Title.s=The title of the resource set as shared property- Parameters:
cms
- the initialized CmsObjectres
- the resource where to read the properties frompath
- the full path to set for the created property file- Returns:
- the created CmsFile with the individual and shared properties as the content
- Throws:
CmsException
- if something goes wrong- See Also:
-
removeFileExtension
Removes an added file extension from the resource name.- If there is only one extension, nothing will be removed.
- If there are two extensions, the last one will be removed.
- If there are more than two extensions the last one will be removed and if then the last extension is a number, the extension with the number will be removed too.
- Parameters:
cms
- the initialized CmsObjectresourcename
- the resource name to remove the file extension fromextension
- the extension to remove- Returns:
- the resource name without the removed file extension
- See Also:
-
removeUtf8Marker
Removes the UTF-8 marker from the beginning of the byte array.- Parameters:
content
- the byte array where to remove the UTF-8 marker- Returns:
- the byte with the removed UTF-8 marker at the beginning
-
writePropertyFile
public static void writePropertyFile(CmsObject cms, String resourcename, byte[] content) throws CmsException Takes the content which should be formatted as a property file and set them as properties to the resource.- Parameters:
cms
- the initialized CmsObjectresourcename
- the name of the resource where to set the propertiescontent
- the properties to set (formatted as a property file)- Throws:
CmsException
- if something goes wrong- See Also:
-