Returns the element settings for a given resource.<p>

@param cms the current cms context
@param resource the resource

@return the element settings for a given resource

@throws CmsException if something goes wrong
556356
public Map<String, CmsXmlContentProperty> getElementSettings(CmsObject cms, CmsResource resource)
    throws CmsException {

        if (CmsResourceTypeXmlContent.isXmlContent(resource)) {
            Map<String, CmsXmlContentProperty> result = new LinkedHashMap<String, CmsXmlContentProperty>();
            Map<String, CmsXmlContentProperty> settings = CmsXmlContentDefinition.getContentHandlerForResource(
                cms,
                resource).getSettings(cms, resource);
            result.putAll(settings);
            return CmsXmlContentPropertyHelper.copyPropertyConfiguration(result);
        }
        return Collections.<String, CmsXmlContentProperty> emptyMap();
    }
675960
public CmsCategory getCategory(CmsObject cms, CmsResource resource) throws CmsException {

        CmsProperty title = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, false);
        CmsProperty description = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
        return new CmsCategory(
            resource.getStructureId(),
            resource.getRootPath(),
            title.getValue(resource.getName()),
            description.getValue(""),
            getRepositoryBaseFolderName(cms));
    }
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);
        }
    }
339810
private CmsResource getResource(CmsObject cms, String resourcename) {

        return getResource(cms, resourcename, CmsResourceFilter.DEFAULT);
    }
601394
private void init(CmsResource resource, CmsObject cms) {

        List<CmsProperty> properties;

        try {
            properties = cms.readPropertyObjects(resource, false);
        } catch (CmsException e) {
            m_priority = 0;
            m_title = "";
            return;
        }

        try {
            m_priority = Integer.parseInt(
                CmsProperty.get(CmsPriorityResourceCollector.PROPERTY_PRIORITY, properties).getValue());
        } catch (NumberFormatException e) {
            m_priority = CmsPriorityResourceCollector.PRIORITY_STANDARD;
        }

        m_title = CmsProperty.get(CmsPropertyDefinition.PROPERTY_TITLE, properties).getValue();
        if (CmsStringUtil.isEmpty(m_title)) {
            m_title = "";
        }
    }
534525
private void getConfiguration() throws CmsException {

        if ((m_configuredErrorChecks == null) || (m_configuredWarningChecks == null)) {
            // get the configuration file
            CmsResource res = m_cms.readResource(CONFIGURATION);
            if (LOG.isDebugEnabled()) {
                LOG.debug(
                    Messages.get().getBundle().key(Messages.LOG_DEBUG_PROPERTY_CONFIG_FILENAME_1, res.getRootPath()));
            }
            CmsFile file = m_cms.readFile(res);
            if (LOG.isDebugEnabled()) {
                LOG.debug(
                    Messages.get().getBundle().key(
                        Messages.LOG_DEBUG_PROPERTY_CONFIG_FILE_1,
                        new String(file.getContents())));
            }
            CmsXmlContent configuration = CmsXmlContentFactory.unmarshal(m_cms, file);

            // now extract the configured error checks from it
            m_configuredErrorChecks = getConfiguredChecks(configuration, XPATH_ERROR);
            m_configuredWarningChecks = getConfiguredChecks(configuration, XPATH_WARNUING);
        }
    }
7799
public String updateContextAndGetFavoriteUrl(CmsObject cms) throws CmsException {

        CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION;
        CmsProject project = null;
        switch (getType()) {
            case explorerFolder:
                CmsResource folder = cms.readResource(getStructureId(), filter);
                project = cms.readProject(getProjectId());
                cms.getRequestContext().setSiteRoot(getSiteRoot());
                cms.getRequestContext().setCurrentProject(project);
                String explorerLink = CmsVaadinUtils.getWorkplaceLink()
                    + "#!"
                    + CmsFileExplorerConfiguration.APP_ID
                    + "/"
                    + getProjectId()
                    + "!!"
                    + getSiteRoot()
                    + "!!"
                    + cms.getSitePath(folder);
                return explorerLink;
            case page:
                project = cms.readProject(getProjectId());
                CmsResource target = cms.readResource(getStructureId(), filter);
                CmsResource detailContent = null;
                String link = null;
                cms.getRequestContext().setCurrentProject(project);
                cms.getRequestContext().setSiteRoot(getSiteRoot());
                if (getDetailId() != null) {
                    detailContent = cms.readResource(getDetailId());
                    link = OpenCms.getLinkManager().substituteLinkForUnknownTarget(
                        cms,
                        cms.getSitePath(detailContent),
                        cms.getSitePath(target),
                        false);
                } else {
                    link = OpenCms.getLinkManager().substituteLink(cms, target);
                }
                return link;
            default:
                return null;
        }
    }
