Finds the correct format for a given container type and width.<p>

@param cms the current CMS context
@param type the container type
@param width the container width

@return the format for the given container type and width
170547
public Format getFormatForContainer(CmsObject cms, String type, int width) {

        IdentityHashMap<CmsFormatterBean, Format> formatsByFormatter = new IdentityHashMap<CmsFormatterBean, Format>();
        // relate formatters to formats so we can pick the corresponding format after a formatter has been selected
        CmsFormatterBean mainFormatter = createFormatterBean(m_mainFormat, true);
        formatsByFormatter.put(mainFormatter, m_mainFormat);
        List<I_CmsFormatterBean> formatters = new ArrayList<I_CmsFormatterBean>();
        for (Format format : m_otherFormats) {
            CmsFormatterBean formatter = createFormatterBean(format, false);
            formatsByFormatter.put(formatter, format);
            formatters.add(formatter);
        }
        formatters.add(0, mainFormatter);
        CmsFormatterConfiguration formatterConfiguration = CmsFormatterConfiguration.create(cms, formatters);
        I_CmsFormatterBean matchingFormatter = formatterConfiguration.getDefaultFormatter(type, width);
        if (matchingFormatter == null) {
            return null;
        }
        return formatsByFormatter.get(matchingFormatter);
    }
848535
public List<CmsDetailPageInfo> getInfosForType(String type) {

        return new ArrayList<CmsDetailPageInfo>(m_map.get(type));
    }
1062856
public static void updateType(Element element, CmsRelationType type) {

        updateAttribute(element, CmsLink.ATTRIBUTE_TYPE, type.getNameForXml());
    }
981574
def find_by_content_type(content_type):
    
    for format in FORMATS:
        if content_type in format.content_types:
            return format

    raise UnknownFormat('No format found with content type "%s"' % content_type)
897177
public List<I_CmsFormatterBean> getNestedFormatters(
        CmsObject cms,
        CmsResource res,
        Locale locale,
        ServletRequest req) {

        List<I_CmsFormatterBean> result = null;
        if (CmsResourceTypeXmlContent.isXmlContent(res)) {
            CmsResourceTypeXmlContent type = (CmsResourceTypeXmlContent)OpenCms.getResourceManager().getResourceType(
                res);
            String schema = type.getSchema();
            try {
                CmsXmlContentDefinition contentDefinition = CmsXmlContentDefinition.unmarshal(cms, schema);
                // get the content handler for the resource type to create
                I_CmsXmlContentHandler handler = contentDefinition.getContentHandler();
                if (handler.hasNestedFormatters()) {
                    Map<CmsUUID, I_CmsFormatterBean> formatters = getCachedFormatters(
                        cms.getRequestContext().getCurrentProject().isOnlineProject()).getFormatters();
                    result = new ArrayList<I_CmsFormatterBean>();
                    for (CmsUUID formatterId : handler.getNestedFormatters(cms, res, locale, req)) {
                        I_CmsFormatterBean formatter = formatters.get(formatterId);
                        if (formatter != null) {
                            result.add(formatter);
                        }
                    }
                }
            } catch (CmsXmlException e) {
                LOG.error(e.getMessage(), e);
            }
        }
        return result;
    }
635286
protected CmsFormatterBean createFormatterBean(Format format, boolean isPreview) {

        if (format.hasNoContainerSettings()) {
            return new CmsFormatterBean(
                CmsResourceTypeFunctionConfig.FORMATTER_PATH,
                m_functionFormatter.getStructureId(),
                m_resource.getRootPath(),
                isPreview);
        } else {
            CmsFormatterBean result = new CmsFormatterBean(
                format.getType(),
                CmsResourceTypeFunctionConfig.FORMATTER_PATH,
                format.getMinWidth(),
                format.getMaxWidth(),
                "" + isPreview,
                "false",
                m_resource.getRootPath());
            result.setJspStructureId(m_functionFormatter.getStructureId());
            return result;
        }
    }
129908
@SuppressWarnings("deprecation")
    public boolean isInheritedContainer(CmsObject cms) throws CmsException {

        if (m_resource == null) {
            initResource(cms);
        }
        return OpenCms.getResourceManager().getResourceType(
            CmsResourceTypeXmlContainerPage.INHERIT_CONTAINER_TYPE_NAME).getTypeId() == m_resource.getTypeId();
    }
