Reads the bundle descriptor, sets m_desc and m_descContent.
@throws CmsXmlException thrown when unmarshalling fails.
@throws CmsException thrown when reading the resource fails or several bundle descriptors for the bundle exist.
332553
private void initDescriptor() throws CmsXmlException, CmsException {

        if (m_bundleType.equals(CmsMessageBundleEditorTypes.BundleType.DESCRIPTOR)) {
            m_desc = m_resource;
        } else {
            //First try to read from same folder like resource, if it fails use CmsMessageBundleEditorTypes.getDescriptor()
            try {
                m_desc = m_cms.readResource(m_sitepath + m_basename + CmsMessageBundleEditorTypes.Descriptor.POSTFIX);
            } catch (CmsVfsResourceNotFoundException e) {
                m_desc = CmsMessageBundleEditorTypes.getDescriptor(m_cms, m_basename);
            }
        }
        unmarshalDescriptor();

    }
1267219
private void updateBundleDescriptorContent() throws CmsXmlException {

        if (m_descContent.hasLocale(Descriptor.LOCALE)) {
            m_descContent.removeLocale(Descriptor.LOCALE);
        }
        m_descContent.addLocale(m_cms, Descriptor.LOCALE);

        int i = 0;
        Property<Object> descProp;
        String desc;
        Property<Object> defaultValueProp;
        String defaultValue;
        Map<String, Item> keyItemMap = getKeyItemMap();
        List<String> keys = new ArrayList<String>(keyItemMap.keySet());
        Collections.sort(keys, CmsCaseInsensitiveStringComparator.getInstance());
        for (Object key : keys) {
            if ((null != key) && !key.toString().isEmpty()) {

                m_descContent.addValue(m_cms, Descriptor.N_MESSAGE, Descriptor.LOCALE, i);
                i++;
                String messagePrefix = Descriptor.N_MESSAGE + "[" + i + "]/";

                m_descContent.getValue(messagePrefix + Descriptor.N_KEY, Descriptor.LOCALE).setStringValue(
                    m_cms,
                    (String)key);
                descProp = keyItemMap.get(key).getItemProperty(TableProperty.DESCRIPTION);
                if ((null != descProp) && (null != descProp.getValue())) {
                    desc = descProp.getValue().toString();
                    m_descContent.getValue(messagePrefix + Descriptor.N_DESCRIPTION, Descriptor.LOCALE).setStringValue(
                        m_cms,
                        desc);
                }

                defaultValueProp = keyItemMap.get(key).getItemProperty(TableProperty.DEFAULT);
                if ((null != defaultValueProp) && (null != defaultValueProp.getValue())) {
                    defaultValue = defaultValueProp.getValue().toString();
                    m_descContent.getValue(messagePrefix + Descriptor.N_DEFAULT, Descriptor.LOCALE).setStringValue(
                        m_cms,
                        defaultValue);
                }

            }
        }

    }
126422
protected void init() throws JspException {

        // initialize OpenCms access objects
        m_controller = CmsFlexController.getController(pageContext.getRequest());
        m_cms = m_controller.getCmsObject();

        try {
            I_CmsSearchConfiguration config = null;
            if (m_configFile != null) {
                CmsFile configFile = m_cms.readFile(CmsJspElFunctions.convertRawResource(m_cms, m_configFile));
                if (m_fileFormat == FileFormat.JSON) {
                    // read the JSON config file
                    OpenCms.getLocaleManager();
                    String configString = new String(
                        configFile.getContents(),
                        CmsLocaleManager.getResourceEncoding(m_cms, configFile));
                    config = new CmsSearchConfiguration(new CmsJSONSearchConfigurationParser(configString));
                } else { // assume XML
                    CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(m_cms, configFile);
                    config = new CmsSearchConfiguration(
                        new CmsXMLSearchConfigurationParser(xmlContent, m_cms.getRequestContext().getLocale()));
                }
            }
            if (m_configString != null) {
                if (m_configString.trim().startsWith("{")) {
                    config = new CmsSearchConfiguration(new CmsJSONSearchConfigurationParser(m_configString, config));
                } else {
                    config = new CmsSearchConfiguration(
                        new CmsPlainQuerySearchConfigurationParser(m_configString, config));
                }
            }
            m_searchController = new CmsSearchController(config);

            String indexName = m_searchController.getCommon().getConfig().getSolrIndex();
            // try to use configured index
            if ((indexName != null) && !indexName.trim().isEmpty()) {
                m_index = OpenCms.getSearchManager().getIndexSolr(indexName);
            }
            // if not successful, use the following default
            if (m_index == null) {
                m_index = OpenCms.getSearchManager().getIndexSolr(
                    m_cms.getRequestContext().getCurrentProject().isOnlineProject()
                    ? CmsSolrIndex.DEFAULT_INDEX_NAME_ONLINE
                    : CmsSolrIndex.DEFAULT_INDEX_NAME_OFFLINE);
            }

            storeAttribute(getVar(), getSearchResults());

        } catch (Exception e) { // CmsException | UnsupportedEncodingException | JSONException
            LOG.error(e.getLocalizedMessage(), e);
            m_controller.setThrowable(e, m_cms.getRequestContext().getUri());
            throw new JspException(e);
        }
    }
