Reads all dependencies that exist for this main resource in provided list of resources.<p>

@param cms the current users OpenCms context
@param folderContent the contents of the folder to check the dependencies for
779390
public void readDependencies(CmsObject cms, List<CmsResource> folderContent) {

        Map<Integer, CmsDocumentDependency> attachments = new HashMap<Integer, CmsDocumentDependency>();
        if (isAttachment()) {
            attachments.put(new Integer(getAttachmentNumber()), this);
        }

        // iterate all resources in the folder to check if this is a language version
        Iterator<CmsResource> i = folderContent.iterator();
        while (i.hasNext()) {
            CmsResource r = i.next();
            // only add files and don't add the resource itself again
            if (r.isFile() && !getResource().getRootPath().equals(r.getRootPath())) {
                CmsPublishedResource pubRes = new CmsPublishedResource(
                    r,
                    getResource().getPublishTag(),
                    CmsResourceState.STATE_CHANGED);
                CmsDocumentDependency dep = new CmsDocumentDependency(pubRes);
                if (getDocumentName().equals(dep.getDocumentName())) {
                    if (isAttachment()) {
                        // this document is an attachment
                        if (dep.isAttachment()) {
                            if ((getAttachmentNumber() == dep.getAttachmentNumber()) && dep.hasLocaleFileName()) {
                                // the dependency must be a language version of this attachment document
                                addVariant(dep);
                            }
                            if (getAttachmentNumber() == dep.getAttachmentNumber()) {
                                dep.setMainDocument(dep);
                            } else {
                                Integer attNum = new Integer(dep.getAttachmentNumber());
                                CmsDocumentDependency att = attachments.get(attNum);
                                if (att != null) {
                                    att.addVariant(dep);
                                } else {
                                    attachments.put(attNum, dep);
                                }
                            }
                        } else {
                            // this is the main document of the dependency
                            setMainDocument(dep);
                        }
                    } else {
                        // this document is a main document
                        if (dep.isAttachment()) {
                            // add this dependency as an attachment
                            addAttachment(dep);
                        } else if (CmsStringUtil.isEqual(getDocumentSuffix(), dep.getDocumentSuffix())) {
                            // if this is no attachment, and the file suffix is equal,
                            // this must be a language version of the main document
                            addVariant(dep);
                        }
                        // if the file suffix is NOT equal, this is a new main document
                        setMainDocument(this);
                    }
                }
            }
        }

        if (m_mainDocument != null) {
            for (CmsDocumentDependency att : attachments.values()) {
                m_mainDocument.addAttachment(att);
            }
            // add the main document as dependency for this attachment
            addDependency(m_mainDocument);
            for (CmsDocumentDependency var : getVariants()) {
                String mainFileName = getMainDocument().getDocumentName();
                if (getMainDocument().getDocumentSuffix() != null) {
                    mainFileName += getMainDocument().getDocumentSuffix();
                }
                if (mainFileName.equals(var.getResource().getRootPath())) {
                    setType(DependencyType.variant);
                    break;
                } else {
                    setType(DependencyType.document);
                    break;
                }
            }
        }
    }