1286257
public CmsGalleryDataBean getInitialSettingsForContainerPage(
        List<CmsResourceTypeBean> types,
        String uri,
        String locale) {

        CmsGalleryDataBean data = null;
        try {
            data = new CmsGalleryDataBean();
            boolean galleryShowInvalidDefault = Boolean.parseBoolean(
                getWorkplaceSettings().getUserSettings().getAdditionalPreference(
                    PREF_GALLERY_SHOW_INVALID_DEFAULT,
                    true));
            data.setIncludeExpiredDefault(galleryShowInvalidDefault);
            data.setResultViewType(readResultViewType());
            data.setMode(GalleryMode.ade);
            data.setGalleryStoragePrefix("");
            data.setLocales(buildLocalesMap());
            data.setLocale(locale);

            data.setVfsRootFolders(getRootEntries());

            data.setScope(getWorkplaceSettings().getLastSearchScope());
            data.setSortOrder(getWorkplaceSettings().getLastGalleryResultOrder());

            data.setTabIds(GalleryMode.ade.getTabs());
            data.setReferenceSitePath(uri);
            data.setTypes(types);
            Map<String, CmsGalleryTypeInfo> adeGalleryTypeInfos = readGalleryInfosByTypeBeans(types);
            data.setGalleries(buildGalleriesList(adeGalleryTypeInfos));
            data.setStartTab(GalleryTabId.cms_tab_types);
            Set<String> folderFilter = readFolderFilters();
            data.setStartFolderFilter(folderFilter);
            if ((folderFilter != null) && !folderFilter.isEmpty()) {
                try {
                    data.setVfsPreloadData(generateVfsPreloadData(getCmsObject(), null, folderFilter));
                } catch (Exception e) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }
            CmsSiteSelectorOptionBuilder optionBuilder = new CmsSiteSelectorOptionBuilder(getCmsObject());
            optionBuilder.addNormalSites(true, getWorkplaceSettings().getUserSettings().getStartFolder());
            optionBuilder.addSharedSite();
            data.setVfsSiteSelectorOptions(optionBuilder.getOptions());

            CmsSiteSelectorOptionBuilder sitemapOptionBuilder = new CmsSiteSelectorOptionBuilder(getCmsObject());
            sitemapOptionBuilder.addNormalSites(false, null);
            if (data.getReferenceSitePath() != null) {
                sitemapOptionBuilder.addCurrentSubsite(getCmsObject().addSiteRoot(data.getReferenceSitePath()));
            }
            data.setSitemapSiteSelectorOptions(sitemapOptionBuilder.getOptions());
            data.setDefaultScope(OpenCms.getWorkplaceManager().getGalleryDefaultScope());
            CmsCoreService service = new CmsCoreService();
            service.setCms(getCmsObject());
            data.setCategories(service.getCategoriesForSitePath(data.getReferenceSitePath()));
        } catch (Exception e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
        return data;
    }
890735
public CmsRelationFilter filterType(CmsRelationType type) {

        CmsRelationFilter filter = (CmsRelationFilter)clone();
        filter.m_types.add(type);
        return filter;
    }
734051
public CmsLogFilter includeType(CmsLogEntryType type) {

        CmsLogFilter filter = (CmsLogFilter)clone();
        filter.m_includeTypes.add(type);
        return filter;
    }
119930
public CmsResource getConfigurationFile(CmsObject cms, String containerPageUri) {

        String cfgPath = null;
        try {
            // get the resource type configuration file from the vfs tree
            cfgPath = cms.readPropertyObject(containerPageUri, m_propertyName, true).getValue();
        } catch (CmsException e) {
            // should never happen
            LOG.error(e.getLocalizedMessage(), e);
        }

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(cfgPath)) {
            // if not found try at the template
            try {
                // retrieve the template uri
                String templateUri = cms.readPropertyObject(
                    containerPageUri,
                    CmsPropertyDefinition.PROPERTY_TEMPLATE,
                    true).getValue();
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(templateUri)) {
                    // get the resource type configuration file from the template itself
                    cfgPath = cms.readPropertyObject(templateUri, m_propertyName, true).getValue();
                }
            } catch (CmsException e) {
                // should never happen
                LOG.error(e.getLocalizedMessage(), e);
            }
        }

        if (CmsStringUtil.isEmptyOrWhitespaceOnly(cfgPath)) {
            // configuration could not be found
            LOG.warn(Messages.get().getBundle().key(Messages.ERR_CONFIG_NOT_SET_2, containerPageUri, m_propertyName));
            return null;
        }

        try {
            // read configuration file
            return cms.readResource(cfgPath);
        } catch (Exception e1) {
            try {
                CmsResource baseResource = cms.readResource(containerPageUri);
                String baseRootPath = baseResource.getRootPath();
                String siteRoot = OpenCms.getSiteManager().getSiteRoot(baseRootPath);
                String rootCfgPath = CmsStringUtil.joinPaths(siteRoot, cfgPath);
                return cms.readResource(rootCfgPath);
            } catch (Exception e2) {
                throw new CmsIllegalStateException(
                    Messages.get().container(
                        Messages.ERR_CONFIG_NOT_FOUND_3,
                        containerPageUri,
                        m_propertyName,
                        cfgPath));
            }
        }
    }
