Search in sources :

Example 1 with CmsMessages

use of org.opencms.i18n.CmsMessages in project opencms-core by alkacon.

the class CmsExternalLinksValidationResult method toHtml.

/**
 * Returns a Html representation of this pointer link validation result.<p>
 *
 * @param locale the Locale to display the result in
 *
 * @return a Html representation of this external link validation result
 */
public String toHtml(Locale locale) {
    CmsMessages mg = Messages.get().getBundle(locale);
    if (m_brokenLinks.size() > 0) {
        StringBuffer result = new StringBuffer(1024);
        Iterator<Entry<String, String>> brokenLinks = m_brokenLinks.entrySet().iterator();
        result.append(mg.key(Messages.GUI_LINK_VALIDATION_RESULTS_INTRO_1, new Object[] { m_validationDate })).append("<ul>");
        while (brokenLinks.hasNext()) {
            Entry<String, String> link = brokenLinks.next();
            String linkPath = link.getKey();
            String linkUrl = link.getValue();
            String msg = mg.key(Messages.GUI_LINK_POINTING_TO_2, new Object[] { linkPath, linkUrl });
            result.append("<li>").append(msg).append("</li>");
        }
        return result.append("</ul>").toString();
    } else {
        return mg.key(Messages.GUI_LINK_VALIDATION_RESULTS_ALL_VALID_1, new Object[] { m_validationDate });
    }
}
Also used : Entry(java.util.Map.Entry) CmsMessages(org.opencms.i18n.CmsMessages)

Example 2 with CmsMessages

use of org.opencms.i18n.CmsMessages in project opencms-core by alkacon.

the class CmsPublishNotification method generateHtmlMsg.

/**
 * @see org.opencms.notification.A_CmsNotification#generateHtmlMsg()
 */
@Override
protected String generateHtmlMsg() {
    StringBuffer buffer = new StringBuffer();
    CmsMessages messages = Messages.get().getBundle(getLocale());
    // add warnings to the notification
    if (m_report.hasWarning()) {
        buffer.append("<b>");
        buffer.append(messages.key(Messages.GUI_PUBLISH_WARNING_HEADER_0));
        buffer.append("</b><br/>\n");
        appendList(buffer, m_report.getWarnings());
        buffer.append("<br/>\n");
    }
    // add errors to the notification
    if (m_report.hasError()) {
        buffer.append("<b>");
        buffer.append(messages.key(Messages.GUI_PUBLISH_ERROR_HEADER_0));
        buffer.append("</b><br/>\n");
        appendList(buffer, m_report.getErrors());
        buffer.append("<br/>\n");
    }
    return buffer.toString();
}
Also used : CmsMessages(org.opencms.i18n.CmsMessages)

Example 3 with CmsMessages

use of org.opencms.i18n.CmsMessages in project opencms-core by alkacon.

the class A_CmsDirectEditProvider method init.

/**
 * @see org.opencms.workplace.editors.directedit.I_CmsDirectEditProvider#init(org.opencms.file.CmsObject, org.opencms.workplace.editors.directedit.CmsDirectEditMode, java.lang.String)
 */
public void init(CmsObject cms, CmsDirectEditMode mode, String fileName) {
    m_cms = cms;
    m_fileName = fileName;
    if (CmsStringUtil.isEmpty(m_fileName)) {
        m_fileName = INCLUDE_FILE_DEFAULT;
    }
    m_mode = mode != null ? mode : CmsDirectEditMode.AUTO;
    m_rnd = new Random();
    CmsUserSettings settings = new CmsUserSettings(cms);
    m_messages = new CmsMessages(org.opencms.workplace.editors.Messages.get().getBundleName(), settings.getLocale());
    m_editButtonStyle = settings.getEditorButtonStyle();
}
Also used : Random(java.util.Random) CmsUserSettings(org.opencms.db.CmsUserSettings) CmsMessages(org.opencms.i18n.CmsMessages)

Example 4 with CmsMessages

use of org.opencms.i18n.CmsMessages in project opencms-core by alkacon.

the class CmsWorkplaceMessages method collectModuleMessages.