1291907
public CmsLocaleGroup readLocaleGroup(CmsResource resource) throws CmsException {

        if (resource.isFolder()) {
            CmsResource defaultFile = m_cms.readDefaultFile(resource, CmsResourceFilter.IGNORE_EXPIRATION);
            if (defaultFile != null) {
                resource = defaultFile;
            }
        }

        List<CmsRelation> relations = m_cms.readRelations(
            CmsRelationFilter.ALL.filterType(CmsRelationType.LOCALE_VARIANT).filterStructureId(
                resource.getStructureId()));
        List<CmsRelation> out = Lists.newArrayList();
        List<CmsRelation> in = Lists.newArrayList();
        for (CmsRelation rel : relations) {
            if (rel.getSourceId().equals(resource.getStructureId())) {
                out.add(rel);
            } else {
                in.add(rel);
            }
        }
        CmsResource primaryResource = null;
        List<CmsResource> secondaryResources = Lists.newArrayList();
        if ((out.size() == 0) && (in.size() == 0)) {
            primaryResource = resource;
        } else if ((out.size() == 0) && (in.size() > 0)) {
            primaryResource = resource;
            // resource is the primary variant
            for (CmsRelation relation : in) {
                CmsResource source = relation.getSource(m_cms, CmsResourceFilter.ALL);
                secondaryResources.add(source);
            }
        } else if ((out.size() == 1) && (in.size() == 0)) {

            CmsResource target = out.get(0).getTarget(m_cms, CmsResourceFilter.ALL);
            primaryResource = target;
            CmsRelationFilter filter = CmsRelationFilter.TARGETS.filterType(
                CmsRelationType.LOCALE_VARIANT).filterStructureId(target.getStructureId());
            List<CmsRelation> relationsToTarget = m_cms.readRelations(filter);
            for (CmsRelation targetRelation : relationsToTarget) {
                CmsResource secondaryResource = targetRelation.getSource(m_cms, CmsResourceFilter.ALL);
                secondaryResources.add(secondaryResource);
            }
        } else {
            throw new IllegalStateException(
                "illegal locale variant relations for resource with id="
                    + resource.getStructureId()
                    + ", path="
                    + resource.getRootPath());
        }
        return new CmsLocaleGroup(m_cms, primaryResource, secondaryResources);
    }
133618
public void initialize(CmsObject cms) throws CmsRoleViolationException {

        OpenCms.getRoleManager().checkRole(cms, CmsRole.WORKPLACE_MANAGER);
        try {
            // store the Admin cms to index Cms resources
            m_adminCms = OpenCms.initCmsObject(cms);
        } catch (CmsException e) {
            // this should never happen
            LOG.error(e.getLocalizedMessage(), e);
        }
        // make sure the site root is the root site
        m_adminCms.getRequestContext().setSiteRoot("/");

        // create the extraction result cache
        m_extractionResultCache = new CmsExtractionResultCache(
            OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(getDirectory()),
            "/extractCache");
        initializeFieldConfigurations();
        initializeIndexes();
        initOfflineIndexes();

        // register this object as event listener
        OpenCms.addCmsEventListener(
            this,
            new int[] {
                I_CmsEventListener.EVENT_CLEAR_CACHES,
                I_CmsEventListener.EVENT_PUBLISH_PROJECT,
                I_CmsEventListener.EVENT_REBUILD_SEARCHINDEXES});
    }
