Returns the detail container resource locale appropriate for the given detail page.<p>

@param cms the cms context
@param contentLocale the content locale
@param resource the detail page resource

@return the locale String
165962
public static String getDetailContainerLocale(CmsObject cms, String contentLocale, CmsResource resource) {

        boolean singleLocale = useSingleLocaleDetailContainers(cms.getRequestContext().getSiteRoot());
        if (!singleLocale) {
            try {
                CmsProperty prop = cms.readPropertyObject(
                    resource,
                    CmsPropertyDefinition.PROPERTY_LOCALE_INDEPENDENT_DETAILS,
                    true);
                singleLocale = Boolean.parseBoolean(prop.getValue());
            } catch (Exception e) {
                LOG.warn(e.getMessage(), e);
            }
        }
        return singleLocale ? LOCALE_ALL : contentLocale;
    }
1343915
protected void parse(CmsXmlContent content) {

        List<Locale> availableLocales = content.getLocales();
        for (Locale locale : availableLocales) {
            CmsXmlContentRootLocation location = new CmsXmlContentRootLocation(content, locale);
            CmsInheritanceReference ref = parseReference(location, locale);
            if (ref != null) {
                m_references.put(locale, ref);
            }
        }
    }
1189270
private void setResourceInformation() {

        String sitePath = m_cms.getSitePath(m_resource);
        int pathEnd = sitePath.lastIndexOf('/') + 1;
        String baseName = sitePath.substring(pathEnd);
        m_sitepath = sitePath.substring(0, pathEnd);
        switch (CmsMessageBundleEditorTypes.BundleType.toBundleType(
            OpenCms.getResourceManager().getResourceType(m_resource).getTypeName())) {
            case PROPERTY:
                String localeSuffix = CmsStringUtil.getLocaleSuffixForName(baseName);
                if ((null != localeSuffix) && !localeSuffix.isEmpty()) {
                    baseName = baseName.substring(
                        0,
                        baseName.lastIndexOf(localeSuffix) - (1 /* cut off trailing underscore, too*/));
                    m_locale = CmsLocaleManager.getLocale(localeSuffix);
                }
                if ((null == m_locale) || !m_locales.contains(m_locale)) {
                    m_switchedLocaleOnOpening = true;
                    m_locale = m_locales.iterator().next();
                }
                break;
            case XML:
                m_locale = OpenCms.getLocaleManager().getBestAvailableLocaleForXmlContent(
                    m_cms,
                    m_resource,
                    m_xmlBundle);
                break;
            case DESCRIPTOR:
                m_basename = baseName.substring(
                    0,
                    baseName.length() - CmsMessageBundleEditorTypes.Descriptor.POSTFIX.length());
                m_locale = new Locale("en");
                break;
            default:
                throw new IllegalArgumentException(
                    Messages.get().container(
                        Messages.ERR_UNSUPPORTED_BUNDLE_TYPE_1,
                        CmsMessageBundleEditorTypes.BundleType.toBundleType(
                            OpenCms.getResourceManager().getResourceType(m_resource).getTypeName())).toString());
        }
        m_basename = baseName;

    }
1318905
public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsIndexException, CmsException {

        logContentExtraction(resource, index);
        CmsFile file = readFile(cms, resource);
        try {
            CmsProperty encProp = cms.readPropertyObject(
                resource,
                CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING,
                true);
            String encoding = encProp.getValue(OpenCms.getSystemInfo().getDefaultEncoding());
            return CmsExtractorHtml.getExtractor().extractText(file.getContents(), encoding);
        } catch (Exception e) {
            throw new CmsIndexException(
                Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()),
                e);
        }
    }
736863
public void init(CmsObject cms, Locale locale, List<CmsResource> content) {

        m_cms = cms;
        m_locale = locale;
        m_content = convertResourceList(m_cms, m_locale, content);
    }
