Reads the size of a single image.<p>

@param cms CmsObejct
@param res CmsResource to be read
@return a String representation of the dimension of the given image
167663
private String getSingleSize(CmsObject cms, CmsResource res) {

        try {
            BufferedImage img = Simapi.read(cms.readFile(res).getContents());
            return "" + img.getWidth() + " x " + img.getHeight() + "px";
        } catch (CmsException | IOException e) {
            return "";
        }
    }
1325880
private Map<String, CmsGalleryTypeInfo> readGalleryInfosByTypeBeans(List<CmsResourceTypeBean> resourceTypes) {

        Map<String, CmsGalleryTypeInfo> galleryTypeInfos = new HashMap<String, CmsGalleryTypeInfo>();
        for (CmsResourceTypeBean typeBean : resourceTypes) {
            try {
                if (!typeBean.isDeactivated()) {
                    addGalleriesForType(galleryTypeInfos, typeBean.getType());
                }
            } catch (CmsLoaderException e1) {
                logError(e1);
            }
        }
        return galleryTypeInfos;
    }
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);
    }
627793
private String getTemplateName(CmsObject cms, CmsResource resource) throws CmsException {

        String templateName = (String)(m_templateNameCache.getCachedObject(cms, resource.getRootPath()));
        if (templateName == null) {
            CmsProperty nameProperty = cms.readPropertyObject(
                resource,
                CmsPropertyDefinition.PROPERTY_TEMPLATE_ELEMENTS,
                false);
            String nameFromProperty = "";
            if (!nameProperty.isNullProperty()) {
                nameFromProperty = nameProperty.getValue();
            }
            m_templateNameCache.putCachedObject(cms, resource.getRootPath(), nameFromProperty);
            return nameFromProperty;
        } else {
            return templateName;
        }
    }
656331
public CmsFormatterConfiguration getFormatters(CmsObject cms, CmsResource res) {

        if (CmsResourceTypeFunctionConfig.isFunction(res)) {

            CmsFormatterConfigurationCacheState formatters = getCachedFormatters();
            I_CmsFormatterBean function = formatters.getFormatters().get(res.getStructureId());
            if (function != null) {
                return CmsFormatterConfiguration.create(cms, Collections.singletonList(function));
            } else {
                if ((!res.getStructureId().isNullUUID())
                    && cms.existsResource(res.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION)) {
                    // usually if it's just been created, but not added to the configuration cache yet
                    CmsFormatterBeanParser parser = new CmsFormatterBeanParser(cms, new HashMap<>());
                    try {
                        function = parser.parse(
                            CmsXmlContentFactory.unmarshal(cms, cms.readFile(res)),
                            res.getRootPath(),
                            "" + res.getStructureId());
                        return CmsFormatterConfiguration.create(cms, Collections.singletonList(function));
                    } catch (Exception e) {
                        LOG.warn(e.getLocalizedMessage(), e);
                        return CmsFormatterConfiguration.EMPTY_CONFIGURATION;
                    }

                } else {
                    // if a new function has been dragged on the page, it doesn't exist in the VFS yet, so we need a different
                    // instance as a replacement
                    CmsResource defaultFormatter = CmsFunctionRenderer.getDefaultFunctionInstance(cms);
                    if (defaultFormatter != null) {
                        I_CmsFormatterBean defaultFormatterBean = formatters.getFormatters().get(
                            defaultFormatter.getStructureId());
                        return CmsFormatterConfiguration.create(cms, Collections.singletonList(defaultFormatterBean));
                    } else {
                        LOG.warn("Could not read default formatter for functions.");
                        return CmsFormatterConfiguration.EMPTY_CONFIGURATION;
                    }
                }
            }
        } else {
            try {
                int resTypeId = res.getTypeId();
                return getFormatters(
                    cms,
                    OpenCms.getResourceManager().getResourceType(resTypeId),
                    getFormattersFromSchema(cms, res));
            } catch (CmsLoaderException e) {
                LOG.warn(e.getLocalizedMessage(), e);
                return CmsFormatterConfiguration.EMPTY_CONFIGURATION;
            }
        }
    }
942878
protected String getFileEncoding(CmsObject cms, CmsResource file) {

        String result;
        try {
            result = cms.readPropertyObject(file, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true).getValue(
                OpenCms.getSystemInfo().getDefaultEncoding());
        } catch (CmsException e) {
            result = OpenCms.getSystemInfo().getDefaultEncoding();
        }
        return CmsEncoder.lookupEncoding(result, OpenCms.getSystemInfo().getDefaultEncoding());
    }
42897
private CmsJspResourceWrapper readResource(String sitePath) {

        CmsJspResourceWrapper result = null;
        try {
            result = new CmsJspResourceWrapper(m_cms, m_cms.readResource(sitePath));
        } catch (CmsException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(e.getMessage(), e);
            }
        }
        return result;
    }
