/** * Unmarshal the XML content with auto-correction. * @param file the file that contains the XML * @return the XML read from the file * @throws CmsXmlException thrown if the XML can't be read. */ private CmsXmlContent unmarshalXmlContent(CmsFile file) throws CmsXmlException { CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file); content.setAutoCorrectionEnabled(true); content.correctXmlStructure(m_cms); return content; }
/** * Corrects the XML structure of the edited content according to the XSD.<p> * * @throws CmsException if the correction fails */ private void correctXmlStructure() throws CmsException { m_content.setAutoCorrectionEnabled(true); m_content.correctXmlStructure(getCms()); // write the corrected temporary file writeContent(); }
/** * Corrects the XML structure of the edited content according to the XSD.<p> * * @throws CmsException if the correction fails */ private void correctXmlStructure() throws CmsException { m_content.setAutoCorrectionEnabled(true); m_content.correctXmlStructure(getCms()); // write the corrected temporary file writeContent(); }
/** * Check if automatic content correction is required. Returns <code>true</code> if the content was changed.<p> * * @param cms the cms context * @param content the content to check * * @return <code>true</code> if the content was changed * @throws CmsXmlException if the automatic content correction failed */ private boolean checkAutoCorrection(CmsObject cms, CmsXmlContent content) throws CmsXmlException { boolean performedAutoCorrection = false; try { content.validateXmlStructure(new CmsXmlEntityResolver(cms)); } catch (CmsXmlException eXml) { // validation failed content.setAutoCorrectionEnabled(true); content.correctXmlStructure(cms); performedAutoCorrection = true; } return performedAutoCorrection; }
CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file); xmlContent.setAutoCorrectionEnabled(true); file = xmlContent.correctXmlStructure(getCms());
file = content.correctXmlStructure(cms); content.setFile(file);
/** * Writes the new detail page information to the configuration file.<p> * * @param infos the new detail page information * @param newId the id to use for new pages * * @throws CmsException if something goes wrong */ public void updateAndSave(List<CmsDetailPageInfo> infos, CmsUUID newId) throws CmsException { //lock(m_cms, m_resource); getDocument(); removeOldValues(); writeDetailPageInfos(infos, newId); m_document.setAutoCorrectionEnabled(true); m_document.correctXmlStructure(m_cms); byte[] content = m_document.marshal(); m_file.setContents(content); m_cms.writeFile(m_file); //m_cms.unlockResource(m_cms.getSitePath(m_resource)); }
/** * Reads a file into a string, applies a transformation to the string, and writes the string back to the file.<p> * * @param resource the resource to transform * @param transformation the transformation to apply * @throws CmsException if something goes wrong * @throws UnsupportedEncodingException in case the encoding is not supported */ private void transformResource(CmsResource resource, Function<String, String> transformation) throws CmsException, UnsupportedEncodingException { CmsFile file = getCms().readFile(resource); if (CmsResourceTypeXmlContent.isXmlContent(file)) { CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file); xmlContent.setAutoCorrectionEnabled(true); file = xmlContent.correctXmlStructure(getCms()); } String encoding = CmsLocaleManager.getResourceEncoding(getCms(), file); String content = new String(file.getContents(), encoding); content = transformation.apply(content); file.setContents(content.getBytes(encoding)); lockResource(getCms(), file); getCms().writeFile(file); } }
CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file); xmlContent.setAutoCorrectionEnabled(true); file = xmlContent.correctXmlStructure(getCms());
file = content.correctXmlStructure(cms); content.setFile(file);
CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file); xmlContent.setAutoCorrectionEnabled(true); file = xmlContent.correctXmlStructure(getCms());
/** * Writes a sitemap configuration back to the VFS.<p> * * @param content the content to write * @param sitemapConfigFile the file to which the sitemap config should be written * * @throws CmsXmlException if an XML processing error occurs * @throws CmsException if something goes wrong */ private void writeSitemapConfig(CmsXmlContent content, CmsFile sitemapConfigFile) throws CmsXmlException, CmsException { content.correctXmlStructure(m_cms); byte[] contentBytes = content.marshal(); sitemapConfigFile.setContents(contentBytes); try { CmsLock lock = m_cms.getLock(sitemapConfigFile); if (lock.isUnlocked() || !lock.isOwnedBy(m_cms.getRequestContext().getCurrentUser())) { m_cms.lockResourceTemporary(sitemapConfigFile); } m_cms.writeFile(sitemapConfigFile); } finally { m_cms.unlockResource(sitemapConfigFile); } }
file = content.correctXmlStructure(cms); content.setFile(file);
/** * Replaces the referenced formatters within the new XSD files with the new formatter paths.<p> * * @param targetModule the target module * * @throws CmsException if something goes wrong * @throws UnsupportedEncodingException if the file content could not be read with the determined encoding */ private void replaceFormatterPaths(CmsModule targetModule) throws CmsException, UnsupportedEncodingException { CmsResource formatterSourceFolder = getCms().readResource( "/system/modules/" + m_cloneInfo.getFormatterSourceModule() + "/"); CmsResource formatterTargetFolder = getCms().readResource( "/system/modules/" + m_cloneInfo.getFormatterTargetModule() + "/"); for (I_CmsResourceType type : targetModule.getResourceTypes()) { String schemaPath = type.getConfiguration().get("schema"); CmsResource res = getCms().readResource(schemaPath); CmsFile file = getCms().readFile(res); if (CmsResourceTypeXmlContent.isXmlContent(file)) { CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), file); xmlContent.setAutoCorrectionEnabled(true); file = xmlContent.correctXmlStructure(getCms()); } String encoding = CmsLocaleManager.getResourceEncoding(getCms(), file); String content = new String(file.getContents(), encoding); content = content.replaceAll(formatterSourceFolder.getRootPath(), formatterTargetFolder.getRootPath()); file.setContents(content.getBytes(encoding)); getCms().writeFile(file); } }
content.correctXmlStructure(m_cms); file.setContents(content.marshal()); m_cms.writeFile(file);
file = content.correctXmlStructure(cms); content.setFile(file);
xmlContent.correctXmlStructure(getCms()); file.setContents(xmlContent.marshal());
xmlContent.correctXmlStructure(getCms()); file.setContents(xmlContent.marshal());