534342
public static String getSiteSelectOptionsStatic(CmsObject cms, Locale locale) {

        List<CmsSite> sites = OpenCms.getSiteManager().getAvailableSites(
            cms,
            true,
            false,
            cms.getRequestContext().getOuFqn());

        StringBuffer resultBuffer = new StringBuffer();
        Iterator<CmsSite> i = sites.iterator();
        int counter = 0;
        while (i.hasNext()) {
            CmsSite site = i.next();
            String siteRoot = site.getSiteRoot();
            if (!siteRoot.endsWith("/")) {
                siteRoot += "/";
            }
            if (counter != 0) {
                resultBuffer.append("|");
            }
            resultBuffer.append(siteRoot).append(":").append(
                CmsWorkplace.substituteSiteTitleStatic(site.getTitle(), locale));
            counter++;
        }

        if (sites.size() < 1) {
            // no site found, assure that at least the current site is shown in the selector
            String siteRoot = cms.getRequestContext().getSiteRoot();
            CmsSite site = OpenCms.getSiteManager().getSiteForSiteRoot(siteRoot);
            if (!siteRoot.endsWith("/")) {
                siteRoot += "/";
            }
            String title = "";
            if (site != null) {
                title = site.getTitle();
            }
            resultBuffer.append(siteRoot).append(":").append(title);
        }
        return resultBuffer.toString();
    }
1095690
private Locale getLocale(CmsResource resource, List<CmsProperty> propertyList) {

        return OpenCms.getLocaleManager().getDefaultLocale(m_guestCms, m_guestCms.getSitePath(resource));
    }
703432
protected Locale ensureLocale(Locale locale) {

        // get the default locale for the resource
        List<Locale> locales = OpenCms.getLocaleManager().getDefaultLocales(getCms(), getParamResource());
        if (m_content != null) {
            if (!m_content.hasLocale(locale)) {
                try {

                    // to copy anything we need at least one locale
                    if ((m_content.getLocales().size() > 0)) {
                        // required locale not available, check if an existing default locale should be copied as "template"
                        try {
                            // a list of possible default locales has been set as property, try to find a match
                            m_content.copyLocale(locales, locale);

                        } catch (CmsException e) {
                            m_content.addLocale(getCms(), locale);
                        }

                    } else {
                        m_content.addLocale(getCms(), locale);
                    }

                    writeContent();
                } catch (CmsException e) {
                    LOG.error(e.getMessageContainer(), e);
                }
            }
            if (!m_content.hasLocale(locale)) {
                // value may have changed because of the copy operation
                locale = m_content.getLocales().get(0);
            }
        }
        return locale;
    }
220740
public static Optional<CmsResource> getDetailOnlyPage(
        CmsObject cms,
        CmsResource detailContent,
        String contentLocale) {

        try {
            CmsObject rootCms = OpenCms.initCmsObject(cms);
            rootCms.getRequestContext().setSiteRoot("");
            String path = getDetailOnlyPageNameWithoutLocaleCheck(detailContent.getRootPath(), contentLocale);
            if (rootCms.existsResource(path, CmsResourceFilter.ALL)) {
                CmsResource detailOnlyRes = rootCms.readResource(path, CmsResourceFilter.ALL);
                return Optional.of(detailOnlyRes);
            }
            return Optional.absent();
        } catch (CmsException e) {
            LOG.warn(e.getLocalizedMessage(), e);
            return Optional.absent();
        }
    }
346768
public CmsGroupContainerBean getGroupContainer(CmsObject cms) {

        if (m_groupContainers.containsKey(CmsLocaleManager.MASTER_LOCALE)) {
            return m_groupContainers.get(CmsLocaleManager.MASTER_LOCALE);
        } else if (!m_groupContainers.isEmpty()) {
            return m_groupContainers.get(m_groupContainers.keySet().iterator().next());
        } else {
            return null;
        }
    }
1367219
public Element getLocaleNode(Locale locale) throws CmsRuntimeException {

        String localeStr = locale.toString();
        Iterator<Element> i = CmsXmlGenericWrapper.elementIterator(m_document.getRootElement());
        while (i.hasNext()) {
            Element element = i.next();
            if (localeStr.equals(element.attributeValue(CmsXmlContentDefinition.XSD_ATTRIBUTE_VALUE_LANGUAGE))) {
                // language element found, return it
                return element;
            }
        }
        // language element was not found
        throw new CmsRuntimeException(Messages.get().container(Messages.ERR_XMLCONTENT_MISSING_LOCALE_1, locale));
    }