681008
private static List<CmsCategory> getCategories(CmsObject cms, CmsResource resource) {

        if ((null != resource) && (null != cms)) {
            try {
                return CmsCategoryService.getInstance().readResourceCategories(cms, resource);
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        return new ArrayList<CmsCategory>(0);
    }
369158
private static Set<CmsResource> getAllResourcesInModule(CmsObject cms, CmsModule module) throws CmsException {

        Set<CmsResource> result = new HashSet<>();
        for (CmsResource resource : CmsModule.calculateModuleResources(cms, module)) {
            result.add(resource);
            if (resource.isFolder()) {
                result.addAll(cms.readResources(resource, CmsResourceFilter.ALL, true));
            }
        }
        return result;
    }
430334
public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsException {

        logContentExtraction(resource, index);
        try {
            CmsFile file = readFile(cms, resource);
            CmsXmlPage page = CmsXmlPageFactory.unmarshal(cms, file);
            Locale locale = index.getLocaleForResource(cms, resource, page.getLocales());

            List<String> elements = page.getNames(locale);
            StringBuffer content = new StringBuffer();
            LinkedHashMap<String, String> items = new LinkedHashMap<String, String>();
            for (Iterator<String> i = elements.iterator(); i.hasNext();) {
                String elementName = i.next();
                String value = page.getStringValue(cms, elementName, locale);
                String extracted = CmsHtmlExtractor.extractText(value, page.getEncoding());
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(extracted)) {
                    items.put(elementName, 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);
        }
    }
271049
protected CmsResource readJspResource(CmsFlexController controller, String jspName) throws CmsException {

        // create an OpenCms user context that operates in the root site
        CmsObject cms = OpenCms.initCmsObject(controller.getCmsObject());
        // we only need to change the site, but not the project,
        // since the request has already the right project set
        cms.getRequestContext().setSiteRoot("");
        // try to read the resource
        return cms.readResource(jspName);
    }
613009
private List<CmsResource> getResources() {

        List<CmsResource> result = new LinkedList<CmsResource>();
        CmsObject cms = getCms();
        CmsResourceFilter filter = CmsResourceFilter.ALL;
        try {
            for (String path : m_paths) {
                List<CmsResource> resources = cms.readResources(path, filter, true);
                result.addAll(resources);
            }
        } catch (CmsException e) {
            if (LOG.isErrorEnabled()) {
                LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_PROPERTYVIEWER_READRESOURCES_0), e);
            }
            result = Collections.emptyList();
        }
        return result;
    }
812322
public void loadAndValidate() throws CmsConfigurationException {

        CmsModule module = CmsModuleImportExportHandler.readModuleFromImport(m_path);
        m_module = module;
        List<CmsModuleDependency> dependencies = OpenCms.getModuleManager().checkDependencies(
            module,
            CmsModuleManager.DEPENDENCY_MODE_IMPORT);
        if (!dependencies.isEmpty()) {
            StringBuffer dep = new StringBuffer(32);
            for (int i = 0; i < dependencies.size(); i++) {
                CmsModuleDependency dependency = dependencies.get(i);
                dep.append("\n - ");
                dep.append(dependency.getName());
                dep.append(" (Version: ");
                dep.append(dependency.getVersion());
                dep.append(")");
            }
            throw new CmsConfigurationException(
                org.opencms.ui.apps.Messages.get().container(
                    org.opencms.ui.apps.Messages.ERR_MODULEMANAGER_ACTION_MODULE_DEPENDENCY_2,
                    m_path,
                    new String(dep)));
        }
    }
937246
public String getFolderPath(CmsObject cms, String pageFolderRootPath) {

        checkInitialized();
        if (m_folderOrName != null) {
            return m_folderOrName.getFolderPath(cms, pageFolderRootPath);
        } else {
            String siteRoot = null;
            if (pageFolderRootPath != null) {
                siteRoot = OpenCms.getSiteManager().getSiteRoot(pageFolderRootPath);
            }
            if (siteRoot == null) {
                siteRoot = cms.getRequestContext().getSiteRoot();
            }
            return CmsStringUtil.joinPaths(siteRoot, CmsADEManager.CONTENT_FOLDER_NAME, m_typeName);
        }
    }
108485
private CmsUgcContent readContent(CmsUgcSession session, CmsResource resource) throws CmsException {

        CmsUgcContent formContent = new CmsUgcContent();
        Map<String, String> contentValues = session.getValues();
        formContent.setContentValues(contentValues);
        formContent.setSessionId(session.getId());
        formContent.setResourceType(OpenCms.getResourceManager().getResourceType(resource).getTypeName());
        formContent.setSitePath(getCmsObject().getSitePath(resource));
        formContent.setStrucureId(resource.getStructureId());
        return formContent;
    }
361208
public static CmsExtractionResult extractXmlContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsException {

        return extractXmlContent(cms, resource, index, null);
    }
1102065
public void checkConsistency(CmsObject cms) {

        if (!m_internal || (cms == null)) {
            return;
        }

        // in case of static resource links use the null UUID
        if (CmsStaticResourceHandler.isStaticResourceUri(m_target)) {
            m_structureId = CmsUUID.getNullUUID();
            return;
        }

        try {
            if (m_structureId == null) {
                // try by path
                throw new CmsException(Messages.get().container(Messages.LOG_BROKEN_LINK_NO_ID_0));
            }
            // first look for the resource with the given structure id
            String rootPath = null;
            CmsResource res;
            try {
                res = cms.readResource(m_structureId, CmsResourceFilter.ALL);
                rootPath = res.getRootPath();
                if (!res.getRootPath().equals(m_target)) {
                    // update path if needed
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(
                            Messages.get().getBundle().key(
                                Messages.LOG_BROKEN_LINK_UPDATED_BY_ID_3,
                                m_structureId,
                                m_target,
                                res.getRootPath()));
                    }

                }
            } catch (CmsException e) {
                // not found
                throw new CmsVfsResourceNotFoundException(
                    org.opencms.db.generic.Messages.get().container(
                        org.opencms.db.generic.Messages.ERR_READ_RESOURCE_1,
                        m_target),
                    e);
            }
            if ((rootPath != null) && !rootPath.equals(m_target)) {
                // set the new target
                m_target = res.getRootPath();
                setUri();
                // update xml node
                CmsLinkUpdateUtil.updateXml(this, m_element, true);
            }
        } catch (CmsException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(Messages.get().getBundle().key(Messages.LOG_BROKEN_LINK_BY_ID_2, m_target, m_structureId), e);
            }
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_target)) {
                // no correction is possible
                return;
            }
            // go on with the resource with the given path
            String siteRoot = cms.getRequestContext().getSiteRoot();
            try {
                cms.getRequestContext().setSiteRoot("");
                // now look for the resource with the given path
                CmsResource res = cms.readResource(m_target, CmsResourceFilter.ALL);
                if (!res.getStructureId().equals(m_structureId)) {
                    // update structure id if needed
                    if (LOG.isDebugEnabled()) {
                        LOG.debug(
                            Messages.get().getBundle().key(
                                Messages.LOG_BROKEN_LINK_UPDATED_BY_NAME_3,
                                m_target,
                                m_structureId,
                                res.getStructureId()));
                    }
                    m_target = res.getRootPath(); // could change by a translation rule
                    m_structureId = res.getStructureId();
                    CmsLinkUpdateUtil.updateXml(this, m_element, true);
                }
            } catch (CmsException e1) {
                // no correction was possible
                if (LOG.isDebugEnabled()) {
                    LOG.debug(Messages.get().getBundle().key(Messages.LOG_BROKEN_LINK_BY_NAME_1, m_target), e1);
                }
                m_structureId = null;
            } finally {
                cms.getRequestContext().setSiteRoot(siteRoot);
            }
        }
    }
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);
    }