1365670
@SuppressWarnings("unused")
    public Set<String> getCSSHeadIncludes(CmsObject cms, CmsResource resource) throws CmsException {

        return getCSSHeadIncludes();
    }
290183
private void saveElementList(CmsObject cms, List<CmsContainerElementBean> elementList, String listKey)
    throws CmsException {

        // limit the favorite list size to avoid the additional info size limit
        if (elementList.size() > DEFAULT_ELEMENT_LIST_SIZE) {
            elementList = elementList.subList(0, DEFAULT_ELEMENT_LIST_SIZE);
        }

        JSONArray data = new JSONArray();

        Set<String> excludedSettings = new HashSet<String>();
        // do not store the template contexts, since dragging an element into the page which might be invisible
        // doesn't make sense
        excludedSettings.add(CmsTemplateContextInfo.SETTING);

        for (CmsContainerElementBean element : elementList) {
            data.put(elementToJson(element, excludedSettings));
        }
        CmsUser user = cms.getRequestContext().getCurrentUser();
        user.setAdditionalInfo(listKey, data.toString());
        cms.writeUser(user);
    }
749135
protected CmsPublishResource createPublishResource(CmsResource resource) throws CmsException {

        CmsResourceUtil resUtil = new CmsResourceUtil(m_cms, resource);
        CmsPermissionInfo permissionInfo = OpenCms.getADEManager().getPermissionInfo(m_cms, resource, null);

        String typeName = CmsIconUtil.getDisplayType(m_cms, resource);
        String detailTypeName = CmsResourceIcon.getDefaultFileOrDetailType(m_cms, resource);
        CmsPublishResource pubResource = new CmsPublishResource(
            resource.getStructureId(),
            resUtil.getFullPath(),
            resUtil.getTitle(),
            typeName,
            resource.getState(),
            permissionInfo,
            resource.getDateLastModified(),
            resUtil.getUserLastModified(),
            CmsVfsService.formatDateTime(m_cms, resource.getDateLastModified()),
            false,
            null,
            new ArrayList<CmsPublishResource>());
        pubResource.setBigIconClasses(CmsIconUtil.getIconClasses(typeName, resource.getName(), false));
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(detailTypeName)) {
            pubResource.setSmallIconClasses(CmsIconUtil.getIconClasses(detailTypeName, null, true));
        }
        return pubResource;
    }
1211402
public static CmsListInfoBean getPageInfo(CmsObject cms, CmsResource res) throws CmsException {

        CmsListInfoBean result = new CmsListInfoBean();
        addPageInfo(cms, res, result);
        return result;
    }
467816
private void lock(CmsObject cms, CmsResource resource) throws CmsException {

        CmsLock lock = cms.getLock(resource);
        if (lock.isUnlocked()) {
            cms.lockResourceTemporary(resource);
        } else {
            cms.changeLock(resource);
        }
    }
1103005
public Map<String, CmsXmlContentProperty> getSettingConfig(String containerName) {

        CmsFormatterConfig formatterConfig = getFormatterConfig(containerName);
        return formatterConfig != null
        ? formatterConfig.getSettingConfig()
        : Collections.<String, CmsXmlContentProperty> emptyMap();
    }
