Gets localized property object.<p>

@param cms CmsObject
@param path of resource
@return Properties object
@throws CmsException exception
@throws IOException exception
430169
private Properties getLocalizedBundle(CmsObject cms, String path) throws CmsException, IOException {

        CmsResource bundleResource = cms.readResource(path
            + CmsSiteManager.MACRO_FOLDER
            + "/"
            + getAvailableLocalVariant(cms, path + CmsSiteManager.MACRO_FOLDER + "/", CmsSiteManager.BUNDLE_NAME));

        Properties ret = new Properties();
        InputStreamReader reader = new InputStreamReader(
            new ByteArrayInputStream(cms.readFile(bundleResource).getContents()),
            StandardCharsets.UTF_8);
        ret.load(reader);

        return ret;
    }
852803
protected void addResource(String path) {

        CmsPathSelectField field = new CmsPathSelectField();
        field.setCmsObject(m_cms);
        field.setUseRootPaths(true);
        field.setValue(path);
        field.addValueChangeListener(new ValueChangeListener() {

            private static final long serialVersionUID = 8646438704383992571L;

            public void valueChange(ValueChangeEvent event) {

                setOkButtonEnabled(true);

            }
        });
        m_componentsToValidate.add(field);
        CmsRemovableFormRow<CmsPathSelectField> row = new CmsRemovableFormRow<CmsPathSelectField>(
            field,
            CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_SYNC_REMOVE_RESOURCE_0));
        row.setCaption(CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_SYNC_RESOURCE_0));
        row.setRemoveRunnable(new Runnable() {

            public void run() {

                setOkButtonEnabled(true);
            }
        });
        m_resources.addComponent(row);
    }
552707
private String readFile(String path) {

        String result = (String)CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().getCachedObject(m_cms, path);
        if (result == null) {
            try {
                CmsFile file = m_cms.readFile(path);
                result = getContentAsString(file);
            } catch (CmsException e) {
                throw new RuntimeException(e);
            }
        }
        if (result != null) {
            CmsVfsMemoryObjectCache.getVfsMemoryObjectCache().putCachedObject(m_cms, path, result);
        }
        return result;

    }
255000
public CmsCategory getCategory(CmsObject cms, String categoryRootPath) throws CmsException {

        CmsResource resource = cms.readResource(cms.getRequestContext().removeSiteRoot(categoryRootPath));
        return getCategory(cms, resource);
    }
403580
@Override
    public CmsResource getResource(CmsObject cms, CmsListItem item) {

        CmsResource res = null;

        CmsUUID id = new CmsUUID(item.getId());
        if (!id.isNullUUID()) {
            try {
                res = cms.readResource(id, CmsResourceFilter.ALL);
            } catch (CmsException e) {
                // should never happen
                if (LOG.isErrorEnabled()) {
                    LOG.error(e.getLocalizedMessage(), e);
                }
            }
        }

        return res;
    }
773127
public Locale getBestAvailableLocaleForXmlContent(CmsObject cms, CmsResource resource, I_CmsXmlDocument content) {

        Locale locale = getDefaultLocale(cms, resource);
        if (!content.hasLocale(locale)) {
            // if the requested locale is not available, get the first matching default locale,
            // or the first matching available locale
            boolean foundLocale = false;
            if (content.getLocales().size() > 0) {
                List<Locale> locales = getDefaultLocales(cms, resource);
                for (Locale defaultLocale : locales) {
                    if (content.hasLocale(defaultLocale)) {
                        locale = defaultLocale;
                        foundLocale = true;
                        break;
                    }
                }
                if (!foundLocale) {
                    locales = getAvailableLocales(cms, resource);
                    for (Locale availableLocale : locales) {
                        if (content.hasLocale(availableLocale)) {
                            locale = availableLocale;
                            foundLocale = true;
                            break;
                        }
                    }
                }
            }
        }
        return locale;
    }
