Parses a given resource.<p>

@param resource the resource to parse

@throws CmsException if something goes wrong
437291
public void parse(CmsResource resource) throws CmsException {

        CmsFile file = m_cms.readFile(resource);
        m_resource = resource;
        CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file);
        parse(content);
    }
417337
public void addResource(String resource) {

        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(Messages.LOG_ADD_MOD_RESOURCE_1, resource));
        }
        m_resources.add(resource);
    }
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;
    }
845478
protected void ensureLock() throws CmsException {

        CmsLock lock = m_cms.getLock(m_resource);
        if (lock.isUnlocked() || !lock.isLockableBy(m_cms.getRequestContext().getCurrentUser())) {
            m_cms.lockResourceTemporary(m_cms.getSitePath(m_resource));
            m_needToUnlock = true;
        }
    }
345117
protected void setResource(CmsObject cms, CmsResource resource) {

        m_resource = CmsJspResourceWrapper.wrap(cms, resource);
    }
375114
public static void tryUnlock(CmsObject cms, CmsResource resource) {

        try {
            cms.unlockResource(resource);
        } catch (CmsException e) {
            LOG.debug("Unable to unlock " + resource.getRootPath(), e);
        }
    }
214273
protected void findRoot(Collection<CmsResource> resources) throws CmsException {

        m_commonRoot = getCommonSite(resources);
        String commonPath = getCommonAncestorPath(resources);
        try {
            m_rootResource = m_cms.readResource(m_commonRoot, m_filter);
        } catch (CmsVfsResourceNotFoundException e) {
            String currentPath = commonPath;
            String lastWorkingPath = null;
            while (m_cms.existsResource(currentPath, m_filter)) {
                lastWorkingPath = currentPath;
                currentPath = CmsResource.getParentFolder(currentPath);
            }
            m_rootResource = m_cms.readResource(lastWorkingPath, m_filter);
            m_commonRoot = lastWorkingPath;
        }
        m_knownResources.add(m_rootResource);
    }
125276
protected CmsBrokenLinkBean createSitemapBrokenLinkBean(CmsResource resource) throws CmsException {

        CmsProperty titleProp = m_cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, true);
        String typeName = OpenCms.getResourceManager().getResourceType(resource).getTypeName();
        String defaultTitle = CmsResource.getName(resource.getRootPath());
        String title = titleProp.getValue(defaultTitle);
        String path = m_cms.getSitePath(resource);
        String subtitle = path;
        return new CmsBrokenLinkBean(resource.getStructureId(), title, subtitle, typeName);
    }
1310965
public void publishResources(List<CmsResource> resources) throws CmsException {

        CmsObject cms = m_cms;
        I_CmsReport report = new CmsWorkplaceReport(
            cms.getRequestContext().getLocale(),
            cms.getRequestContext().getSiteRoot(),
            null);
        CmsPublishManager publishManager = OpenCms.getPublishManager();
        CmsPublishList publishList = publishManager.getPublishListAll(m_cms, resources, false, true);
        OpenCms.getPublishManager().publishProject(m_cms, report, publishList);
    }
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;
    }
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();
    }
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);
    }
222441
public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsException {

        logContentExtraction(resource, index);
        try {
            CmsFile file = readFile(cms, resource);
            CmsXmlContainerPage containerPage = CmsXmlContainerPageFactory.unmarshal(cms, file);
            Locale locale = index.getLocaleForResource(cms, resource, null);

            // initialize return values
            StringBuffer content = new StringBuffer();
            LinkedHashMap<String, String> items = new LinkedHashMap<String, String>();

            CmsContainerPageBean containerBean = containerPage.getContainerPage(cms);
            for (CmsContainerElementBean element : containerBean.getElements()) {
                // check all elements in this container

                // get the formatter configuration for this element
                element.initResource(cms);
                CmsADEConfigData adeConfig = OpenCms.getADEManager().lookupConfiguration(cms, file.getRootPath());
                CmsFormatterConfiguration formatters = adeConfig.getFormatters(cms, element.getResource());

                if (formatters.isSearchContent(element.getFormatterId())) {
                    // the content of this element must be included for the container page

                    element.initResource(cms);
                    CmsFile elementFile = readFile(cms, element.getResource());
                    A_CmsXmlDocument elementContent = CmsXmlContentFactory.unmarshal(cms, elementFile);
                    List<String> elementNames = elementContent.getNames(locale);
                    for (String xpath : elementNames) {
                        // xpath will have the form "Text[1]" or "Nested[1]/Text[1]"
                        I_CmsXmlContentValue value = elementContent.getValue(xpath, locale);
                        if (value.getContentDefinition().getContentHandler().isSearchable(value)) {
                            // the content value is searchable
                            String extracted = value.getPlainText(cms);
                            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(extracted)) {
                                items.put(elementFile.getRootPath() + "/" + xpath, 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);
        }
    }
515542
private CmsClientTemplateBean getTemplateBean(CmsObject cms, CmsResource resource) throws CmsException {

        CmsProperty titleProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, false);
        CmsProperty descProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false);
        CmsProperty imageProp = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TEMPLATE_IMAGE, false);
        CmsProperty selectValueProp = cms.readPropertyObject(
            resource,
            CmsPropertyDefinition.PROPERTY_TEMPLATE_PROVIDER,
            false);
        String sitePath = cms.getSitePath(resource);
        String templateValue = sitePath;
        if (!selectValueProp.isNullProperty() && !CmsStringUtil.isEmptyOrWhitespaceOnly(selectValueProp.getValue())) {
            String selectValue = selectValueProp.getValue();
            CmsMacroResolver resolver = new CmsMacroResolver();
            resolver.addMacro(MACRO_TEMPLATEPATH, sitePath);
            templateValue = resolver.resolveMacros(selectValue);
        }
        return new CmsClientTemplateBean(
            titleProp.getValue(),
            descProp.getValue(),
            templateValue,
            imageProp.getValue());
    }
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);
    }
294207
public static String readFromResource(String resource) throws IOException {

        InputStream in = getResourceAsStream(resource);
        if (in == null) {
            return null;
        }
        try {
            return read(in);
        } finally {
            closeQuietly(in);
        }
    }
317150
public String getSiteTitle(CmsObject cms, CmsResource resource) throws CmsException {

        String title = cms.readPropertyObject(resource, CmsPropertyDefinition.PROPERTY_TITLE, false).getValue();
        if (title == null) {
            title = resource.getRootPath();
        }
        if (resource.getRootPath().equals(getSharedFolder())) {
            title = SHARED_FOLDER_TITLE;
        }
        return title;
    }