Returns the XML content document.<p>

@param file the resource file
@param fromCache <code>true</code> to use the cached document

@return the content document

@throws CmsXmlException if reading the XML fails
172867
private CmsXmlContent getContentDocument(CmsFile file, boolean fromCache) throws CmsXmlException {

        CmsXmlContent content = null;
        if (fromCache) {
            content = getSessionCache().getCacheXmlContent(file.getStructureId());
        }
        if (content == null) {
            content = CmsXmlContentFactory.unmarshal(getCmsObject(), file);
            getSessionCache().setCacheXmlContent(file.getStructureId(), content);
        }
        return content;
    }
1007921
public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsIndexException {

        if (resource == null) {
            throw new CmsIndexException(Messages.get().container(Messages.ERR_NO_RAW_CONTENT_1, index.getLocale()));
        }
        // just return an empty result set
        return new CmsExtractionResult("");
    }
819168
public static void loadCache(Map<String, String> cache, File file, int maxSize) {
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String line = null;
            while ((line = br.readLine()) != null) {
                int sepIndex = line.indexOf(" ");
                String hash = line.substring(0, sepIndex);
                String urlExternalForm = line.substring(sepIndex + 1);
                cache.put(urlExternalForm, hash);
            }
        } catch (FileNotFoundException e) {
            // Nothing: New cache will be used.
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            FileUtil.closeAndIgnoreExceptions(br);
        }
    }
840007
protected static byte[] getHistoricalResourceContent(CmsObject cms, String resource, String version) {

        if (CmsStringUtil.isNotEmpty(resource) && CmsStringUtil.isNotEmpty(version)) {
            // try to load the historical resource
            I_CmsHistoryResource res = null;
            String storedSiteRoot = cms.getRequestContext().getSiteRoot();
            try {
                cms.getRequestContext().setSiteRoot("/");
                res = cms.readResource(
                    cms.readResource(resource, CmsResourceFilter.ALL).getStructureId(),
                    Integer.parseInt(version));
            } catch (CmsException e) {
                // can usually be ignored
                if (LOG.isInfoEnabled()) {
                    LOG.info(e.getLocalizedMessage());
                }
                return "".getBytes();
            } finally {
                cms.getRequestContext().setSiteRoot(storedSiteRoot);
            }
            if (res.isFile()) {
                byte[] historyResourceContent = ((CmsFile)res).getContents();
                if ((historyResourceContent == null) || (historyResourceContent.length == 0)) {
                    try {
                        CmsFile file = cms.readFile((CmsResource)res);
                        historyResourceContent = file.getContents();
                    } catch (CmsException e) {
                        // ignore
                    }
                }
                historyResourceContent = CmsEncoder.changeEncoding(
                    historyResourceContent,
                    OpenCms.getSystemInfo().getDefaultEncoding(),
                    cms.getRequestContext().getEncoding());
                return historyResourceContent;
            }
        }
        return "".getBytes();
    }
817458
public void fromXML(String file) throws DocumentException
    {
        SAXReader reader = new SAXReader();
        fromXML(reader.read(new StringReader(file)));
    }
887813
private static CmsXmlContainerPage getCache(CmsObject cms, CmsResource resource, boolean keepEncoding) {

        if (resource instanceof I_CmsHistoryResource) {
            return null;
        }
        return getCache().getCacheContainerPage(
            getCache().getCacheKey(resource.getStructureId(), keepEncoding),
            cms.getRequestContext().getCurrentProject().isOnlineProject());
    }
978487
private CmsContainerPageBean getContainerPageBean(CmsResource resource) throws CmsException {

        CmsXmlContainerPage xmlCnt = CmsXmlContainerPageFactory.unmarshal(m_cms, m_cms.readFile(resource));
        return xmlCnt.getContainerPage(m_cms);
    }