1043826
public CmsContainerElement setElementInfo(CmsContainerElementBean elementBean, CmsContainerElement result)
    throws CmsException {

        Locale wpLocale = OpenCms.getWorkplaceManager().getWorkplaceLocale(m_cms);
        // reinitializing resource to avoid caching issues
        elementBean.initResource(m_cms);
        CmsResource resource = elementBean.getResource();
        boolean isModelGroup = elementBean.getIndividualSettings().containsKey(CmsContainerElement.MODEL_GROUP_ID);
        if (isModelGroup) {
            CmsUUID groupId = new CmsUUID(elementBean.getIndividualSettings().get(CmsContainerElement.MODEL_GROUP_ID));
            resource = m_cms.readResource(groupId, CmsResourceFilter.IGNORE_EXPIRATION);
        }

        boolean newEditorDisabled = !CmsWorkplaceEditorManager.checkAcaciaEditorAvailable(
            m_cms,
            elementBean.getResource());
        result.setNewEditorDisabled(newEditorDisabled);
        I_CmsResourceType resourceType = OpenCms.getResourceManager().getResourceType(resource);
        String typeName = resourceType.getTypeName();
        result.setHasEditHandler(
            (resourceType instanceof CmsResourceTypeXmlContent)
                && (((CmsResourceTypeXmlContent)resourceType).getEditHandler(m_cms) != null));
        result.setResourceType(typeName);
        result.setIconClasses(
            CmsIconUtil.getIconClasses(
                CmsIconUtil.getDisplayType(m_cms, resource),
                elementBean.getResource().getName(),
                false));
        CmsPermissionInfo permissionInfo;
        String title;
        String subTitle;
        if (!elementBean.isInMemoryOnly()) {
            permissionInfo = OpenCms.getADEManager().getPermissionInfo(m_cms, resource, m_page.getRootPath());
            if (CmsResourceTypeXmlContent.isXmlContent(resource)) {
                if (CmsStringUtil.isEmptyOrWhitespaceOnly(permissionInfo.getNoEditReason())
                    && elementBean.isInheritedContainer(m_cms)) {
                    String requestUri = m_cms.getRequestContext().getUri();
                    String folderPath = CmsResource.getFolderPath(requestUri);
                    String configPath = CmsStringUtil.joinPaths(
                        folderPath,
                        CmsContainerConfigurationCache.INHERITANCE_CONFIG_FILE_NAME);
                    if (m_cms.existsResource(configPath)) {
                        permissionInfo.setNoEditReason(
                            new CmsResourceUtil(m_cms, m_cms.readResource(configPath)).getNoEditReason(wpLocale, true));
                    } else {
                        if (!m_cms.getLock(folderPath).isLockableBy(m_cms.getRequestContext().getCurrentUser())) {
                            permissionInfo.setNoEditReason(
                                org.opencms.workplace.explorer.Messages.get().getBundle(wpLocale).key(
                                    org.opencms.workplace.explorer.Messages.GUI_NO_EDIT_REASON_LOCK_1,
                                    new CmsResourceUtil(m_cms, m_cms.readResource(folderPath)).getLockedByName()));
                        }
                    }
                }
            } else {
                permissionInfo.setNoEditReason(
                    Messages.get().getBundle(wpLocale).key(Messages.GUI_ELEMENT_RESOURCE_CAN_NOT_BE_EDITED_0));
            }
            CmsGallerySearchResult searchResult = CmsGallerySearch.searchById(
                m_cms,
                resource.getStructureId(),
                m_locale);
            title = searchResult.getTitle();
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(title)) {
                resource.getName();
            }
            subTitle = searchResult.getUserLastModified();
            Date lastModDate = searchResult.getDateLastModified();
            if (lastModDate != null) {
                subTitle += " / " + CmsDateUtil.getDateTime(lastModDate, DateFormat.MEDIUM, wpLocale);
            }
        } else {
            permissionInfo = new CmsPermissionInfo(true, true, "");
            title = CmsWorkplaceMessages.getResourceTypeName(wpLocale, typeName);
            subTitle = CmsWorkplaceMessages.getResourceTypeDescription(wpLocale, typeName);
        }
        result.setTitle(title);
        result.setSubTitle(subTitle);
        result.setClientId(elementBean.editorHash());
        result.setSitePath(m_cms.getSitePath(resource));

        result.setCreateNew(elementBean.isCreateNew());
        CmsResourceTypeConfig typeConfig = getConfigData().getResourceType(typeName);
        if (typeConfig != null) {
            result.setCopyInModels(typeConfig.isCopyInModels());
        }
        Map<CmsUUID, CmsElementView> viewMap = OpenCms.getADEManager().getElementViews(m_cms);

        boolean isModelGroupEditing = CmsModelGroupHelper.isModelGroupResource(m_page);
        if (!isModelGroup
            && isModelGroupEditing
            && elementBean.getIndividualSettings().containsKey(CmsContainerElement.MODEL_GROUP_STATE)
            && (ModelGroupState.isModelGroup == ModelGroupState.evaluate(
                elementBean.getIndividualSettings().get(CmsContainerElement.MODEL_GROUP_STATE)))) {
            isModelGroup = true;
        }
        if (!isModelGroupEditing && isModelGroup) {
            CmsResourceTypeConfig modelGroupConfig = getConfigData().getResourceType(
                CmsResourceTypeXmlContainerPage.MODEL_GROUP_TYPE_NAME);
            if (modelGroupConfig != null) {
                CmsUUID elementView = modelGroupConfig.getElementView();
                CmsElementView viewObject = viewMap.get(elementView);
                if ((viewObject != null) && (viewObject.getParentViewId() != null)) {
                    elementView = viewObject.getParentViewId();
                }
                result.setElementView(elementView);
            }
        } else if (typeConfig != null) {
            CmsUUID elementView = typeConfig.getElementView();
            CmsElementView viewObject = viewMap.get(elementView);
            if ((viewObject != null) && (viewObject.getParentViewId() != null)) {
                elementView = viewObject.getParentViewId();
            }
            result.setElementView(elementView);
        }
        if (elementBean.isCreateNew()
            && CmsStringUtil.isEmptyOrWhitespaceOnly(permissionInfo.getNoEditReason())
            && ((typeConfig == null)
                || !typeConfig.checkCreatable(m_cms, CmsResource.getParentFolder(m_page.getRootPath())))) {
            String niceName = CmsWorkplaceMessages.getResourceTypeName(wpLocale, typeName);
            permissionInfo.setNoEditReason(
                Messages.get().getBundle(wpLocale).key(Messages.GUI_CONTAINERPAGE_TYPE_NOT_CREATABLE_1, niceName));
        }
        result.setHasSettings(hasSettings(m_cms, elementBean.getResource()));
        result.setPermissionInfo(permissionInfo);
        result.setReleasedAndNotExpired(elementBean.isReleasedAndNotExpired());
        if (elementBean.isModelGroup()) {
            String modelId = elementBean.getIndividualSettings().get(CmsContainerElement.MODEL_GROUP_ID);
            result.setModelGroupId(modelId != null ? new CmsUUID(modelId) : CmsUUID.getNullUUID());
        }
        result.setWasModelGroup(
            elementBean.getIndividualSettings().containsKey(CmsContainerElement.MODEL_GROUP_STATE)
                && (ModelGroupState.evaluate(
                    elementBean.getIndividualSettings().get(
                        CmsContainerElement.MODEL_GROUP_STATE)) == ModelGroupState.wasModelGroup));
        return result;
    }
