/** * Adds a new macro to the used macro resolver. Macros are used for the xml * content file. * * @param key The key of the macro. * @param value The value of the macro. */ public void addMacro(String key, String value) { m_macroResolver.addMacro(key, value); }
/** * Adds a new macro to the used macro resolver. Macros are used for the xml * content file. * * @param key The key of the macro. * @param value The value of the macro. */ public void addMacro(String key, String value) { m_macroResolver.addMacro(key, value); }
/** * Replaces the macros in the given message.<p> * * @param msg the message in which the macros are replaced * @param contentLocale the locale of the content that is currently decorated * * @return the message with the macros replaced */ private String replaceMacros(String msg, String contentLocale) { CmsMacroResolver resolver = CmsMacroResolver.newInstance(); resolver.addMacro(MACRO_DECORATION, m_decoration); resolver.addMacro(MACRO_DECORATIONKEY, m_decorationKey); if (m_locale != null) { resolver.addMacro(MACRO_LOCALE, m_locale.toString()); if (!contentLocale.equals(m_locale.toString())) { resolver.addMacro(MACRO_LANGUAGE, "lang=\"" + m_locale.toString() + "\""); } } return resolver.resolveMacros(msg); }
/** * Replaces the macros in the given message.<p> * * @param msg the message in which the macros are replaced * @param contentLocale the locale of the content that is currently decorated * * @return the message with the macros replaced */ private String replaceMacros(String msg, String contentLocale) { CmsMacroResolver resolver = CmsMacroResolver.newInstance(); resolver.addMacro(MACRO_DECORATION, m_decoration); resolver.addMacro(MACRO_DECORATIONKEY, m_decorationKey); if (m_locale != null) { resolver.addMacro(MACRO_LOCALE, m_locale.toString()); if (!contentLocale.equals(m_locale.toString())) { resolver.addMacro(MACRO_LANGUAGE, "lang=\"" + m_locale.toString() + "\""); } } return resolver.resolveMacros(msg); }
/** * @see org.opencms.workplace.editors.directedit.CmsDirectEditDefaultProvider#prepareMacroResolverForIncludes(org.opencms.workplace.editors.directedit.CmsDirectEditParams) */ @Override protected CmsMacroResolver prepareMacroResolverForIncludes(CmsDirectEditParams params) { CmsMacroResolver resolver = super.prepareMacroResolverForIncludes(params); resolver.addMacro( "jquery_flydom", readFile("/system/modules/org.opencms.jquery/resources/packed/jquery.flydom.js")); resolver.addMacro( "jquery_dimensions", readFile("/system/modules/org.opencms.jquery/resources/packed/jquery.dimensions.js")); resolver.addMacro("jquery", readFile("/system/modules/org.opencms.jquery/resources/packed/jquery.js")); return resolver; }
/** * Replaces the macros in the given message.<p> * * @param msg the message in which the macros are replaced * @param recipient the recipient in the message * * @return the message with the macros replaced */ private String replaceMacros(String msg, I_CmsNewsletterRecipient recipient) { CmsMacroResolver resolver = CmsMacroResolver.newInstance(); resolver.addMacro(MACRO_USER_FIRSTNAME, recipient.getFirstname()); resolver.addMacro(MACRO_USER_LASTNAME, recipient.getLastname()); resolver.addMacro(MACRO_USER_FULLNAME, recipient.getFullName()); resolver.addMacro(MACRO_USER_EMAIL, recipient.getEmail()); resolver.addMacro( MACRO_SEND_DATE, DateFormat.getDateTimeInstance().format(new Date(System.currentTimeMillis()))); return resolver.resolveMacros(msg); } }
/** * Replaces the macros in the given message.<p> * * @param msg the message in which the macros are replaced * @param recipient the recipient in the message * * @return the message with the macros replaced */ private String replaceMacros(String msg, I_CmsNewsletterRecipient recipient) { CmsMacroResolver resolver = CmsMacroResolver.newInstance(); resolver.addMacro(MACRO_USER_FIRSTNAME, recipient.getFirstname()); resolver.addMacro(MACRO_USER_LASTNAME, recipient.getLastname()); resolver.addMacro(MACRO_USER_FULLNAME, recipient.getFullName()); resolver.addMacro(MACRO_USER_EMAIL, recipient.getEmail()); resolver.addMacro( MACRO_SEND_DATE, DateFormat.getDateTimeInstance().format(new Date(System.currentTimeMillis()))); return resolver.resolveMacros(msg); } }
/** * Creates a macro resolver based on the current users OpenCms context and the provided resource name.<p> * * @param cms the current OpenCms user context * @param resourcename the resource name for macros like {@link A_CmsResourceType#MACRO_RESOURCE_FOLDER_PATH} * * @return a macro resolver based on the current users OpenCms context and the provided resource name */ protected CmsMacroResolver getMacroResolver(CmsObject cms, String resourcename) { CmsMacroResolver result = CmsMacroResolver.newInstance().setCmsObject(cms); if (isFolder() && (!CmsResource.isFolder(resourcename))) { // ensure folder ends with "/" so resourcename = resourcename.concat("/"); } // add special mappings for macros in default properties result.addMacro(MACRO_RESOURCE_ROOT_PATH, cms.getRequestContext().addSiteRoot(resourcename)); result.addMacro(MACRO_RESOURCE_SITE_PATH, resourcename); result.addMacro(MACRO_RESOURCE_FOLDER_PATH, CmsResource.getFolderPath(resourcename)); result.addMacro(MACRO_RESOURCE_FOLDER_PATH_TOUCH, CmsResource.getFolderPath(resourcename)); result.addMacro(MACRO_RESOURCE_PARENT_PATH, CmsResource.getParentFolder(resourcename)); result.addMacro(MACRO_RESOURCE_NAME, CmsResource.getName(resourcename)); return result; }
/** * Creates a macro resolver based on the current users OpenCms context and the provided resource name.<p> * * @param cms the current OpenCms user context * @param resourcename the resource name for macros like {@link A_CmsResourceType#MACRO_RESOURCE_FOLDER_PATH} * * @return a macro resolver based on the current users OpenCms context and the provided resource name */ protected CmsMacroResolver getMacroResolver(CmsObject cms, String resourcename) { CmsMacroResolver result = CmsMacroResolver.newInstance().setCmsObject(cms); if (isFolder() && (!CmsResource.isFolder(resourcename))) { // ensure folder ends with "/" so resourcename = resourcename.concat("/"); } // add special mappings for macros in default properties result.addMacro(MACRO_RESOURCE_ROOT_PATH, cms.getRequestContext().addSiteRoot(resourcename)); result.addMacro(MACRO_RESOURCE_SITE_PATH, resourcename); result.addMacro(MACRO_RESOURCE_FOLDER_PATH, CmsResource.getFolderPath(resourcename)); result.addMacro(MACRO_RESOURCE_FOLDER_PATH_TOUCH, CmsResource.getFolderPath(resourcename)); result.addMacro(MACRO_RESOURCE_PARENT_PATH, CmsResource.getParentFolder(resourcename)); result.addMacro(MACRO_RESOURCE_NAME, CmsResource.getName(resourcename)); return result; }
/** * Returns the substituted value for the given key and arguments from the configuration file.<p> * * @param key the key to get the value for * @param args the arguments that should be substituted * @return the substituted value for the given key and arguments */ protected String getConfigValue(String key, Object[] args) { String value = getConfigValue(key); CmsMacroResolver resolver = CmsMacroResolver.newInstance(); for (int i = 0; i < args.length; i++) { resolver.addMacro(String.valueOf(i), args[i].toString()); } return resolver.resolveMacros(value); }
/** * Returns the substituted value for the given key and arguments from the configuration file.<p> * * @param key the key to get the value for * @param args the arguments that should be substituted * @return the substituted value for the given key and arguments */ protected String getConfigValue(String key, Object[] args) { String value = getConfigValue(key); CmsMacroResolver resolver = CmsMacroResolver.newInstance(); for (int i = 0; i < args.length; i++) { resolver.addMacro(String.valueOf(i), args[i].toString()); } return resolver.resolveMacros(value); }
/** * Prepares the macro resolver which is used to process the included text file.<p> * * @param params the direct edit parameters * * @return the macro resolver */ protected CmsMacroResolver prepareMacroResolverForIncludes(CmsDirectEditParams params) { String closeLink = getLink(params.getLinkForClose()); String deleteLink = getLink(params.getLinkForDelete()); String titleForNew = m_messages.key(Messages.GUI_EDITOR_TITLE_NEW_0); String skinUri = CmsWorkplace.getSkinUri(); // resolve macros in include header CmsMacroResolver resolver = CmsMacroResolver.newInstance(); resolver.addMacro("closeLink", closeLink); resolver.addMacro("deleteLink", deleteLink); resolver.addMacro("titleForNew", titleForNew); resolver.addMacro("skinUri", skinUri); return resolver; } }
/** * Returns the direct edit include HTML to insert in the page beginning.<p> t * * @param params the parameters for the direct edit includes * * @return the direct edit include HTML to insert in the page beginning */ public String getDirectEditIncludes(CmsDirectEditParams params) { String closeLink = getLink(params.getLinkForClose()); String deleteLink = getLink(params.getLinkForDelete()); String titleForNew = m_messages.key(Messages.GUI_EDITOR_TITLE_NEW_0); String skinUri = CmsWorkplace.getSkinUri(); // resolve macros in include header CmsMacroResolver resolver = CmsMacroResolver.newInstance(); resolver.addMacro("closeLink", closeLink); resolver.addMacro("deleteLink", deleteLink); resolver.addMacro("titleForNew", titleForNew); resolver.addMacro("skinUri", skinUri); return resolver.resolveMacros(m_headerInclude); }
/** * @see org.opencms.xml.content.I_CmsXmlContentHandler#getPreview(org.opencms.file.CmsObject, org.opencms.xml.content.CmsXmlContent, java.lang.String) */ public String getPreview(CmsObject cms, CmsXmlContent content, String resourcename) { CmsMacroResolver resolver = CmsMacroResolver.newInstance().setCmsObject(cms); resolver.addMacro(MACRO_PREVIEW_TEMPFILE, resourcename); return resolver.resolveMacros(m_previewLocation); }
/** * @see org.opencms.xml.content.I_CmsXmlContentHandler#getPreview(org.opencms.file.CmsObject, org.opencms.xml.content.CmsXmlContent, java.lang.String) */ public String getPreview(CmsObject cms, CmsXmlContent content, String resourcename) { CmsMacroResolver resolver = CmsMacroResolver.newInstance().setCmsObject(cms); resolver.addMacro(MACRO_PREVIEW_TEMPFILE, resourcename); return resolver.resolveMacros(m_previewLocation); }
/** * Substitutes the ${CONTEXT_NAME} and ${SERVLET_NAME} in a path with the real values.<p> * * @param path the path to substitute * @return path with real context values */ protected String insertContextStrings(String path) { // create a new macro resolver CmsMacroResolver resolver = CmsMacroResolver.newInstance(); // add special mappings for macros resolver.addMacro("CONTEXT_NAME", OpenCms.getSystemInfo().getContextPath()); resolver.addMacro("SERVLET_NAME", OpenCms.getSystemInfo().getServletPath()); // resolve the macros return resolver.resolveMacros(path); }
/** * Substitutes the ${CONTEXT_NAME} and ${SERVLET_NAME} in a path with the real values.<p> * * @param path the path to substitute * @return path with real context values */ protected String insertContextStrings(String path) { // create a new macro resolver CmsMacroResolver resolver = CmsMacroResolver.newInstance(); // add special mappings for macros resolver.addMacro("CONTEXT_NAME", OpenCms.getSystemInfo().getContextPath()); resolver.addMacro("SERVLET_NAME", OpenCms.getSystemInfo().getServletPath()); // resolve the macros return resolver.resolveMacros(path); }
/** * Gets the path to use for the authorization cookie, optionally resolving any macros used.<p> * * @param resolveMacros if true, macros should be resolved * @return the authorization cookie path */ public String getCookiePath(boolean resolveMacros) { String result = m_cookiePath; if (resolveMacros) { CmsMacroResolver resolver = new CmsMacroResolver(); // add special mappings for macros resolver.addMacro("CONTEXT_NAME", OpenCms.getSystemInfo().getContextPath()); resolver.addMacro("SERVLET_NAME", OpenCms.getSystemInfo().getServletPath()); result = resolver.resolveMacros(result); } return result; }
/** * Returns the parameters of the collector with resolved macros.<p> * * @return the parameters of the collector with resolved macros */ public String getParameter() { Locale locale = getRequestContext().getLocale(); String params = m_content.getStringValue(getCmsObject(), NODE_PARAMETER, locale); List links = m_content.getValues(NODE_LINKS, locale); CmsMacroResolver macroResolver = CmsMacroResolver.newInstance(); macroResolver.setKeepEmptyMacros(true); for (int i = 0; i < links.size(); i++) { I_CmsXmlContentValue xmlValue = (I_CmsXmlContentValue)links.get(i); String value = xmlValue.getStringValue(getCmsObject()); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value)) { StringBuffer macro = new StringBuffer(10); macro.append(MACRO_LINK_PREFIX).append(i + 1); macroResolver.addMacro(macro.toString(), getRequestContext().removeSiteRoot(value)); } } return macroResolver.resolveMacros(params); }
/** * Processes a file path, which may have macros in it, so it can be opened by the XML content editor.<p> * * @param cms the current CMS context * @param res the resource for which the context menu option has been selected * @param pathWithMacros the file path which may contain macros * * @return the processed file path */ public static String prepareFileNameForEditor(CmsObject cms, CmsResource res, String pathWithMacros) { String subsite = OpenCms.getADEManager().getSubSiteRoot(cms, res.getRootPath()); CmsMacroResolver resolver = new CmsMacroResolver(); if (subsite != null) { resolver.addMacro("subsite", cms.getRequestContext().removeSiteRoot(subsite)); } String path = resolver.resolveMacros(pathWithMacros).replaceAll("/+", "/"); return path; }