1356827
public static CmsXmlContentDefinition getContentDefinitionForResource(CmsObject cms, CmsResource resource)
    throws CmsException {

        CmsXmlContentDefinition contentDef = null;
        I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(resource.getTypeId());
        String schema = resType.getConfiguration().get(CmsResourceTypeXmlContent.CONFIGURATION_SCHEMA);
        if (schema != null) {
            try {
                // this wont in most cases read the file content because of caching
                contentDef = unmarshal(cms, schema);
            } catch (CmsException e) {
                // this should never happen, unless the configured schema is different than the schema in the XML
                if (!LOG.isDebugEnabled()) {
                    LOG.warn(e);
                }
                LOG.debug(e.getLocalizedMessage(), e);
            }
        }
        if (contentDef == null) {
            // could still be empty since it is not mandatory to configure the resource type in the XML configuration
            // try through the XSD relation
            List<CmsRelation> relations = cms.getRelationsForResource(
                resource,
                CmsRelationFilter.TARGETS.filterType(CmsRelationType.XSD));
            if ((relations != null) && !relations.isEmpty()) {
                CmsXmlEntityResolver entityResolver = new CmsXmlEntityResolver(cms);
                String xsd = cms.getSitePath(relations.get(0).getTarget(cms, CmsResourceFilter.ALL));
                contentDef = entityResolver.getCachedContentDefinition(xsd);
            }
        }
        if (contentDef == null) {
            // could still be empty if the XML content has been saved with an OpenCms before 8.0.0
            // so, to unmarshal is the only possibility left
            CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, cms.readFile(resource));
            contentDef = content.getContentDefinition();
        }

        return contentDef;
    }
719960
protected CmsResource getResource(CmsObject cms, I_CmsWidgetParameter param) {

        I_CmsXmlContentValue value = (I_CmsXmlContentValue)param;
        CmsFile file = value.getDocument().getFile();
        String resourceName = cms.getSitePath(file);
        if (CmsWorkplace.isTemporaryFile(file)) {
            StringBuffer result = new StringBuffer(resourceName.length() + 2);
            result.append(CmsResource.getFolderPath(resourceName));
            result.append(CmsResource.getName(resourceName).substring(1));
            resourceName = result.toString();
        }
        try {
            List<CmsResource> listsib = cms.readSiblings(resourceName, CmsResourceFilter.ALL);
            for (int i = 0; i < listsib.size(); i++) {
                CmsResource resource = listsib.get(i);
                // get the default locale of the resource
                Locale locale = getDefaultLocale(cms, cms.getSitePath(resource));
                if (locale.equals(value.getLocale())) {
                    // get the property for the right locale
                    return resource;
                }
            }
        } catch (CmsVfsResourceNotFoundException e) {
            // may hapen if editing a new resource
            if (LOG.isDebugEnabled()) {
                LOG.debug(e.getLocalizedMessage(), e);
            }
        } catch (CmsException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return file;
    }
1174537
private LinkedHashMap<String, String> getAvailableLocales(CmsResource resource) {

        LinkedHashMap<String, String> result = null;
        List<Locale> locales = null;
        try {
            if (CmsResourceTypeXmlPage.isXmlPage(resource)) {
                locales = CmsXmlPageFactory.unmarshal(getCmsObject(), resource, getRequest()).getLocales();
            } else if (CmsResourceTypeXmlContent.isXmlContent(resource)) {
                locales = CmsXmlContentFactory.unmarshal(getCmsObject(), resource, getRequest()).getLocales();
            } else if (CmsResourceTypeXmlContainerPage.isContainerPage(resource)) {
                locales = CmsXmlContainerPageFactory.unmarshal(getCmsObject(), resource).getLocales();
            }
        } catch (CmsException e) {
            LOG.warn(e.getLocalizedMessage(), e);
        }
        if (locales != null) {
            Locale wpLocale = OpenCms.getWorkplaceManager().getWorkplaceLocale(getCmsObject());
            result = new LinkedHashMap<String, String>();
            for (Locale locale : locales) {
                result.put(locale.toString(), locale.getDisplayName(wpLocale));
            }
        }
        return result;
    }
339810
private CmsResource getResource(CmsObject cms, String resourcename) {

        return getResource(cms, resourcename, CmsResourceFilter.DEFAULT);
    }
174575
private CmsObject getCmsObject() {

        CmsObject cms;
        try {
            cms = OpenCms.initCmsObject(A_CmsUI.getCmsObject());
            //m_cms.getRequestContext().setSiteRoot("");
        } catch (CmsException e) {
            cms = A_CmsUI.getCmsObject();
        }
        return cms;
    }
1113595
public static CmsFlexBucketConfiguration loadFromVfsFile(CmsObject cms, String path) throws CmsException {

        if (!cms.existsResource(path)) {
            return null;
        }
        CmsResource configRes = cms.readResource(path);
        if (configRes.isFolder()) {
            return null;
        }
        CmsFile configFile = cms.readFile(configRes);
        String encoding = CmsFileUtil.getEncoding(cms, configRes);
        Properties props = new Properties();
        try {
            props.load(new InputStreamReader(new ByteArrayInputStream(configFile.getContents()), encoding));
            return loadFromProperties(props);
        } catch (IOException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
        return null;
    }
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;
        }
    }
