Gets the options for the project selector.<p>

@param cms  the CMS context
@param  locale the locale

@return the options for the project selector
323105
private String getProjectSelectOptions(CmsObject cms, Locale locale) {

        List<CmsProject> allProjects;
        try {
            String ouFqn = "";
            CmsUserSettings settings = new CmsUserSettings(cms);
            if (!settings.getListAllProjects()) {
                ouFqn = cms.getRequestContext().getCurrentUser().getOuFqn();
            }
            allProjects = OpenCms.getOrgUnitManager().getAllAccessibleProjects(
                cms,
                ouFqn,
                settings.getListAllProjects());
        } catch (CmsException e) {
            // should usually never happen
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
            allProjects = Collections.emptyList();
        }

        boolean singleOu = true;
        String ouFqn = null;
        Iterator<CmsProject> itProjects = allProjects.iterator();
        while (itProjects.hasNext()) {
            CmsProject prj = itProjects.next();
            if (prj.isOnlineProject()) {
                // skip the online project
                continue;
            }
            if (ouFqn == null) {
                // set the first ou
                ouFqn = prj.getOuFqn();
            }
            if (!ouFqn.equals(prj.getOuFqn())) {
                // break if one different ou is found
                singleOu = false;
                break;
            }
        }

        int counter = 0;
        StringBuffer resultBuffer = new StringBuffer();
        for (int i = 0, n = allProjects.size(); i < n; i++) {
            CmsProject project = allProjects.get(i);
            String projectName = project.getSimpleName();
            if (!singleOu && !project.isOnlineProject()) {
                try {
                    projectName = projectName
                        + " - "
                        + OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, project.getOuFqn()).getDisplayName(
                            locale);
                } catch (CmsException e) {
                    projectName = projectName + " - " + project.getOuFqn();
                }
            }
            if (counter != 0) {
                resultBuffer.append("|");
            }
            counter++;
            resultBuffer.append(project.getName()).append(":").append(projectName);
        }
        return resultBuffer.toString();
    }
661264
private String generateInfo(CmsObject cms, Locale locale) {

        StringBuffer infoHtml = new StringBuffer(128);
        infoHtml.append("<p>").append(CmsStringUtil.escapeHtml(m_user.getSimpleName())).append("</p>");
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_user.getFirstname())) {
            infoHtml.append(CmsStringUtil.escapeHtml(m_user.getFirstname())).append("&nbsp;");
        }
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_user.getLastname())) {
            infoHtml.append(CmsStringUtil.escapeHtml(m_user.getLastname()));
        }
        infoHtml.append(LINE_BREAK);
        return infoHtml.toString();
    }
592140
public List<I_CmsXmlContentValue> getSimpleValuesBelowPath(String elementPath, Locale locale) {

        List<I_CmsXmlContentValue> result = new ArrayList<I_CmsXmlContentValue>();
        for (I_CmsXmlContentValue value : getValuesByPath(elementPath, locale)) {
            if (value.isSimpleType()) {
                result.add(value);
            } else {
                result.addAll(getAllSimpleSubValues(value));
            }
        }

        return result;
    }
408767
protected String getLabel(Locale locale) {

        return OpenCms.getWorkplaceManager().getMessages(locale).key(m_labelKey);
    }
940822
protected Locale getDefaultLocale(CmsObject cms, String resource) {

        Locale locale = OpenCms.getLocaleManager().getDefaultLocale(cms, resource);
        if (locale == null) {
            List<Locale> locales = OpenCms.getLocaleManager().getAvailableLocales();
            if (locales.size() > 0) {
                locale = locales.get(0);
            } else {
                locale = Locale.ENGLISH;
            }
        }
        return locale;
    }
152139
public List<Locale> getAvailableLocales(CmsObject cms, CmsResource resource) {

        String availableNames = null;
        try {
            availableNames = cms.readPropertyObject(
                resource,
                CmsPropertyDefinition.PROPERTY_AVAILABLE_LOCALES,
                true).getValue();
        } catch (CmsException exc) {
            LOG.debug("Could not read available locales property for resource " + resource.getRootPath(), exc);
        }

        List<Locale> result = null;
        if (availableNames != null) {
            result = getAvailableLocales(availableNames);
        }
        if ((result == null) || (result.size() == 0)) {
            return Collections.unmodifiableList(m_availableLocales);
        } else {
            return result;
        }
    }