576159
public void loadProjects() {

        CmsObject cms = A_CmsUI.getCmsObject();
        Locale locale = UI.getCurrent().getLocale();
        m_container.removeAllItems();
        boolean isMultiOU = false;
        // hide ou column if only one ou exists
        try {
            isMultiOU = !OpenCms.getOrgUnitManager().getOrganizationalUnits(cms, "", true).isEmpty();
        } catch (CmsException e) {
            // noop
        }
        if (isMultiOU) {
            setVisibleColumns(
                CmsProjectsTable.PROP_NAME,
                CmsProjectsTable.PROP_DESCRIPTION,
                PROP_PUBLISH_DATE,
                PROP_PUBLISH_USER,
                CmsProjectsTable.PROP_ORG_UNIT,
                CmsProjectsTable.PROP_OWNER,
                CmsProjectsTable.PROP_MANAGER,
                CmsProjectsTable.PROP_USER,
                CmsProjectsTable.PROP_DATE_CREATED,
                CmsProjectsTable.PROP_RESOURCES);
        } else {
            setVisibleColumns(
                CmsProjectsTable.PROP_NAME,
                CmsProjectsTable.PROP_DESCRIPTION,
                PROP_PUBLISH_DATE,
                PROP_PUBLISH_USER,
                CmsProjectsTable.PROP_OWNER,
                CmsProjectsTable.PROP_MANAGER,
                CmsProjectsTable.PROP_USER,
                CmsProjectsTable.PROP_DATE_CREATED,
                CmsProjectsTable.PROP_RESOURCES);
        }

        // get content
        try {
            List<CmsHistoryProject> projects = cms.getAllHistoricalProjects();
            for (CmsHistoryProject project : projects) {
                Item item = m_container.addItem(new Integer(project.getPublishTag()));
                if (item != null) {
                    item.getItemProperty(CmsProjectsTable.PROP_ID).setValue(project.getUuid());
                    item.getItemProperty(CmsProjectsTable.PROP_NAME).setValue(project.getSimpleName());
                    item.getItemProperty(CmsProjectsTable.PROP_DESCRIPTION).setValue(project.getDescription());
                    item.getItemProperty(PROP_PUBLISH_DATE).setValue(new Date(project.getPublishingDate()));
                    item.getItemProperty(PROP_PUBLISH_USER).setValue(project.getPublishedByName(cms));
                    try {
                        item.getItemProperty(CmsProjectsTable.PROP_ORG_UNIT).setValue(
                            OpenCms.getOrgUnitManager().readOrganizationalUnit(cms, project.getOuFqn()).getDisplayName(
                                locale));
                        item.getItemProperty(CmsProjectsTable.PROP_OWNER).setValue(
                            cms.readUser(project.getOwnerId()).getName());
                        item.getItemProperty(CmsProjectsTable.PROP_MANAGER).setValue(
                            cms.readGroup(project.getManagerGroupId()).getSimpleName());
                        item.getItemProperty(CmsProjectsTable.PROP_USER).setValue(
                            cms.readGroup(project.getGroupId()).getSimpleName());
                    } catch (CmsException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    item.getItemProperty(CmsProjectsTable.PROP_DATE_CREATED).setValue(
                        new Date(project.getDateCreated()));

                    StringBuffer html = new StringBuffer(512);
                    for (String resource : cms.readProjectResources(project)) {
                        html.append(resource);
                        html.append("<br />");
                    }
                    Label resLabel = new Label();
                    resLabel.setContentMode(ContentMode.HTML);
                    resLabel.setValue(html.toString());
                    item.getItemProperty(CmsProjectsTable.PROP_RESOURCES).setValue(resLabel);
                }
            }
            m_container.sort(new Object[] {PROP_PUBLISH_DATE}, new boolean[] {false});
        } catch (CmsException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
1027201
public void initResource(CmsObject cms) throws CmsException {

        if (m_resource == null) {
            m_resource = cms.readResource(getId(), CmsResourceFilter.IGNORE_EXPIRATION);
            m_releasedAndNotExpired = m_resource.isReleasedAndNotExpired(cms.getRequestContext().getRequestTime());
        } else if (!isInMemoryOnly()) {
            CmsUUID id = m_resource.getStructureId();
            if (id == null) {
                id = getId();
            }
            // the resource object may have a wrong root path, e.g. if it was created before the resource was moved
            if (cms.getRequestContext().getCurrentProject().isOnlineProject()) {
                m_resource = cms.readResource(id, CmsResourceFilter.IGNORE_EXPIRATION);
                m_releasedAndNotExpired = m_resource.isReleasedAndNotExpired(cms.getRequestContext().getRequestTime());
            } else {
                if (!isTemporaryContent()) {
                    m_resource = cms.readResource(getId(), CmsResourceFilter.IGNORE_EXPIRATION);
                }
                m_releasedAndNotExpired = m_resource.isReleasedAndNotExpired(cms.getRequestContext().getRequestTime());
            }
        }
        if (m_settings == null) {
            setSettings(new HashMap<String, String>(getIndividualSettings()));
        }
        // redo on every init call to ensure sitepath is calculated for current site
        m_sitePath = cms.getSitePath(m_resource);
    }
134742
public CmsResource ensureModelFolder(CmsResource rootResource) throws CmsException {

        String modelFolderPath = CmsStringUtil.joinPaths(m_adeConfig.getBasePath(), ".content/.templates");

        try {
            CmsResource result = m_cms.readFolder(modelFolderPath);
            return result;
        } catch (CmsVfsResourceNotFoundException e) {
            CmsProperty searchExclude = new CmsProperty(CmsPropertyDefinition.PROPERTY_SEARCH_EXCLUDE, "all", null);
            CmsResource result = m_cms.createResource(
                modelFolderPath,
                getType(CmsResourceTypeFolder.getStaticTypeName()),
                null,
                Arrays.asList(searchExclude));
            tryUnlock(result);
            return result;
        }

    }