/** * Factory method to create a new {@link CmsMacroResolver} instance.<p> * * @return a new instance of a {@link CmsMacroResolver} */ public static CmsMacroResolver newInstance() { return new CmsMacroResolver(); }
/** * Creates a new A_CmsNotification.<p> * * @param cms the cms object to use * @param receiver the receiver of the notification */ public A_CmsNotification(CmsObject cms, CmsUser receiver) { m_cms = cms; m_receiver = receiver; m_macroResolver = new CmsMacroResolver(); }
/** * Factory method to create a new {@link CmsMacroResolver} instance.<p> * * @return a new instance of a {@link CmsMacroResolver} */ public static CmsMacroResolver newInstance() { return new CmsMacroResolver(); }
/** * Creates a new A_CmsNotification.<p> * * @param cms the cms object to use * @param receiver the receiver of the notification */ public A_CmsNotification(CmsObject cms, CmsUser receiver) { m_cms = cms; m_receiver = receiver; m_macroResolver = new CmsMacroResolver(); m_macroResolver.setCmsObject(cms); }
/** * Resolves the macros in the given input using the provided parameters.<p> * * A macro in the form <code>%(key)</code> or <code>${key}</code> in the content is replaced with it's assigned value * returned by the <code>{@link I_CmsMacroResolver#getMacroValue(String)}</code> method of the given * <code>{@link I_CmsMacroResolver}</code> instance.<p> * * 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.<p> * * @param input the input in which to resolve the macros * @param cms the OpenCms user context to use when resolving macros * @param messages the message resource bundle to use when resolving macros * * @return the input with the macros resolved */ public static String resolveMacros(String input, CmsObject cms, CmsMessages messages) { CmsMacroResolver resolver = new CmsMacroResolver(); resolver.m_cms = cms; resolver.m_messages = messages; resolver.m_keepEmptyMacros = true; return resolver.resolveMacros(input); }
/** * Resolves the macros in the given input using the provided parameters.<p> * * A macro in the form <code>%(key)</code> or <code>${key}</code> in the content is replaced with it's assigned value * returned by the <code>{@link I_CmsMacroResolver#getMacroValue(String)}</code> method of the given * <code>{@link I_CmsMacroResolver}</code> instance.<p> * * 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.<p> * * @param input the input in which to resolve the macros * @param cms the OpenCms user context to use when resolving macros * @param messages the message resource bundle to use when resolving macros * * @return the input with the macros resolved */ public static String resolveMacros(String input, CmsObject cms, CmsMessages messages) { CmsMacroResolver resolver = new CmsMacroResolver(); resolver.m_cms = cms; resolver.m_messages = messages; resolver.m_keepEmptyMacros = true; return resolver.resolveMacros(input); }
/** * Returns the description of this organizational unit.<p> * * @param locale the locale * * @return the description of this organizational unit */ public String getDescription(Locale locale) { CmsMacroResolver macroResolver = new CmsMacroResolver(); macroResolver.setMessages(org.opencms.db.generic.Messages.get().getBundle(locale)); return macroResolver.resolveMacros(m_description); }
/** * Returns the description of this organizational unit.<p> * * @param locale the locale * * @return the description of this organizational unit */ public String getDescription(Locale locale) { CmsMacroResolver macroResolver = new CmsMacroResolver(); macroResolver.setMessages(org.opencms.db.generic.Messages.get().getBundle(locale)); return macroResolver.resolveMacros(m_description); }
/** * Returns the description of this organizational unit.<p> * * @param locale the locale * * @return the description of this organizational unit */ public String getDescription(Locale locale) { CmsMacroResolver macroResolver = new CmsMacroResolver(); macroResolver.setMessages(org.opencms.db.generic.Messages.get().getBundle(locale)); return macroResolver.resolveMacros(m_description); }
/** * @see org.opencms.xml.containerpage.I_CmsFormatterBean#getNiceName(Locale) */ @Override public String getNiceName(Locale locale) { if (locale == null) { return m_niceName; } CmsMacroResolver resolver = new CmsMacroResolver(); resolver.setMessages(OpenCms.getWorkplaceManager().getMessages(locale)); return resolver.resolveMacros(m_niceName); }
/** * @see org.opencms.ui.contextmenu.I_CmsContextMenuItem#getTitle(java.util.Locale) */ public String getTitle(Locale locale) { CmsMacroResolver resolver = new CmsMacroResolver(); resolver.setMessages(OpenCms.getWorkplaceManager().getMessages(locale)); if (m_title == null) { return ""; } return resolver.resolveMacros(m_title); }
/** * Returns the description of this organizational unit.<p> * * @param locale the locale * * @return the description of this organizational unit */ public String getDescription(Locale locale) { CmsMacroResolver macroResolver = new CmsMacroResolver(); macroResolver.setMessages(org.opencms.db.generic.Messages.get().getBundle(locale)); return macroResolver.resolveMacros(m_description); }
/** * Returns the description of this organizational unit.<p> * * @param locale the locale * * @return the description of this organizational unit */ public String getDescription(Locale locale) { CmsMacroResolver macroResolver = new CmsMacroResolver(); macroResolver.setMessages(org.opencms.db.generic.Messages.get().getBundle(locale)); return macroResolver.resolveMacros((String)getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_DESCRIPTION)); }
/** * Returns the description of this organizational unit.<p> * * @param locale the locale * * @return the description of this organizational unit */ public String getDescription(Locale locale) { CmsMacroResolver macroResolver = new CmsMacroResolver(); macroResolver.setMessages(org.opencms.db.generic.Messages.get().getBundle(locale)); return macroResolver.resolveMacros((String)getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_DESCRIPTION)); }
/** * 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; }
/** * Uses the currently set locale to resolve localization macros in the input string using workplace message bundles.<p> * * @param baseString the string to localize * * @return the localized string */ public static String localizeString(String baseString) { if (baseString == null) { return null; } CmsWorkplaceMessages wpMessages = OpenCms.getWorkplaceManager().getMessages(A_CmsUI.get().getLocale()); CmsMacroResolver resolver = new CmsMacroResolver(); resolver.setMessages(wpMessages); String result = resolver.resolveMacros(baseString); return result; }
/** * Creates a comparator that will resolve the {@link CmsResource} related values with the given macro * expression. * <p> * * @param cms will be cloned and used for macro - resolution * @param comparatorMacro the macro to use to find the resource related strings to compare. * * @throws CmsException if something goes wrong * * @see CmsMacroResolver */ CmsResourceSelectWidgetOptionComparator(CmsObject cms, String comparatorMacro) throws CmsException { if (CmsStringUtil.isEmpty(comparatorMacro)) { m_comparatorMacro = I_CmsMacroResolver.MACRO_DELIMITER + "" + I_CmsMacroResolver.MACRO_START + "opencms.filename)"; } else { m_comparatorMacro = comparatorMacro; } m_macroCmsObjectInner = OpenCms.initCmsObject(cms); m_macroCmsObjectInner.getRequestContext().setSiteRoot("/"); m_macroResolverInner = new CmsMacroResolver(); m_macroResolverInner.setCmsObject(m_macroCmsObjectInner); }
/** * 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 a new macro resolver that loads message keys from the workplace bundle in the user setting's language. * @param cms the CmsObject. * @return a new macro resolver with messages from the workplace bundle in the current users locale. */ public static I_CmsMacroResolver newWorkplaceLocaleResolver(final CmsObject cms) { // Resolve macros in the property configuration CmsMacroResolver resolver = new CmsMacroResolver(); resolver.setCmsObject(cms); CmsUserSettings userSettings = new CmsUserSettings(cms.getRequestContext().getCurrentUser()); CmsMultiMessages multimessages = new CmsMultiMessages(userSettings.getLocale()); multimessages.addMessages(OpenCms.getWorkplaceManager().getMessages(userSettings.getLocale())); resolver.setMessages(multimessages); resolver.setKeepEmptyMacros(true); return resolver; }
/** * Returns the Javascript code to use for initializing a Vaadin UI.<p> * * @param cms the CMS context * @param elementId the id of the DOM element in which to initialize the UI * @param servicePath the UI servlet path * @return the Javascript code to initialize Vaadin * * @throws Exception if something goes wrong */ public static String getBootstrapScript(CmsObject cms, String elementId, String servicePath) throws Exception { String script = BOOTSTRAP_SCRIPT; CmsMacroResolver resolver = new CmsMacroResolver(); String context = OpenCms.getSystemInfo().getContextPath(); String vaadinDir = CmsStringUtil.joinPaths(context, "VAADIN/"); String vaadinVersion = Version.getFullVersion(); String vaadinServlet = CmsStringUtil.joinPaths(context, servicePath); String vaadinBootstrap = CmsStringUtil.joinPaths(context, "VAADIN/vaadinBootstrap.js"); resolver.addMacro("vaadinDir", vaadinDir); resolver.addMacro("vaadinVersion", vaadinVersion); resolver.addMacro("elementId", elementId); resolver.addMacro("vaadinServlet", vaadinServlet); resolver.addMacro("vaadinBootstrap", vaadinBootstrap); script = resolver.resolveMacros(script); return script; }