115696
private void initKeySetForXmlBundle() {

        // consider only available locales
        for (Locale l : m_locales) {
            if (m_xmlBundle.hasLocale(l)) {
                Set<Object> keys = new HashSet<Object>();
                for (I_CmsXmlContentValue msg : m_xmlBundle.getValueSequence("Message", l).getValues()) {
                    String msgpath = msg.getPath();
                    keys.add(m_xmlBundle.getStringValue(m_cms, msgpath + "/Key", l));
                }
                m_keyset.updateKeySet(null, keys);
            }
        }

    }
936772
public void init(CmsObject cms, Locale locale, I_CmsXmlDocument content, CmsResource resource) {

        m_cms = cms;
        m_requestedLocale = locale;
        m_content = content;
        m_resource = resource;
    }
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;
    }
272868
protected List<CmsResource> readTree(String rootPath) throws CmsException {

        rootPath = CmsFileUtil.removeTrailingSeparator(rootPath);
        CmsResource base = m_cms.readResource(rootPath);

        I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(base);
        List<CmsResource> result = new ArrayList<CmsResource>();
        if (resType.isFolder()) {
            rootPath = CmsStringUtil.joinPaths(rootPath, "/");
            List<CmsResource> subResources = m_cms.readResources(rootPath, CmsResourceFilter.ALL, true);
            result.add(base);
            result.addAll(subResources);
        } else {
            result.add(base);
        }
        for (CmsResource resource : result) {
            m_cachedResources.put(resource.getStructureId(), resource);
        }

        return result;
    }
1050457
public void initialize(CmsObject cms) throws CmsException {

        m_publishEngine.initialize(cms, m_publishQueuePersistance, m_publishQueueShutdowntime);
        m_frozen = true;
    }
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;
                }
            }
        }
    }
299324
protected void parseDetailPage(I_CmsXmlContentLocation node) throws CmsException {

        I_CmsXmlContentValueLocation pageLoc = node.getSubValue(N_PAGE);
        String typeName = getString(node.getSubValue(N_TYPE));
        try {
            String page = pageLoc.asString(m_cms);
            CmsResource detailPageRes = m_cms.readResource(page);
            CmsUUID id = detailPageRes.getStructureId();
            String iconClasses;
            if (typeName.startsWith(CmsDetailPageInfo.FUNCTION_PREFIX)) {
                iconClasses = CmsIconUtil.getIconClasses(CmsXmlDynamicFunctionHandler.TYPE_FUNCTION, null, false);
            } else {
                iconClasses = CmsIconUtil.getIconClasses(typeName, null, false);
            }

            CmsDetailPageInfo detailPage = new CmsDetailPageInfo(id, page, typeName, iconClasses);
            m_detailPageConfigs.add(detailPage);
        } catch (CmsVfsResourceNotFoundException e) {
            CmsUUID structureId = pageLoc.asId(m_cms);
            CmsResource detailPageRes = m_cms.readResource(structureId);
            CmsDetailPageInfo detailPage = new CmsDetailPageInfo(
                structureId,
                m_cms.getSitePath(detailPageRes),
                typeName,
                CmsIconUtil.getIconClasses(typeName, null, false));
            m_detailPageConfigs.add(detailPage);
        }
    }
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);
        }
    }
370675
private void saveToBundleDescriptor() throws CmsException {

        if (null != m_descFile) {
            m_removeDescriptorOnCancel = false;
            updateBundleDescriptorContent();
            m_descFile.getFile().setContents(m_descContent.marshal());
            m_cms.writeFile(m_descFile.getFile());
        }
    }
717923
protected void parseLinks(CmsObject cms) throws CmsException {

        List<CmsResource> linkParseables = new ArrayList<>();
        for (CmsResourceImportData resData : m_moduleData.getResourceData()) {
            CmsResource importRes = resData.getImportResource();
            if ((importRes != null) && m_importIds.contains(importRes.getStructureId()) && isLinkParsable(importRes)) {
                linkParseables.add(importRes);
            }
        }
        m_report.println(Messages.get().container(Messages.RPT_START_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE);
        CmsImportVersion10.parseLinks(cms, linkParseables, m_report);
        m_report.println(Messages.get().container(Messages.RPT_END_PARSE_LINKS_0), I_CmsReport.FORMAT_HEADLINE);
    }
473240
public static CmsResource readResource(CmsObject cms, CmsHistoryResourceBean bean) throws CmsException {

        CmsHistoryVersion versionBean = bean.getVersion();
        if (versionBean.getVersionNumber() != null) {
            return (CmsResource)(cms.readResource(bean.getStructureId(), versionBean.getVersionNumber().intValue()));
        } else {
            if (versionBean.isOnline()) {
                CmsObject onlineCms = OpenCms.initCmsObject(cms);
                onlineCms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
                return onlineCms.readResource(bean.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
            } else {
                return cms.readResource(bean.getStructureId(), CmsResourceFilter.IGNORE_EXPIRATION);
            }
        }
    }
221606
public static void initialize(CmsObject cms) throws CmsException {

        OpenCms.getRoleManager().checkRole(cms, CmsRole.ADMINISTRATOR);
        try {
            // store the Admin cms to index Cms resources
            m_adminCms = OpenCms.initCmsObject(cms);
            m_adminCms.getRequestContext().setSiteRoot("");
        } catch (CmsException e) {
            // this should never happen
        }
    }
242104
public Map<String, String> getValues() throws CmsException {

        CmsFile file = m_cms.readFile(m_editResource);
        CmsXmlContent content = unmarshalXmlContent(file);
        Locale locale = m_cms.getRequestContext().getLocale();
        if (!content.hasLocale(locale)) {
            content.addLocale(m_cms, locale);
        }
        return getContentValues(content, locale);
    }
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);
    }