1083120
public Collection<CmsResource> getResourcesForLocale(Locale locale) {

        return Lists.newArrayList(m_resourcesByLocale.get(locale));
    }
222441
public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsException {

        logContentExtraction(resource, index);
        try {
            CmsFile file = readFile(cms, resource);
            CmsXmlContainerPage containerPage = CmsXmlContainerPageFactory.unmarshal(cms, file);
            Locale locale = index.getLocaleForResource(cms, resource, null);

            // initialize return values
            StringBuffer content = new StringBuffer();
            LinkedHashMap<String, String> items = new LinkedHashMap<String, String>();

            CmsContainerPageBean containerBean = containerPage.getContainerPage(cms);
            for (CmsContainerElementBean element : containerBean.getElements()) {
                // check all elements in this container

                // get the formatter configuration for this element
                element.initResource(cms);
                CmsADEConfigData adeConfig = OpenCms.getADEManager().lookupConfiguration(cms, file.getRootPath());
                CmsFormatterConfiguration formatters = adeConfig.getFormatters(cms, element.getResource());

                if (formatters.isSearchContent(element.getFormatterId())) {
                    // the content of this element must be included for the container page

                    element.initResource(cms);
                    CmsFile elementFile = readFile(cms, element.getResource());
                    A_CmsXmlDocument elementContent = CmsXmlContentFactory.unmarshal(cms, elementFile);
                    List<String> elementNames = elementContent.getNames(locale);
                    for (String xpath : elementNames) {
                        // xpath will have the form "Text[1]" or "Nested[1]/Text[1]"
                        I_CmsXmlContentValue value = elementContent.getValue(xpath, locale);
                        if (value.getContentDefinition().getContentHandler().isSearchable(value)) {
                            // the content value is searchable
                            String extracted = value.getPlainText(cms);
                            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(extracted)) {
                                items.put(elementFile.getRootPath() + "/" + xpath, extracted);
                                content.append(extracted);
                                content.append('\n');
                            }
                        }
                    }
                }
            }

            return new CmsExtractionResult(content.toString(), items);

        } catch (Exception e) {
            throw new CmsIndexException(
                Messages.get().container(Messages.ERR_TEXT_EXTRACTION_1, resource.getRootPath()),
                e);
        }
    }
292123
private Set<String> getCSSHeadIncludes(CmsObject cms, CmsResource resource) {

        if (CmsResourceTypeXmlContent.isXmlContent(resource)) {
            try {
                CmsXmlContentDefinition contentDefinition = CmsXmlContentDefinition.getContentDefinitionForResource(
                    cms,
                    resource);
                return contentDefinition.getContentHandler().getCSSHeadIncludes(cms, resource);
            } catch (CmsException e) {
                LOG.warn(e.getLocalizedMessage(), e);
                // NOOP, use the empty set
            }
        }
        return Collections.emptySet();
    }
660004
protected boolean isDetailPage(CmsObject cms, CmsResource resource) {

        CmsResource folder;
        if (resource.isFile()) {
            if (!CmsResourceTypeXmlContainerPage.isContainerPage(resource)) {
                return false;
            }
            try {
                folder = getCms().readResource(CmsResource.getParentFolder(resource.getRootPath()));
            } catch (CmsException e) {
                LOG.debug(e.getLocalizedMessage(), e);
                return false;
            }
        } else {
            folder = resource;
        }
        List<CmsDetailPageInfo> allDetailPages = new ArrayList<CmsDetailPageInfo>();
        // First collect all detail page infos
        for (CmsADEConfigDataInternal configData : m_siteConfigurationsByPath.values()) {
            List<CmsDetailPageInfo> detailPageInfos = wrap(configData).getAllDetailPages();
            allDetailPages.addAll(detailPageInfos);
        }
        // First pass: check if the structure id or path directly match one of the configured detail pages.
        for (CmsDetailPageInfo info : allDetailPages) {
            if (folder.getStructureId().equals(info.getId())
                || folder.getRootPath().equals(info.getUri())
                || resource.getStructureId().equals(info.getId())
                || resource.getRootPath().equals(info.getUri())) {
                return true;
            }
        }
        // Second pass: configured detail pages may be actual container pages rather than folders
        String normalizedFolderRootPath = CmsStringUtil.joinPaths(folder.getRootPath(), "/");
        for (CmsDetailPageInfo info : allDetailPages) {
            String parentPath = CmsResource.getParentFolder(info.getUri());
            if (parentPath != null) {
                String normalizedParentPath = CmsStringUtil.joinPaths(parentPath, "/");
                if (normalizedParentPath.equals(normalizedFolderRootPath)) {
                    try {
                        CmsResource infoResource = getCms().readResource(info.getId());
                        if (infoResource.isFile()) {
                            return true;
                        }
                    } catch (CmsException e) {
                        LOG.warn(e.getLocalizedMessage(), e);
                    }
                }
            }
        }
        return false;
    }
