Adds the given values to the content document.<p>

@param file the content file
@param contentValues the values to add

@return the content document

@throws CmsException if writing the XML fails
492993
protected CmsXmlContent addContentValues(CmsFile file, Map<String, String> contentValues) throws CmsException {

        CmsXmlContent content = unmarshalXmlContent(file);
        Locale locale = m_cms.getRequestContext().getLocale();

        addContentValues(content, locale, contentValues);
        return content;
    }
1333385
private void insertEditEmpty() throws CmsException, JspException {

        Tag ancestor = findAncestorWithClass(this, I_CmsXmlContentContainer.class);
        I_CmsXmlContentContainer container = null;
        if (ancestor != null) {
            // parent content container available, use preloaded values from this container
            container = (I_CmsXmlContentContainer)ancestor;
            insertEditEmpty(pageContext, container, m_mode == null ? CmsDirectEditMode.AUTO : m_mode, null);
        }
    }
298593
void setup() throws CmsException {

        m_types = new HashMap<String, TypeDefinitionContainerImpl>();
        m_typeList = new ArrayList<TypeDefinitionContainer>();
        m_cmsPropertyDefinitions = m_adminCms.readAllPropertyDefinitions();

        // folder type
        FolderTypeDefinitionImpl folderType = new FolderTypeDefinitionImpl();
        folderType.setBaseTypeId(BaseTypeId.CMIS_FOLDER);
        folderType.setIsControllableAcl(Boolean.TRUE);
        folderType.setIsControllablePolicy(Boolean.FALSE);
        folderType.setIsCreatable(Boolean.TRUE);
        folderType.setDescription("Folder");
        folderType.setDisplayName("Folder");
        folderType.setIsFileable(Boolean.TRUE);
        folderType.setIsFulltextIndexed(Boolean.FALSE);
        folderType.setIsIncludedInSupertypeQuery(Boolean.TRUE);
        folderType.setLocalName("Folder");
        folderType.setLocalNamespace(NAMESPACE);
        folderType.setIsQueryable(Boolean.TRUE);
        folderType.setQueryName("cmis:folder");
        folderType.setId(FOLDER_TYPE_ID);

        addBasePropertyDefinitions(folderType);
        addFolderPropertyDefinitions(folderType);
        addCmsPropertyDefinitions(folderType);
        addProviderPropertyDefinitions(folderType);

        addTypeInternal(folderType);

        // document type
        DocumentTypeDefinitionImpl documentType = new DocumentTypeDefinitionImpl();
        documentType.setBaseTypeId(BaseTypeId.CMIS_DOCUMENT);
        documentType.setIsControllableAcl(Boolean.TRUE);
        documentType.setIsControllablePolicy(Boolean.FALSE);
        documentType.setIsCreatable(Boolean.TRUE);
        documentType.setDescription("Document");
        documentType.setDisplayName("Document");
        documentType.setIsFileable(Boolean.TRUE);
        documentType.setIsFulltextIndexed(Boolean.FALSE);
        documentType.setIsIncludedInSupertypeQuery(Boolean.TRUE);
        documentType.setLocalName("Document");
        documentType.setLocalNamespace(NAMESPACE);
        documentType.setIsQueryable(Boolean.TRUE);
        documentType.setQueryName("cmis:document");
        documentType.setId(DOCUMENT_TYPE_ID);

        documentType.setIsVersionable(Boolean.FALSE);
        documentType.setContentStreamAllowed(ContentStreamAllowed.REQUIRED);

        addBasePropertyDefinitions(documentType);
        addDocumentPropertyDefinitions(documentType);
        addCmsPropertyDefinitions(documentType);
        addProviderPropertyDefinitions(documentType);

        addTypeInternal(documentType);

        // relationship types
        RelationshipTypeDefinitionImpl relationshipType = new RelationshipTypeDefinitionImpl();
        relationshipType.setBaseTypeId(BaseTypeId.CMIS_RELATIONSHIP);
        relationshipType.setIsControllableAcl(Boolean.FALSE);
        relationshipType.setIsControllablePolicy(Boolean.FALSE);
        relationshipType.setIsCreatable(Boolean.FALSE);
        relationshipType.setDescription("Relationship");
        relationshipType.setDisplayName("Relationship");
        relationshipType.setIsFileable(Boolean.FALSE);
        relationshipType.setIsIncludedInSupertypeQuery(Boolean.TRUE);
        relationshipType.setLocalName("Relationship");
        relationshipType.setLocalNamespace(NAMESPACE);
        relationshipType.setIsQueryable(Boolean.FALSE);
        relationshipType.setQueryName("cmis:relationship");
        relationshipType.setId(RELATIONSHIP_TYPE_ID);
        List<String> typeList = new ArrayList<String>();
        typeList.add("cmis:document");
        typeList.add("cmis:folder");
        relationshipType.setAllowedSourceTypes(typeList);
        relationshipType.setAllowedTargetTypes(typeList);
        addBasePropertyDefinitions(relationshipType);
        addRelationPropertyDefinitions(relationshipType);
        addTypeInternal(relationshipType);

        for (CmsRelationType relType : CmsRelationType.getAll()) {
            createRelationshipType(relType);
        }
        m_lastUpdate = System.currentTimeMillis();
    }