107806
public String getDefaultNamePattern(String type) {

        CmsExplorerTypeSettings settings = getExplorerTypeSetting(type);
        if ((settings != null) && (settings.getNamePattern() != null)) {
            return settings.getNamePattern();
        }
        if (type.equals("sitemap_config") || type.equals("module_config")) {
            return ".config%(number)";
        }
        if (type.equals("content_folder")) {
            return ".content%(number)";
        }
        return "new_" + type + "%(number)";
    }
901797
public static boolean matchFormatter(I_CmsFormatterBean formatter, Set<String> types, int width) {

        if (formatter.isMatchAll()) {
            return true;
        }
        if (formatter.isTypeFormatter()) {
            return !Sets.intersection(types, formatter.getContainerTypes()).isEmpty();
        } else {
            return (width == MATCH_ALL_CONTAINER_WIDTH)
                || ((formatter.getMinWidth() <= width) && (width <= formatter.getMaxWidth()));
        }
    }
754489
public Object getFormatFor() {

        Transformer mapFunction = new Transformer() {

            public Object transform(Object param) {

                if (m_functionBean == null) {
                    return new CmsDynamicFunctionFormatWrapper(m_cms, null);
                }
                int width = -1;
                String type = null;
                boolean isWidth = false;
                if (param instanceof Long) {
                    width = (int)((Long)param).longValue();
                    isWidth = true;
                } else if (param instanceof Integer) {
                    width = ((Integer)param).intValue();
                    isWidth = true;
                } else {
                    type = param.toString();
                }
                Format format;
                if (isWidth) {
                    format = m_functionBean.getFormatForContainer(m_cms, "", width);
                } else {
                    format = m_functionBean.getFormatForContainer(m_cms, type, -1);
                }
                CmsDynamicFunctionFormatWrapper wrapper = new CmsDynamicFunctionFormatWrapper(m_cms, format);
                return wrapper;
            }
        };
        return CmsCollectionsGenericWrapper.createLazyMap(mapFunction);
    }
1001463
public CmsContainerPageBean getContainerPage(CmsObject cms) {

        Locale masterLocale = CmsLocaleManager.MASTER_LOCALE;
        Locale localeToLoad = null;
        // always use master locale if possible, otherwise use the first locale.
        // this is important for 'legacy' container pages which were created before container pages became locale independent
        if (m_cntPages.containsKey(masterLocale)) {
            localeToLoad = masterLocale;
        } else if (!m_cntPages.isEmpty()) {
            localeToLoad = m_cntPages.keySet().iterator().next();
        }
        if (localeToLoad == null) {
            return null;
        } else {
            CmsContainerPageBean result = m_cntPages.get(localeToLoad);
            return result;
        }
    }
363869
public String getTypeTitle() {

        if (m_type == null) {
            return CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_STATS_ALL_RESOURCES_0);
        }

        String res = "";
        CmsExplorerTypeSettings typeSetting = OpenCms.getWorkplaceManager().getExplorerTypeSetting(
            m_type.getTypeName());
        res = CmsVaadinUtils.getMessageText(typeSetting.getKey());
        return res;
    }
861530
private CmsFunctionFormatterBean getFormatterBean(CmsObject cms) {

        Map<CmsUUID, I_CmsFormatterBean> formatters = OpenCms.getADEManager().getCachedFormatters(
            m_cms.getRequestContext().getCurrentProject().isOnlineProject()).getFormatters();

        // Using getId(), *not* getFormatterId() here , since the former is the id of the function formatter configuration,
        // and the latter is just the id of the internal JSP used to render it
        I_CmsFormatterBean formatterConfig = formatters.get(m_element.getId());
        CmsFunctionFormatterBean function = (CmsFunctionFormatterBean)formatterConfig;
        return function;

    }