1006678
protected String getLocaleSpecificTitle(Locale locale) {

        String result = null;

        try {

            if (isDetailRequest()) {
                // this is a request to a detail page
                CmsResource res = getDetailContent();
                CmsFile file = m_cms.readFile(res);
                CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file);
                result = content.getHandler().getTitleMapping(m_cms, content, m_cms.getRequestContext().getLocale());
                if (result == null) {
                    // title not found, maybe no mapping OR not available in the current locale
                    // read the title of the detail resource as fall back (may contain mapping from another locale)
                    result = m_cms.readPropertyObject(
                        res,
                        CmsPropertyDefinition.PROPERTY_TITLE,
                        false,
                        locale).getValue();
                }
            }
            if (result == null) {
                // read the title of the requested resource as fall back
                result = m_cms.readPropertyObject(
                    m_cms.getRequestContext().getUri(),
                    CmsPropertyDefinition.PROPERTY_TITLE,
                    true,
                    locale).getValue();
            }
        } catch (CmsException e) {
            LOG.debug(e.getLocalizedMessage(), e);
        }
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(result)) {
            result = "";
        }

        return result;
    }
755289
public static CmsContainerPageBean getDetailOnlyPage(CmsObject cms, ServletRequest req, String pageRootPath) {

        CmsJspStandardContextBean standardContext = CmsJspStandardContextBean.getInstance(req);
        CmsContainerPageBean detailOnlyPage = standardContext.getDetailOnlyPage();
        if (standardContext.isDetailRequest() && (detailOnlyPage == null)) {

            try {
                CmsObject rootCms = OpenCms.initCmsObject(cms);
                rootCms.getRequestContext().setSiteRoot("");
                String locale = getDetailContainerLocale(
                    cms,
                    cms.getRequestContext().getLocale().toString(),
                    cms.readResource(cms.getRequestContext().getUri()));

                String resourceName = getDetailOnlyPageNameWithoutLocaleCheck(
                    standardContext.getDetailContent().getRootPath(),
                    locale);
                CmsResource resource = null;
                if (rootCms.existsResource(resourceName)) {
                    resource = rootCms.readResource(resourceName);
                } else {
                    // check if the deprecated locale independent detail container page exists
                    resourceName = getDetailOnlyPageNameWithoutLocaleCheck(
                        standardContext.getDetailContent().getRootPath(),
                        null);
                    if (rootCms.existsResource(resourceName)) {
                        resource = rootCms.readResource(resourceName);
                    }
                }

                CmsXmlContainerPage xmlContainerPage = null;
                if (resource != null) {
                    xmlContainerPage = CmsXmlContainerPageFactory.unmarshal(rootCms, resource, req);
                }
                if (xmlContainerPage != null) {
                    detailOnlyPage = xmlContainerPage.getContainerPage(rootCms);
                    detailOnlyPage = CmsTemplateMapper.get(req).transformContainerpageBean(
                        rootCms,
                        detailOnlyPage,
                        pageRootPath);
                    standardContext.setDetailOnlyPage(detailOnlyPage);
                }
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return detailOnlyPage;
    }