334354
public List<I_CmsXmlContentValue> getAllSimpleSubValues(I_CmsXmlContentValue value) {

        List<I_CmsXmlContentValue> result = new ArrayList<I_CmsXmlContentValue>();
        for (I_CmsXmlContentValue subValue : getSubValues(value.getPath(), value.getLocale())) {
            if (subValue.isSimpleType()) {
                result.add(subValue);
            } else {
                result.addAll(getAllSimpleSubValues(subValue));
            }
        }
        return result;
    }
1109038
private void saveToXmlVfsBundle() throws CmsException {

        if (m_lockedBundleFiles.get(null) != null) { // If the file was not locked, no changes were made, i.e., storing is not necessary.
            for (Locale l : m_locales) {
                SortedProperties props = m_localizations.get(l);
                if (null != props) {
                    if (m_xmlBundle.hasLocale(l)) {
                        m_xmlBundle.removeLocale(l);
                    }
                    m_xmlBundle.addLocale(m_cms, l);
                    int i = 0;
                    List<Object> keys = new ArrayList<Object>(props.keySet());
                    Collections.sort(keys, CmsCaseInsensitiveStringComparator.getInstance());
                    for (Object key : keys) {
                        if ((null != key) && !key.toString().isEmpty()) {
                            String value = props.getProperty(key.toString());
                            if (!value.isEmpty()) {
                                m_xmlBundle.addValue(m_cms, "Message", l, i);
                                i++;
                                m_xmlBundle.getValue("Message[" + i + "]/Key", l).setStringValue(m_cms, key.toString());
                                m_xmlBundle.getValue("Message[" + i + "]/Value", l).setStringValue(m_cms, value);
                            }
                        }
                    }
                }
                CmsFile bundleFile = m_lockedBundleFiles.get(null).getFile();
                bundleFile.setContents(m_xmlBundle.marshal());
                m_cms.writeFile(bundleFile);
            }
        }
    }
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());
            }
        }
    }
671009
protected void rewriteContent(CmsFile file, Collection<CmsRelation> relations) throws CmsException {

        LOG.info("Rewriting in-content links for " + file.getRootPath());
        CmsPair<String, String> contentAndEncoding = decode(file);

        String content = "";

        if (OpenCms.getResourceManager().getResourceType(file) instanceof CmsResourceTypeXmlContent) {
            CmsXmlContent contentXml = CmsXmlContentFactory.unmarshal(m_cms, file);
            try {
                contentXml.validateXmlStructure(new CmsXmlEntityResolver(m_cms));
            } catch (CmsException e) {
                LOG.info("XML content was corrected automatically for resource " + file.getRootPath());
                contentXml.setAutoCorrectionEnabled(true);
                contentXml.correctXmlStructure(m_cms);
                try {
                    content = new String(contentXml.marshal(), contentAndEncoding.getSecond());
                } catch (UnsupportedEncodingException e1) {
                    //
                }
            }
        }

        if (content.isEmpty()) {
            content = contentAndEncoding.getFirst();
        }
        String encodingForSave = contentAndEncoding.getSecond();
        String newContent = rewriteContentString(content);
        byte[] newContentBytes;
        try {
            newContentBytes = newContent.getBytes(encodingForSave);
        } catch (UnsupportedEncodingException e) {
            newContentBytes = newContent.getBytes();
        }
        file.setContents(newContentBytes);
        m_cms.writeFile(file);

    }