872679
protected CmsObject rootCms(CmsObject cms) throws CmsException {

        CmsObject result = OpenCms.initCmsObject(cms);
        result.getRequestContext().setSiteRoot("");
        return result;
    }
365043
public static List<String> getAttachmentLocales(CmsObject cms, CmsResource content) {

        List<CmsResource> detailOnlyResources = CmsDetailOnlyContainerUtil.getDetailOnlyResources(cms, content);
        Set<String> validLocaleNames = Sets.newHashSet();
        List<String> result = Lists.newArrayList();
        for (Locale locale : OpenCms.getLocaleManager().getAvailableLocales()) {
            validLocaleNames.add(locale.toString());
        }
        validLocaleNames.add(CmsDetailOnlyContainerUtil.LOCALE_ALL);
        for (CmsResource resource : detailOnlyResources) {
            String parent = CmsResource.getParentFolder(resource.getRootPath());
            String parentName = CmsResource.getName(parent);
            parentName = CmsFileUtil.removeTrailingSeparator(parentName);
            if (validLocaleNames.contains(parentName)) {
                result.add(parentName);
            }
        }
        return result;

    }
145577
private void saveToPropertyVfsBundle() throws CmsException {

        for (Locale l : m_changedTranslations) {
            SortedProperties props = m_localizations.get(l);
            LockedFile f = m_lockedBundleFiles.get(l);
            if ((null != props) && (null != f)) {
                try {
                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                    Writer writer = new OutputStreamWriter(outputStream, f.getEncoding());
                    props.store(writer, null);
                    byte[] contentBytes = outputStream.toByteArray();
                    CmsFile file = f.getFile();
                    file.setContents(contentBytes);
                    String contentEncodingProperty = m_cms.readPropertyObject(
                        file,
                        CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING,
                        false).getValue();
                    if ((null == contentEncodingProperty) || !contentEncodingProperty.equals(f.getEncoding())) {
                        m_cms.writePropertyObject(
                            m_cms.getSitePath(file),
                            new CmsProperty(
                                CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING,
                                f.getEncoding(),
                                f.getEncoding()));
                    }
                    m_cms.writeFile(file);
                } catch (IOException e) {
                    LOG.error(
                        Messages.get().getBundle().key(
                            Messages.ERR_READING_FILE_UNSUPPORTED_ENCODING_2,
                            f.getFile().getRootPath(),
                            f.getEncoding()),
                        e);

                }
            }
        }
    }
496598
private CmsObject getAdminCms(CmsObject cms) throws CmsException {

        CmsObject adminCms = OpenCms.initCmsObject(m_adminCms);
        adminCms.getRequestContext().setSiteRoot(cms.getRequestContext().getSiteRoot());
        adminCms.getRequestContext().setRequestTime(cms.getRequestContext().getRequestTime());
        adminCms.getRequestContext().setCurrentProject(cms.getRequestContext().getCurrentProject());
        adminCms.getRequestContext().setEncoding(cms.getRequestContext().getEncoding());
        adminCms.getRequestContext().setUri(cms.getRequestContext().getUri());
        return adminCms;
    }