/**
 * Gathers all localization files for the workplace from the different modules.<p>
 *
 * For a module named "my.module.name" the locale file must be named
 * "my.module.name.workplace" or "my.module.name.messages" and
 * be located in the classpath so that the resource loader can find it.<p>
 *
 * @param locale the selected locale
 *
 * @return an initialized set of module messages
 */
private static List<CmsMessages> collectModuleMessages(Locale locale) {
    // create a new list and add the base bundle
    ArrayList<CmsMessages> result = new ArrayList<CmsMessages>();
    // ////////// iterate over all registered modules ////////////////
    Set<String> names = new HashSet<String>();
    Set<String> modules = OpenCms.getModuleManager().getModuleNames();
    if (modules != null) {
        names.addAll(modules);
    }
    // use service loader to get additional bundle names
    Iterator<I_CmsWorkplaceMessageBundleProvider> providers = ServiceLoader.load(I_CmsWorkplaceMessageBundleProvider.class).iterator();
    while (providers.hasNext()) {
        try {
            I_CmsWorkplaceMessageBundleProvider provider = providers.next();
            names.addAll(provider.getMessageBundleNames());
        } catch (Throwable t) {
            LOG.error("Error loading workplace messages bundle names from classpath.", t);
        }
    }
    // iterate all module names
    for (String baseName : names) {
        // ////////// collect the workplace.properties ////////////////
        // this should result in a name like "my.module.name.workplace"
        String bundleName = baseName + PREFIX_BUNDLE_WORKPLACE;
        // try to load a bundle with the module names
        CmsMessages msg = new CmsMessages(bundleName, locale);
        // bundle was loaded, add to list of bundles
        if (msg.isInitialized()) {
            result.add(msg);
        }
        // ////////// collect the messages.properties ////////////////
        // this should result in a name like "my.module.name.messages"
        bundleName = baseName + PREFIX_BUNDLE_MESSAGES;
        // try to load a bundle with the module names
        msg = new CmsMessages(bundleName, locale);
        // bundle was loaded, add to list of bundles
        if (msg.isInitialized()) {
            result.add(msg);
        }
    }
    // ////////// collect additional core packages ////////////////
    I_CmsMessageBundle[] coreMsgs = A_CmsMessageBundle.getOpenCmsMessageBundles();
    for (int i = 0; i < coreMsgs.length; i++) {
        I_CmsMessageBundle bundle = coreMsgs[i];
        result.add(bundle.getBundle(locale));
    }
    // ///////// collect bundles configured in module configurations ////////
    if (OpenCms.getADEManager().isInitialized()) {
        Set<String> bundleNames = OpenCms.getADEManager().getConfiguredWorkplaceBundles();
        for (String bundleName : bundleNames) {
            CmsMessages msg = new CmsMessages(bundleName, locale);
            if (msg.isInitialized()) {
                result.add(msg);
            }
        }
    }
    return result;
}
Also used : I_CmsMessageBundle(org.opencms.i18n.I_CmsMessageBundle) CmsMessages(org.opencms.i18n.CmsMessages) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 5 with CmsMessages

use of org.opencms.i18n.CmsMessages in project opencms-core by alkacon.

the class CmsListExplorerFrameset method dialogTitle.

/**
 * @see org.opencms.workplace.tools.CmsToolDialog#dialogTitle()
 */