390455
protected void touchFiles() throws CmsException {

        Date touchDate = m_dateField.getDate();
        boolean validDate = touchDate != null;
        long touchTime = touchDate != null ? touchDate.getTime() : 0;
        boolean recursive = m_modifySubresourcesField.getValue().booleanValue();
        boolean rewriteContent = m_rewriteContentField.getValue().booleanValue();
        List<CmsUUID> changedIds = Lists.newArrayList();
        for (CmsResource resource : m_context.getResources()) {
            CmsLockActionRecord actionRecord = null;
            try {
                actionRecord = CmsLockUtil.ensureLock(m_context.getCms(), resource);
                touchSingleResource(
                    m_context.getCms().getSitePath(resource),
                    touchTime,
                    recursive,
                    validDate,
                    rewriteContent);
                changedIds.add(resource.getStructureId());
            } finally {
                if ((actionRecord != null) && (actionRecord.getChange() == LockChange.locked)) {
                    try {
                        m_context.getCms().unlockResource(resource);
                    } catch (CmsLockException e) {
                        LOG.warn(e.getLocalizedMessage(), e);
                    }
                }

            }

        }
        m_context.finish(changedIds);

    }
367459
public void parse(CmsResource resource) throws CmsException {

        CmsFile file = m_cms.readFile(resource);
        parse(file);
    }
1143318
public static void setFileProperties (final File file, final String contentType) throws IOException, FrameworkException {

		final java.io.File fileOnDisk = file.getFileOnDisk(false);
		final PropertyMap map         = new PropertyMap();

		map.put(StructrApp.key(File.class, "contentType"), contentType != null ? contentType : FileHelper.getContentMimeType(fileOnDisk, file.getProperty(File.name)));
		map.put(StructrApp.key(File.class, "size"),        FileHelper.getSize(fileOnDisk));
		map.put(StructrApp.key(File.class, "version"),     1);

		map.putAll(getChecksums(file, fileOnDisk));

		file.setProperties(file.getSecurityContext(), map);
	}
18413
private String createStringValue(CmsObject cms, I_CmsXmlDocument document) {

        Element data = m_element.element(CmsXmlPage.NODE_CONTENT);
        if (data == null) {
            String content = m_element.getText();
            m_element.clearContent();
            int index = m_element.getParent().elements(m_element.getQName()).indexOf(m_element);
            m_element.addAttribute(CmsXmlPage.ATTRIBUTE_NAME, getName() + index);
            m_element.addElement(CmsXmlPage.NODE_LINKS);
            m_element.addElement(CmsXmlPage.NODE_CONTENT).addCDATA(content);
            data = m_element.element(CmsXmlPage.NODE_CONTENT);
        }
        Attribute enabled = m_element.attribute(CmsXmlPage.ATTRIBUTE_ENABLED);

        String content = "";
        if ((enabled == null) || Boolean.valueOf(enabled.getText()).booleanValue()) {

            content = data.getText();

            CmsLinkTable linkTable = getLinkTable();
            if (!linkTable.isEmpty()) {

                // link processing: replace macros with links
                CmsLinkProcessor linkProcessor = document.getLinkProcessor(cms, linkTable);
                try {
                    content = linkProcessor.processLinks(content);
                } catch (ParserException e) {
                    // should better not happen
                    LOG.error(Messages.get().getBundle().key(Messages.ERR_XMLCONTENT_LINK_PROCESS_FAILED_0), e);
                }
            }
        }
        return content;
    }
317396
public void save() throws CmsException {

        if (hasChanges()) {
            switch (m_bundleType) {
                case PROPERTY:
                    saveLocalization();
                    saveToPropertyVfsBundle();
                    break;

                case XML:
                    saveLocalization();
                    saveToXmlVfsBundle();

                    break;

                case DESCRIPTOR:
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            if (null != m_descFile) {
                saveToBundleDescriptor();
            }

            resetChanges();
        }

    }
797148
public void upgradeContent(CmsObject cms) throws CmsException {

        if (m_content == null) {
            m_content = cms.readFile(m_resource).getContents();
        }
    }
1090239
private void initMacroContent() throws CmsException {

        I_CmsFormatterBean formatterConfig = OpenCms.getADEManager().getCachedFormatters(
            m_cms.getRequestContext().getCurrentProject().isOnlineProject()).getFormatters().get(
                m_element.getFormatterId());
        if (formatterConfig instanceof CmsMacroFormatterBean) {
            CmsMacroFormatterBean config = (CmsMacroFormatterBean)formatterConfig;
            m_input = config.getMacroInput();
            m_formatterReferences = config.getReferencedFormatters();
            if (m_element.isInMemoryOnly()) {
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(config.getPlaceholderMacroInput())) {
                    m_input = config.getPlaceholderMacroInput();
                }
                if (config.getDefaultContentStructureId() != null) {
                    try {
                        CmsResource defaultContent = m_cms.readResource(
                            ((CmsMacroFormatterBean)formatterConfig).getDefaultContentStructureId());
                        CmsFile defaultFile = m_cms.readFile(defaultContent);
                        m_element = new CmsContainerElementBean(
                            defaultFile,
                            m_element.getFormatterId(),
                            m_element.getIndividualSettings(),
                            true,
                            m_element.editorHash(),
                            m_element.isCreateNew());
                    } catch (CmsException e) {
                        LOG.error("Error reading default content for new resource", e);
                    }
                }
            }
        } else {
            // only as a fall back, should not be used
            m_formatterReferences = new HashMap<String, CmsUUID>();
            CmsResource macroContent = m_cms.readResource(m_element.getFormatterId());
            CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(m_cms, macroContent, m_request);
            m_input = xmlContent.getStringValue(m_cms, CmsFormatterBeanParser.N_MACRO, CmsLocaleManager.MASTER_LOCALE);
            List<I_CmsXmlContentValue> formatters = xmlContent.getValues(
                CmsFormatterBeanParser.N_FORMATTERS,
                CmsLocaleManager.MASTER_LOCALE);
            for (I_CmsXmlContentValue formatterValue : formatters) {
                CmsXmlVfsFileValue file = (CmsXmlVfsFileValue)xmlContent.getValue(
                    formatterValue.getPath() + "/" + CmsFormatterBeanParser.N_FORMATTER,
                    CmsLocaleManager.MASTER_LOCALE);
                String macroName = xmlContent.getStringValue(
                    m_cms,
                    formatterValue.getPath() + "/" + CmsFormatterBeanParser.N_MACRO_NAME,
                    CmsLocaleManager.MASTER_LOCALE);
                m_formatterReferences.put(macroName, file.getLink(m_cms).getStructureId());
            }
        }
    }