1280129
public static Resource getSitemapResourceIcon(CmsObject cms, CmsResource resource, IconMode iconMode) {

        CmsResource defaultFile = null;
        List<CmsResource> resourcesForType = Lists.newArrayList();
        resourcesForType.add(resource);
        boolean skipDefaultFile = (iconMode == IconMode.sitemapSelect)
            && OpenCms.getResourceManager().matchResourceType(
                CmsResourceTypeFolderSubSitemap.TYPE_SUBSITEMAP,
                resource.getTypeId());
        if (resource.isFolder() && !skipDefaultFile) {

            try {
                defaultFile = cms.readDefaultFile(resource, CmsResourceFilter.IGNORE_EXPIRATION);
                if (defaultFile != null) {
                    resourcesForType.add(0, defaultFile);
                }
            } catch (Exception e) {
                // Shouldn't normally happen - readDefaultFile returns null instead of throwing an exception when it doesn't find a default file
            }
        }
        if (CmsJspNavBuilder.isNavLevelFolder(cms, resource)) {
            return new CmsCssIcon(CmsExplorerTypeSettings.ICON_STYLE_NAV_LEVEL_BIG);
        }
        CmsResource maybePage = resourcesForType.get(0);
        if (CmsResourceTypeXmlContainerPage.isContainerPage(maybePage)) {
            CmsADEConfigData config = OpenCms.getADEManager().lookupConfiguration(cms, maybePage.getRootPath());
            for (CmsDetailPageInfo realInfo : config.getAllDetailPages(true)) {
                if (realInfo.getUri().equals(maybePage.getRootPath())
                    || realInfo.getUri().equals(CmsResource.getParentFolder(maybePage.getRootPath()))) {
                    CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(
                        realInfo.getIconType());
                    if (settings != null) {
                        return CmsResourceUtil.getBigIconResource(settings, resource.getName());
                    }
                }
            }
        }

        Resource result = null;
        for (CmsResource res : resourcesForType) {
            I_CmsResourceType type = OpenCms.getResourceManager().getResourceType(res);
            CmsExplorerTypeSettings settings = OpenCms.getWorkplaceManager().getExplorerTypeSetting(type.getTypeName());
            if (settings != null) {
                result = CmsResourceUtil.getBigIconResource(settings, res.getName());
                break;
            }
        }
        return result;
    }
477465
protected List<CmsResource> getImages() {

        // get all image resources of the folder
        int imageId;
        try {
            imageId = OpenCms.getResourceManager().getResourceType(
                CmsResourceTypeImage.getStaticTypeName()).getTypeId();
        } catch (CmsLoaderException e1) {
            // should really never happen
            LOG.warn(e1.getLocalizedMessage(), e1);
            imageId = CmsResourceTypeImage.getStaticTypeId();
        }
        CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION.addRequireType(imageId);
        try {
            return getCms().readResources(getParamResource(), filter, false);
        } catch (CmsException e) {
            // log, should never happen
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(getLocale()));
            }
            return Collections.emptyList();
        }
    }
600477
public CmsJspImageBean getSrcSetMaxImage() {

        CmsJspImageBean result = this;
        if (m_srcSet != null) {
            result = m_srcSet.lastEntry().getValue();
        }
        return result;
    }
339810
private CmsResource getResource(CmsObject cms, String resourcename) {

        return getResource(cms, resourcename, CmsResourceFilter.DEFAULT);
    }
25809
public String getFormat(CmsObject cms) {

        if (m_format == null) {
            if (m_element.element(PARAM_FORMAT) != null) {
                m_format = m_element.element(PARAM_FORMAT).getText();
            }
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_format)) {
                m_format = getParameterValue(cms, PARAM_FORMAT);
            }
        }
        return m_format;
    }
1061662
public List<CmsCategory> readResourceCategories(CmsObject cms, CmsResource resource) throws CmsException {

        return internalReadResourceCategories(cms, resource, false);
    }
95579
private void writePointerLink(CmsResource res) throws CmsException {

        String resPath = getCms().getSitePath(res);
        String currentPropertyValue = getParamPropertyValue();
        boolean locked = true;
        CmsLock lock = getCms().getLock(res);
        if (lock.isUnlocked()) {
            // lock resource before operation
            getCms().lockResource(resPath);
            locked = false;
        }
        CmsFile file = getCms().readFile(res);
        file.setContents(currentPropertyValue.getBytes());
        checkLock(getCms().getSitePath(res));
        getCms().writeFile(file);
        if (!locked) {
            // unlock the resource
            getCms().unlockResource(resPath);
        }
    }
299483
public static List<CmsResource> getGalleries(int galleryTypeId, CmsObject cms) {

        List<CmsResource> galleries = new ArrayList<CmsResource>();
        try {
            // get the galleries of the current site
            galleries = cms.readResources("/", CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(galleryTypeId));
        } catch (CmsException e) {
            // error reading resources with filter
            LOG.error(e.getLocalizedMessage(), e);
        }

        // if the current site is NOT the root site - add all other galleries from the system path
        if (!cms.getRequestContext().getSiteRoot().equals("")) {
            List<CmsResource> systemGalleries = null;
            try {
                // get the galleries in the /system/ folder
                systemGalleries = cms.readResources(
                    CmsWorkplace.VFS_PATH_SYSTEM,
                    CmsResourceFilter.ONLY_VISIBLE_NO_DELETED.addRequireType(galleryTypeId));
            } catch (CmsException e) {
                // error reading resources with filter
                LOG.error(e.getLocalizedMessage(), e);
            }

            if ((systemGalleries != null) && (systemGalleries.size() > 0)) {
                // add the found system galleries to the result
                galleries.addAll(systemGalleries);
            }
        }

        // return the found galleries
        return galleries;
    }
98908
private void readLocale(CmsResource res) {

        Locale locale = OpenCms.getLocaleManager().getDefaultLocale(m_cms, res);
        m_localeCache.put(res, locale);
    }
459646
private int getSize() {

        return Integer.valueOf(
            (String)CmsVaadinUtils.getRequest().getSession().getAttribute(ATTR_FILE_VIEW_SIZE)).intValue();
    }