775774
public void setDefaultLocale(String locale) {

        try {
            m_defaultLocale = CmsLocaleManager.getLocale(locale);
        } catch (Exception e) {
            if (CmsLog.INIT.isWarnEnabled()) {
                CmsLog.INIT.warn(Messages.get().getBundle().key(Messages.INIT_NONCRIT_ERROR_0), e);
            }
        }
        if (CmsLog.INIT.isInfoEnabled()) {
            CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DEFAULT_LOCALE_1, m_defaultLocale));
        }
    }
1308770
public void setLocale(Locale locale) throws CmsException {

        CmsUserSettings settings = getSettings();
        if (settings != null) {
            settings.setLocale(locale);
            settings.save(m_cms);
            m_messages = Messages.get().getBundle(locale);
        }
    }
596033
public String getTitle(CmsObject cms, Locale locale) {

        if (m_titleKey == null) {
            return m_title;
        } else {
            return OpenCms.getWorkplaceManager().getMessages(locale).key(m_titleKey);
        }
    }
242104
public Map<String, String> getValues() throws CmsException {

        CmsFile file = m_cms.readFile(m_editResource);
        CmsXmlContent content = unmarshalXmlContent(file);
        Locale locale = m_cms.getRequestContext().getLocale();
        if (!content.hasLocale(locale)) {
            content.addLocale(m_cms, locale);
        }
        return getContentValues(content, locale);
    }
91576
public String buildSelectLocales(String attributes) {

        List options = new ArrayList();
        List values = new ArrayList();
        List locales = OpenCms.getLocaleManager().getAvailableLocales();
        int selectedIndex = -1;
        if (locales == null) {
            // no locales found, return empty String
            return "";
        } else {
            // locales found, create option and value lists
            CmsMessages messages = Messages.get().getBundle(getLocale());
            options.add(messages.key(Messages.GUI_PLEASE_SELECT_0));
            values.add("");
            options.add(messages.key(Messages.GUI_BUTTON_ALL_0));
            values.add(ALL);
            if (ALL.equals(getParamLocale())) {
                selectedIndex = 1;
            }
            Iterator i = locales.iterator();
            int counter = 2;
            while (i.hasNext()) {
                Locale locale = (Locale)i.next();
                String language = locale.getLanguage();
                String displayLanguage = locale.getDisplayLanguage();
                if (language.equals(getParamLocale())) {
                    selectedIndex = counter;
                }
                options.add(displayLanguage);
                values.add(language);
                counter++;
            }
        }

        return CmsWorkplace.buildSelect(attributes, options, values, selectedIndex, false);
    }
152668
public CmsResourceUtil getResourceUtil() {

        if (m_resourceUtil == null) {
            try {
                m_resourceUtil = new CmsResourceUtil(OpenCms.initCmsObject(getCms()));
                m_resourceUtil.setReferenceProject(getProject());
            } catch (CmsException ex) {
                if (LOG.isErrorEnabled()) {
                    LOG.error(ex.getLocalizedMessage(), ex);
                }
            }
        }
        return m_resourceUtil;
    }
378524
public CmsGallerySearchResult searchByPath(String path, Locale locale) throws CmsException {

        I_CmsSearchDocument sDoc = m_index.getDocument(CmsSearchField.FIELD_PATH, path);
        CmsGallerySearchResult result = null;
        if ((sDoc != null) && (sDoc.getDocument() != null)) {
            result = new CmsGallerySearchResult(sDoc, m_cms, 100, locale);
        } else {
            CmsResource res = m_cms.readResource(path, CmsResourceFilter.IGNORE_EXPIRATION);
            result = new CmsGallerySearchResult(m_cms, res);
        }
        return result;
    }
542822
public static Document createDocument(Locale locale) {

        Document doc = DocumentHelper.createDocument();
        Element pages = doc.addElement(CmsXmlPage.NODE_PAGES);
        pages.add(I_CmsXmlSchemaType.XSI_NAMESPACE);
        pages.addAttribute(
            I_CmsXmlSchemaType.XSI_NAMESPACE_ATTRIBUTE_NO_SCHEMA_LOCATION,
            CmsXmlPage.XMLPAGE_XSD_SYSTEM_ID);

        Element page = pages.addElement(CmsXmlPage.NODE_PAGE);
        page.addAttribute(CmsXmlPage.ATTRIBUTE_LANGUAGE, locale.toString());

        return doc;
    }
