Class CmsMacroResolver
- All Implemented Interfaces:
I_CmsMacroResolver
- Direct Known Subclasses:
CmsGalleryNameMacroResolver
,CmsKeyDummyMacroResolver
,CmsNotificationMacroResolver
,CmsVersionMacroResolver
%(key)
or ${key}
in an input String.
Starting with OpenCms 7.0, the preferred form of a macro is %(key)
. This is to
avoid conflicts / confusion with the JSP EL, which also uses the ${key}
syntax.
The macro names that can be resolved depend of the context objects provided to the resolver
using the set...
methods.
- Since:
- 6.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The prefix indicating that the key represents an OpenCms runtime attribute.static final String
Key used to specify the context path as macro value.static final String
Key used to specify the description of the current organizational unit as macro value.static final String
Key used to specify the full qualified name of the current organizational unit as macro value.static final String
Key used to specify the current time as macro value.static final String
Key used to specify the city of the current user as macro value.static final String
Key used to specify the country of the current user as macro value.static final String
Key used to specify the display name of the current user as macro value.static final String
Key used to specify the email address of the current user as macro value.static final String
Key used to specify the first name of the current user as macro value.static final String
Key used to specify the full name of the current user as macro value.static final String
Key used to specify the institution of the current user as macro value.static final String
Key used to specify the last login date of the current user as macro value.static final String
Key used to specify the last name of the current user as macro value.static final String
Key used to specify the user name of the current user as macro value.static final String
Key used to specify the street of the current user as macro value.static final String
Key used to specify the zip code of the current user as macro value.static final String
Key prefix used to specify the value of a localized key as macro value.static final String
Identifier for "magic" parameter names.static final String
The prefix indicating that the key represents a page context object.static final String
Prefix for getting parameters from the CmsParameterStore.static final String
Key used to specify the project id as macro value.static final String
The prefix indicating that the key represents a property to be read on the current request URI.static final String
The prefix indicating that the key represents a property to be read on the current element.static final String
Key used to specify a random id as macro value.static final String
Key used to specify the request encoding as macro value.static final String
Key used to specify the folder of the request URI as macro value.static final String
Key user to specify the request locale as macro value.static final String
The prefix indicating that the key represents a HTTP request parameter.static final String
Key used to specify the request site root as macro value.static final String
Key used to specify the request uri as macro value.static final String
Key for accessing sitemap attributes.static final String
Key used to specify the validation path as macro value.static final String
Key used to specify the validation regex as macro value.static final String
Key used to specify the validation value as macro value.A map of additional values provided by the calling class.protected CmsObject
The OpenCms user context to use for resolving macros.protected javax.servlet.jsp.PageContext
The JSP's page context to use for resolving macros.protected boolean
Indicates if unresolved macros should be kept "as is" or replaced by an empty String.protected CmsMessages
The messages resource bundle to resolve localized keys with.The request parameter map, used for better compatibility with multi part requests.protected String
The resource name to use for resolving macros.The "magic" commands wrapped in a List.Fields inherited from interface org.opencms.util.I_CmsMacroResolver
MACRO_DELIMITER, MACRO_DELIMITER_OLD, MACRO_END, MACRO_END_OLD, MACRO_START, MACRO_START_OLD
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDynamicMacro
(String name, org.apache.commons.collections.Factory factory) Adds a macro whose value will be dynamically generated at macro resolution time.void
Adds a customized macro to this macro resolver.static void
copyAndResolveMacro
(CmsObject cms, String source, String destination, Map<String, String> keyValue, boolean adjustLinks) Copies resources, adjust internal links (if adjustLinks==true) and resolves macros (if keyValue map is set).static void
copyAndResolveMacro
(CmsObject cms, String source, String destination, Map<String, String> keyValue, boolean adjustLinks, CmsResource.CmsResourceCopyMode copyMode) Copies resources, adjust internal links (if adjustLinks==true) and resolves macros (if keyValue map is set).static void
copyAndResolveMacro
(CmsObject cms, String source, String destination, Map<String, String> keyValue, boolean adjustLinks, CmsResource.CmsResourceCopyMode copyMode, I_CmsReport report) Copies resources, adjust internal links (if adjustLinks==true) and resolves macros (if keyValue map is set).static String
formatMacro
(String input) Adds macro delimiters to the given input, for examplekey
becomes%(key)
.getBundleMapFromResources
(Properties resourceBundle, CmsResource descriptor, CmsObject clonedCms) Reads a bundle (key, value, descriptor) from Descriptor Resource and property resource.getMacroValue
(String macro) Resolves a single macro to the macro value, returnsnull
if the macro could not be resolved.boolean
Returnstrue
if macros that could not be resolved are kept "as is" in the input String,false
if they are replaced by an empty String.static boolean
Returnstrue
if the given input String if formatted like a macro, that is it starts with
and ends withI_CmsMacroResolver.MACRO_DELIMITER_OLD
+I_CmsMacroResolver.MACRO_START_OLD
.I_CmsMacroResolver.MACRO_END_OLD
static boolean
Returnstrue
if the given input String is a macro equal to the given macro name.static String
localizedKeyMacro
(String keyName, Object[] params) Returns a macro for the given localization key with the given parameters.static CmsMacroResolver
Factory method to create a newCmsMacroResolver
instance.static I_CmsMacroResolver
Returns a new macro resolver that loads message keys from the workplace bundle in the user setting's language.resolveMacros
(String input) Resolves the macros in the given input.static String
resolveMacros
(String input, CmsObject cms, CmsMessages messages) Resolves the macros in the given input using the provided parameters.static String
resolveMacros
(String input, I_CmsMacroResolver resolver) Resolves macros in the provided input String using the given macro resolver.setAdditionalMacros
(Map<String, String> additionalMacros) Provides a set of additional macros to this macro resolver.setCmsObject
(CmsObject cms) Provides an OpenCms user context to this macro resolver, required to resolve certain macros.setJspPageContext
(javax.servlet.jsp.PageContext jspPageContext) Provides a JSP page context to this macro resolver, required to resolve certain macros.setKeepEmptyMacros
(boolean keepEmptyMacros) Controls of macros that can't be resolved are left unchanged in the input, or are replaced with an empty String.setMessages
(CmsMessages messages) Provides a set of
to this macro resolver, required to resolve localized macros.CmsMessages
void
setParameterMap
(Map<String, String[]> parameterMap) Sets the parameter map.setResourceName
(String resourceName) Provides a resource name to this macro resolver, required to resolve certain macros.static String
stripMacro
(String input) Strips the macro delimiters from the given input, for example%(key)
or${key}
becomeskey
.Returns a function which applies the macro substitution of this resolver to its argument.
-
Field Details
-
KEY_ATTRIBUTE
The prefix indicating that the key represents an OpenCms runtime attribute.- See Also:
-
KEY_CONTEXT_PATH
Key used to specify the context path as macro value.- See Also:
-
KEY_CURRENT_ORGUNIT_DESCRIPTION
Key used to specify the description of the current organizational unit as macro value.- See Also:
-
KEY_CURRENT_ORGUNIT_FQN
Key used to specify the full qualified name of the current organizational unit as macro value.- See Also:
-
KEY_CURRENT_TIME
Key used to specify the current time as macro value.- See Also:
-
KEY_CURRENT_USER_CITY
Key used to specify the city of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_COUNTRY
Key used to specify the country of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_DISPLAYNAME
Key used to specify the display name of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_EMAIL
Key used to specify the email address of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_FIRSTNAME
Key used to specify the first name of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_FULLNAME
Key used to specify the full name of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_INSTITUTION
Key used to specify the institution of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_LASTLOGIN
Key used to specify the last login date of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_LASTNAME
Key used to specify the last name of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_NAME
Key used to specify the user name of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_STREET
Key used to specify the street of the current user as macro value.- See Also:
-
KEY_CURRENT_USER_ZIP
Key used to specify the zip code of the current user as macro value.- See Also:
-
KEY_LOCALIZED_PREFIX
Key prefix used to specify the value of a localized key as macro value.- See Also:
-
KEY_OPENCMS
Identifier for "magic" parameter names.- See Also:
-
KEY_PAGE_CONTEXT
The prefix indicating that the key represents a page context object.- See Also:
-
KEY_PARAM
Prefix for getting parameters from the CmsParameterStore.- See Also:
-
KEY_PROJECT_ID
Key used to specify the project id as macro value.- See Also:
-
KEY_PROPERTY
The prefix indicating that the key represents a property to be read on the current request URI.- See Also:
-
KEY_PROPERTY_ELEMENT
The prefix indicating that the key represents a property to be read on the current element.- See Also:
-
KEY_RANDOM_ID
Key used to specify a random id as macro value.- See Also:
-
KEY_REQUEST_ENCODING
Key used to specify the request encoding as macro value.- See Also:
-
KEY_REQUEST_FOLDER
Key used to specify the folder of the request URI as macro value.- See Also:
-
KEY_REQUEST_LOCALE
Key user to specify the request locale as macro value.- See Also:
-
KEY_REQUEST_PARAM
The prefix indicating that the key represents a HTTP request parameter.- See Also:
-
KEY_REQUEST_SITEROOT
Key used to specify the request site root as macro value.- See Also:
-
KEY_REQUEST_URI
Key used to specify the request uri as macro value.- See Also:
-
KEY_VALIDATION_PATH
Key used to specify the validation path as macro value.- See Also:
-
KEY_VALIDATION_REGEX
Key used to specify the validation regex as macro value.- See Also:
-
KEY_VALIDATION_VALUE
Key used to specify the validation value as macro value.- See Also:
-
KEY_SITEMAP_ATTRIBUTE
Key for accessing sitemap attributes.- See Also:
-
VALUE_NAMES
The "magic" commands wrapped in a List. -
m_additionalMacros
A map of additional values provided by the calling class. -
m_cms
The OpenCms user context to use for resolving macros. -
m_jspPageContext
The JSP's page context to use for resolving macros. -
m_keepEmptyMacros
Indicates if unresolved macros should be kept "as is" or replaced by an empty String. -
m_messages
The messages resource bundle to resolve localized keys with. -
m_parameterMap
The request parameter map, used for better compatibility with multi part requests. -
m_resourceName
The resource name to use for resolving macros.
-
-
Constructor Details
-
CmsMacroResolver
public CmsMacroResolver()
-
-
Method Details
-
copyAndResolveMacro
public static void copyAndResolveMacro(CmsObject cms, String source, String destination, Map<String, String> keyValue, boolean adjustLinks) throws CmsExceptionCopies resources, adjust internal links (if adjustLinks==true) and resolves macros (if keyValue map is set).- Parameters:
cms
- CmsObjectsource
- pathdestination
- pathkeyValue
- map to be used for macro resolveradjustLinks
- boolean, true means internal links get adjusted.- Throws:
CmsException
- exception
-
copyAndResolveMacro
public static void copyAndResolveMacro(CmsObject cms, String source, String destination, Map<String, String> keyValue, boolean adjustLinks, CmsResource.CmsResourceCopyMode copyMode) throws CmsExceptionCopies resources, adjust internal links (if adjustLinks==true) and resolves macros (if keyValue map is set).- Parameters:
cms
- CmsObjectsource
- pathdestination
- pathkeyValue
- map to be used for macro resolveradjustLinks
- boolean, true means internal links get adjusted.copyMode
- copyMode- Throws:
CmsException
- exception
-
copyAndResolveMacro
public static void copyAndResolveMacro(CmsObject cms, String source, String destination, Map<String, String> keyValue, boolean adjustLinks, CmsResource.CmsResourceCopyMode copyMode, I_CmsReport report) throws CmsExceptionCopies resources, adjust internal links (if adjustLinks==true) and resolves macros (if keyValue map is set).- Parameters:
cms
- CmsObjectsource
- pathdestination
- pathkeyValue
- map to be used for macro resolveradjustLinks
- boolean, true means internal links get adjusted.copyMode
- copy Modereport
- report to write logs to- Throws:
CmsException
- exception
-
formatMacro
Adds macro delimiters to the given input, for examplekey
becomes%(key)
.- Parameters:
input
- the input to format as a macro- Returns:
- the input formatted as a macro
-
getBundleMapFromResources
public static Map<String,String[]> getBundleMapFromResources(Properties resourceBundle, CmsResource descriptor, CmsObject clonedCms) throws CmsXmlException, CmsException Reads a bundle (key, value, descriptor) from Descriptor Resource and property resource.- Parameters:
resourceBundle
- property resourcedescriptor
- resourceclonedCms
- cms instance- Returns:
- Map <key, [value, descriptor]>
- Throws:
CmsXmlException
- exceptionCmsException
- exception
-
isMacro
Returnstrue
if the given input String if formatted like a macro, that is it starts with
and ends withI_CmsMacroResolver.MACRO_DELIMITER_OLD
+I_CmsMacroResolver.MACRO_START_OLD
.I_CmsMacroResolver.MACRO_END_OLD
- Parameters:
input
- the input to check for a macro- Returns:
true
if the given input String if formatted like a macro
-
isMacro
Returnstrue
if the given input String is a macro equal to the given macro name.- Parameters:
input
- the input to check for a macromacroName
- the macro name to check for- Returns:
true
if the given input String is a macro equal to the given macro name
-
localizedKeyMacro
Returns a macro for the given localization key with the given parameters.- Parameters:
keyName
- the name of the localized keyparams
- the optional parameter array- Returns:
- a macro for the given localization key with the given parameters
-
newInstance
Factory method to create a newCmsMacroResolver
instance.- Returns:
- a new instance of a
CmsMacroResolver
-
newWorkplaceLocaleResolver
Returns a new macro resolver that loads message keys from the workplace bundle in the user setting's language.- Parameters:
cms
- the CmsObject.- Returns:
- a new macro resolver with messages from the workplace bundle in the current users locale.
-
resolveMacros
Resolves the macros in the given input using the provided parameters.A macro in the form
%(key)
or${key}
in the content is replaced with it's assigned value returned by the
method of the givenI_CmsMacroResolver.getMacroValue(String)
instance.I_CmsMacroResolver
If a macro is found that can not be mapped to a value by the given macro resolver, it is left untouched in the input.
- Parameters:
input
- the input in which to resolve the macroscms
- the OpenCms user context to use when resolving macrosmessages
- the message resource bundle to use when resolving macros- Returns:
- the input with the macros resolved
-
resolveMacros
Resolves macros in the provided input String using the given macro resolver.A macro in the form
%(key)
or${key}
in the content is replaced with it's assigned value returned by the
method of the givenI_CmsMacroResolver.getMacroValue(String)
instance.I_CmsMacroResolver
If a macro is found that can not be mapped to a value by the given macro resolver,
controls if the macro is replaced by an empty String, or is left untouched in the input.I_CmsMacroResolver.isKeepEmptyMacros()
- Parameters:
input
- the input in which to resolve the macrosresolver
- the macro resolver to use- Returns:
- the input with all macros resolved
-
stripMacro
Strips the macro delimiters from the given input, for example%(key)
or${key}
becomeskey
.In case the input is not a macro,
null
is returned.- Parameters:
input
- the input to strip- Returns:
- the macro stripped from the input, or
null
-
addDynamicMacro
Adds a macro whose value will be dynamically generated at macro resolution time.The value will be generated for each occurence of the macro in a string.
- Parameters:
name
- the name of the macrofactory
- the macro value generator
-
addMacro
Adds a customized macro to this macro resolver.- Parameters:
key
- the macro to addvalue
- the value to return if the macro is encountered
-
getMacroValue
Description copied from interface:I_CmsMacroResolver
Resolves a single macro to the macro value, returnsnull
if the macro could not be resolved.- Specified by:
getMacroValue
in interfaceI_CmsMacroResolver
- Parameters:
macro
- the macro to resolve- Returns:
- the resolved macro or
null
if the macro could not be resolved - See Also:
-
isKeepEmptyMacros
Description copied from interface:I_CmsMacroResolver
Returnstrue
if macros that could not be resolved are kept "as is" in the input String,false
if they are replaced by an empty String.- Specified by:
isKeepEmptyMacros
in interfaceI_CmsMacroResolver
- Returns:
true
if macros that could not be resolved are kept "as is" in the input String,false
if they are replaced by an empty String- See Also:
-
resolveMacros
Resolves the macros in the given input.Calls
until no more macros can be resolved in the input. This way "nested" macros in the input are resolved as well.resolveMacros(String)
- Specified by:
resolveMacros
in interfaceI_CmsMacroResolver
- Parameters:
input
- the input to resolve the macros in- Returns:
- the input with all macros resolved
- See Also:
-
setAdditionalMacros
Provides a set of additional macros to this macro resolver.Macros added with
addMacro(String, String)
are added to the same set- Parameters:
additionalMacros
- the additional macros to add- Returns:
- this instance of the macro resolver
-
setCmsObject
Provides an OpenCms user context to this macro resolver, required to resolve certain macros.- Parameters:
cms
- the OpenCms user context- Returns:
- this instance of the macro resolver
-
setJspPageContext
Provides a JSP page context to this macro resolver, required to resolve certain macros.- Parameters:
jspPageContext
- the JSP page context to use- Returns:
- this instance of the macro resolver
-
setKeepEmptyMacros
Controls of macros that can't be resolved are left unchanged in the input, or are replaced with an empty String.- Parameters:
keepEmptyMacros
- the replacement flag to use- Returns:
- this instance of the macro resolver
- See Also:
-
setMessages
Provides a set of
to this macro resolver, required to resolve localized macros.CmsMessages
- Parameters:
messages
- the message resource bundle to use- Returns:
- this instance of the macro resolver
-
setParameterMap
Sets the parameter map.- Parameters:
parameterMap
- the parameter map to set
-
setResourceName
Provides a resource name to this macro resolver, required to resolve certain macros.- Parameters:
resourceName
- the resource name to use- Returns:
- this instance of the macro resolver
-
toFunction
Returns a function which applies the macro substitution of this resolver to its argument.- Returns:
- a function performing string substitution with this resolver
-