74705
private static CmsWorkplaceSettings getWorkplaceSettings(CmsObject cms, HttpSession session) {

        CmsWorkplaceSettings settings = (CmsWorkplaceSettings)session.getAttribute(
            CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS);
        if (settings == null) {
            settings = CmsLoginHelper.initSiteAndProject(cms);
            if (VaadinService.getCurrentRequest() != null) {
                VaadinService.getCurrentRequest().getWrappedSession().setAttribute(
                    CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS,
                    settings);
            } else {
                session.setAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS, settings);
            }
        }
        return settings;
    }
580437
public static List<CmsContainerElementBean> loadInheritContainerElements(CmsObject cms, CmsResource resource) {

        CmsInheritanceReferenceParser parser = new CmsInheritanceReferenceParser(cms);
        try {
            parser.parse(resource);
            CmsInheritanceReference ref = parser.getReference(cms.getRequestContext().getLocale());
            if (ref != null) {
                String name = ref.getName();
                CmsADEManager adeManager = OpenCms.getADEManager();
                CmsInheritedContainerState result = adeManager.getInheritedContainerState(
                    cms,
                    cms.getRequestContext().getRootUri(),
                    name);
                return result.getElements(false);
            }
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
        return Collections.emptyList();
    }
583284
public static boolean hasChildren(CmsObject cms, CmsResource resource) throws CmsException {

        return !cms.getResourcesInFolder(cms.getSitePath(resource), CmsResourceFilter.ALL).isEmpty();
    }