132397
private void setXmlContentFromFile(
        CmsResource cmsResource,
        CmsFile cmsFile,
        CmsObject cmsObject,
        String xmlContent,
        String encodingType,
        I_CmsReport report) {

        try {
            byte[] fileContent = xmlContent.getBytes(encodingType);
            cmsFile.setContents(fileContent);
            // write into file
            cmsObject.writeFile(cmsFile);
            // unlock resource
            try {
                cmsObject.unlockResource(cmsObject.getSitePath(cmsResource));
            } catch (CmsException e) {
                m_errorTransform += 1;
                report.println(
                    Messages.get().container(Messages.RPT_CONVERTXML_UNLOCK_FILE_1, cmsObject.getSitePath(cmsResource)),
                    I_CmsReport.FORMAT_ERROR);
                if (LOG.isErrorEnabled()) {
                    LOG.error(e.getMessageContainer(), e);
                }
            }
        } catch (Exception e) {
            m_errorTransform += 1;
            String reportContent = "<br/>";
            reportContent = reportContent + CmsEncoder.escapeXml(xmlContent);
            reportContent = reportContent.replaceAll("\r\n", "<br/>");
            report.println(
                Messages.get().container(Messages.RPT_CONVERTXML_WRITE_ERROR_1, reportContent),
                I_CmsReport.FORMAT_ERROR);
            if (LOG.isErrorEnabled()) {
                LOG.error(e.toString());
            }
        }
    }
838255
@Override
    public I_CmsExtractionResult extractContent(CmsObject cms, CmsResource resource, I_CmsSearchIndex index)
    throws CmsException {

        return extractContent(cms, resource, index, null);
    }
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);
    }
15821
protected XWikiDocument getDocFromXML(File file) throws MojoExecutionException
    {
        XWikiDocument doc;

        try {
            doc = new XWikiDocument();
            doc.fromXML(file);
        } catch (Exception e) {
            throw new MojoExecutionException(String.format("Failed to parse [%s].", file.getAbsolutePath()), e);
        }

        return doc;
    }
247054
protected CmsPair<String, String> decode(CmsFile file) throws CmsException {

        String content = null;
        String encoding = getConfiguredEncoding(m_cms, file);
        I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(file.getTypeId());
        if (resType instanceof CmsResourceTypeJsp) {
            content = decode(file.getContents(), encoding);
        } else {
            try {
                CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(m_cms);
                // parse the XML and serialize it back to  a string with the configured encoding
                Document doc = CmsXmlUtils.unmarshalHelper(file.getContents(), resolver);
                content = CmsXmlUtils.marshal(doc, encoding);
            } catch (Exception e) {
                // invalid xml structure, just use the configured encoding
                content = decode(file.getContents(), encoding);
            }
        }
        return CmsPair.create(content, encoding);
    }
1113408
public T getTemplateFromCache(String filename) {

        LRUCache.CacheEntry<String, T> cachedTemplate = cache.get(filename);

        // this is to avoid null pointer exception in case of the layout composite template
        if (cachedTemplate == null) {
            return null;
        }

        return cachedTemplate.compiled;
    }
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;
    }
169971
private void initXmlBundle() throws CmsException {

        CmsFile file = m_cms.readFile(m_resource);
        m_bundleFiles.put(null, m_resource);
        m_xmlBundle = CmsXmlContentFactory.unmarshal(m_cms, file);
        initKeySetForXmlBundle();

    }
1108027
public static Document getDocument(File file) {
		SAXReader reader = new SAXReader();
		Document document = null;
		try {
			document = reader.read(file);
		} catch (DocumentException e) {
			throw new RuntimeException(e);
		}
		return document;
	}
30078
public static CmsADESessionCache getCache(HttpServletRequest request, CmsObject cms) {

        CmsADESessionCache cache = (CmsADESessionCache)request.getSession().getAttribute(
            CmsADESessionCache.SESSION_ATTR_ADE_CACHE);
        if (cache == null) {
            cache = new CmsADESessionCache(cms, request);
            request.getSession().setAttribute(CmsADESessionCache.SESSION_ATTR_ADE_CACHE, cache);
        }
        return cache;
    }