482716
public void load(CmsObject cms, CmsResource resource) throws CmsException {

        CmsFile file = cms.readFile(resource);
        CmsObject rootCms = OpenCms.initCmsObject(cms);
        rootCms.getRequestContext().setSiteRoot("");
        CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, file);
        Locale en = new Locale("en");
        for (I_CmsXmlContentValue value : content.getValues(N_INCLUDE, en)) {
            String include = value.getStringValue(rootCms);
            if (!CmsStringUtil.isEmpty(include)) {
                m_includes.add(include);
            }
        }
        for (I_CmsXmlContentValue value : content.getValues(N_EXCLUDE, en)) {
            String exclude = value.getStringValue(rootCms);
            if (!CmsStringUtil.isEmpty(exclude)) {
                m_excludes.add(exclude);
            }
        }
        I_CmsXmlContentValue robotsValue = content.getValue(N_MODE, en);
        m_mode = robotsValue.getStringValue(rootCms);

        I_CmsXmlContentValue robotsTxtTextValue = content.getValue(N_ROBOTS_TXT_TEXT, en);
        if (robotsTxtTextValue != null) {
            m_robotsTxtText = robotsTxtTextValue.getStringValue(rootCms);
        }

        I_CmsXmlContentValue computeContPageDates = content.getValue(N_COMPUTE_CONTAINER_PAGE_DATES, en);
        if (computeContPageDates != null) {
            m_computeContainerPageDates = Boolean.parseBoolean(computeContPageDates.getStringValue(rootCms));
        }

        I_CmsXmlContentValue generatorClassValue = content.getValue(N_GENERATOR_CLASS, en);
        if (generatorClassValue != null) {
            m_generatorClassName = generatorClassValue.getStringValue(rootCms);
        }

        I_CmsXmlContentValue cacheValue = content.getValue(N_CACHE, en);
        if (cacheValue != null) {
            m_useCache = Boolean.parseBoolean(cacheValue.getStringValue(rootCms));
        }

        I_CmsXmlContentValue serverUrlValue = content.getValue(N_SERVER_URL, en);
        if (serverUrlValue != null) {
            m_serverUrl = serverUrlValue.getStringValue(rootCms);
        }
    }
245305
protected void createContentDirectory() throws CmsException {

        if (!isModuleConfiguration()) {
            String contentFolder = getContentFolderPath();
            if (!getCms().existsResource(contentFolder)) {
                getCms().createResource(
                    contentFolder,
                    OpenCms.getResourceManager().getResourceType(CmsResourceTypeFolder.getStaticTypeName()));
            }
        }
    }
646489
protected String getContentAsString(CmsFile file) throws CmsException {

        CmsProperty p = m_cms.readPropertyObject(file, CmsPropertyDefinition.PROPERTY_CONTENT_ENCODING, true);
        String e = p.getValue();
        if (e == null) {
            e = OpenCms.getSystemInfo().getDefaultEncoding();
        }
        return CmsEncoder.createString(file.getContents(), e);
    }