1281779
void switchLocale(final String locale) {

        if (locale.equals(m_locale)) {
            return;
        }
        m_locale = locale;
        m_basePanel.clear();
        destroyForm(false);
        final CmsEntity entity = m_entityBackend.getEntity(m_entityId);
        m_entityId = getIdForLocale(locale);
        // if the content does not contain the requested locale yet, a new node will be created
        final boolean addedNewLocale = !m_contentLocales.contains(locale);
        if (m_registeredEntities.contains(m_entityId)) {
            unregistereEntity(m_entityId);
        }
        if (addedNewLocale) {
            loadNewDefinition(m_entityId, entity, new I_CmsSimpleCallback<CmsContentDefinition>() {

                public void execute(final CmsContentDefinition contentDefinition) {

                    setContentDefinition(contentDefinition);
                    renderFormContent();
                    setChanged();

                }
            });
        } else {
            loadDefinition(m_entityId, entity, new I_CmsSimpleCallback<CmsContentDefinition>() {

                public void execute(CmsContentDefinition contentDefinition) {

                    setContentDefinition(contentDefinition);
                    renderFormContent();
                }
            });
        }
    }
444066
public String getContent(String target, String element, Locale locale) {

        I_CmsResourceLoader loader;
        CmsFile file;
        target = toAbsolute(target);

        try {
            file = getCmsObject().readFile(target);
            loader = OpenCms.getResourceManager().getLoader(file);
        } catch (ClassCastException e) {
            // no loader implementation found
            return CmsMessages.formatUnknownKey(e.getMessage());
        } catch (CmsException e) {
            // file might not exist or no read permissions
            return CmsMessages.formatUnknownKey(e.getMessage());
        }

        try {
            byte[] result = loader.dump(getCmsObject(), file, element, locale, getRequest(), getResponse());
            return new String(result, getRequestContext().getEncoding());
        } catch (UnsupportedEncodingException uee) {
            // encoding unsupported
            return CmsMessages.formatUnknownKey(uee.getMessage());
        } catch (Throwable t) {
            // any other exception, check for hidden root cause first
            Throwable cause = CmsFlexController.getThrowable(getRequest());
            if (cause == null) {
                cause = t;
            }
            handleException(cause);
            return CmsMessages.formatUnknownKey(cause.getMessage());
        }
    }
1102484
public static SelectOptions getProjectSelectOptionsStatic(CmsObject cms, String startProject, Locale locale) {

        List<CmsProject> allProjects;
        try {
            String ouFqn = "";
            CmsUserSettings settings = new CmsUserSettings(cms);
            if (!settings.getListAllProjects()) {
                ouFqn = cms.getRequestContext().getCurrentUser().getOuFqn();
            }
            allProjects = OpenCms.getOrgUnitManager().getAllAccessibleProjects(
                cms,
                ouFqn,
                settings.getListAllProjects());
        } catch (CmsException e) {
            // should usually never happen
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
            allProjects = Collections.emptyList();
        }

        boolean singleOu = true;
        String ouFqn = null;
        Iterator<CmsProject> itProjects = allProjects.iterator();
        while (itProjects.hasNext()) {
            CmsProject prj = itProjects.next();
            if (prj.isOnlineProject()) {
                // skip the online project
                continue;
            }
            if (ouFqn == null) {
                // set the first ou
                ouFqn = prj.getOuFqn();
            }
            if (!ouFqn.equals(prj.getOuFqn())) {
                // break if one different ou is found
                singleOu = false;
                break;
            }
        }

        List<String> options = new ArrayList<String>(allProjects.size());
        List<String> values = new ArrayList<String>(allProjects.size());
        int checkedIndex = 0;

        for (int i = 0, n = allProjects.size(); i < n; i++) {
            CmsProject project = allProjects.get(i);
            String projectName = project.getSimpleName();
            if (!singleOu && !project.isOnlineProject()) {
                try {
                    projectName = projectName
                        + " - "
                        + OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, project.getOuFqn()).getDisplayName(
                            locale);
                } catch (CmsException e) {
                    projectName = projectName + " - " + project.getOuFqn();
                }
            }
            options.add(projectName);
            values.add(project.getName());
            if (startProject.equals(project.getName())) {
                checkedIndex = i;
            }
        }
        SelectOptions selectOptions = new SelectOptions(options, values, checkedIndex);
        return selectOptions;
    }