@Override
public String dialogTitle() {
    StringBuffer html = new StringBuffer(512);
    String toolPath = getCurrentToolPath();
    String parentPath = getParentPath();
    String rootKey = getToolManager().getCurrentRoot(this).getKey();
    CmsTool parentTool = getToolManager().resolveAdminTool(rootKey, parentPath);
    String upLevelLink = CmsToolManager.linkForToolPath(getJsp(), parentPath, parentTool.getHandler().getParameters(this));
    String listLevelLink = CmsToolManager.linkForToolPath(getJsp(), toolPath, getToolManager().resolveAdminTool(rootKey, toolPath).getHandler().getParameters(this));
    listLevelLink = CmsRequestUtil.appendParameter(listLevelLink, A_CmsListExplorerDialog.PARAM_SHOW_EXPLORER, Boolean.FALSE.toString());
    String parentName = getToolManager().resolveAdminTool(rootKey, parentPath).getHandler().getName();
    html.append(getToolManager().generateNavBar(toolPath, this));
    // check if page switch needed
    int items = 0;
    try {
        items = getSettings().getCollector().getResults(getCms()).size();
    } catch (CmsException e) {
        // ignore
        LOG.error(e.getLocalizedMessage(), e);
    }
    int size = (int) Math.ceil((double) items / getSettings().getUserSettings().getExplorerFileEntries());
    // build title
    html.append("<div class='screenTitle'>\n");
    html.append("\t<table width='100%' cellspacing='0'>\n");
    html.append("\t\t<tr>\n");
    html.append("\t\t\t<td>\n");
    html.append(getAdminTool().getHandler().getName());
    html.append("\n\t\t\t</td>\n");
    html.append("\t\t\t<td class='uplevel'>\n");
    html.append("<form name='title-form' method='post' target='_parent' action='");
    html.append(getJsp().link(A_CmsListExplorerDialog.PATH_EXPLORER_LIST)).append("'>\n");
    html.append(getFormContent());
    // if page switch needed
    if (size > 1) {
        html.append("<select name='").append(PARAM_PAGE);
        html.append("' class='location' onchange='this.form.submit()'>\n");
        html.append(CmsHtmlList.htmlPageSelector(size, getSettings().getUserSettings().getExplorerFileEntries(), items, getSettings().getExplorerPage(), getLocale()));
        html.append("</select>\n");
    }
    // list view button
    CmsMessages messages = Messages.get().getBundle(getLocale());
    html.append(A_CmsHtmlIconButton.defaultButtonHtml(CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT, "id-list-switch", messages.key(Messages.GUI_LIST_ACTION_LIST_SWITCH_NAME_0), messages.key(Messages.GUI_LIST_ACTION_LIST_SWITCH_HELP_0), true, "list/list.png", null, "openPage('" + listLevelLink + "');"));
    html.append("\n");
    // uplevel button only if needed
    if (!toolPath.equals(getParentPath())) {
        html.append(A_CmsHtmlIconButton.defaultButtonHtml(CmsHtmlIconButtonStyleEnum.SMALL_ICON_TEXT, "id-up-level", org.opencms.workplace.tools.Messages.get().getBundle(getLocale()).key(org.opencms.workplace.tools.Messages.GUI_ADMIN_VIEW_UPLEVEL_0), parentName, true, "admin/images/up.png", null, "openPage('" + upLevelLink + "');"));
    }
    html.append("</form>");
    html.append("\n\t\t\t</td>\n");
    html.append("\t\t</tr>\n");
    html.append("\t</table>\n");
    html.append("</div>\n");
    String code = html.toString().replaceAll("openPage\\('([^']+)'\\)", "openPageIn('$1', parent)");
    return CmsToolMacroResolver.resolveMacros(code, this);
}
Also used : CmsException(org.opencms.main.CmsException) CmsMessages(org.opencms.i18n.CmsMessages) CmsTool(org.opencms.workplace.tools.CmsTool)

Aggregations

CmsMessages (org.opencms.i18n.CmsMessages)48 CmsObject (org.opencms.file.CmsObject)11 CmsException (org.opencms.main.CmsException)11 Locale (java.util.Locale)9 ArrayList (java.util.ArrayList)7 CmsResource (org.opencms.file.CmsResource)7 Iterator (java.util.Iterator)4 I_CmsResourceType (org.opencms.file.types.I_CmsResourceType)4 CmsMultiMessages (org.opencms.i18n.CmsMultiMessages)4 HashSet (java.util.HashSet)3 List (java.util.List)3 CmsADEConfigData (org.opencms.ade.configuration.CmsADEConfigData)3 CmsUser (org.opencms.file.CmsUser)3 CmsExplorerTypeSettings (org.opencms.workplace.explorer.CmsExplorerTypeSettings)3 CmsXmlContentDefinition (org.opencms.xml.CmsXmlContentDefinition)3 CmsXmlEntityResolver (org.opencms.xml.CmsXmlEntityResolver)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2