/** * @see org.opencms.loader.A_CmsXmlDocumentLoader#unmarshalXmlDocument(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.ServletRequest) */ @Override protected I_CmsXmlDocument unmarshalXmlDocument(CmsObject cms, CmsResource resource, ServletRequest req) throws CmsException { return CmsXmlContentFactory.unmarshal(cms, resource, req); }
/** * @see org.opencms.loader.A_CmsXmlDocumentLoader#unmarshalXmlDocument(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.ServletRequest) */ @Override protected I_CmsXmlDocument unmarshalXmlDocument(CmsObject cms, CmsResource resource, ServletRequest req) throws CmsException { return CmsXmlContentFactory.unmarshal(cms, resource, req); }
/** * @see org.opencms.loader.A_CmsXmlDocumentLoader#unmarshalXmlDocument(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.ServletRequest) */ @Override protected I_CmsXmlDocument unmarshalXmlDocument(CmsObject cms, CmsResource resource, ServletRequest req) throws CmsException { return CmsXmlContentFactory.unmarshal(cms, resource, req); }
/** * Factory method to unmarshal (read) a XML content instance from a OpenCms VFS file * that contains XML data.<p> * * <b>Warning:</b><br/> * This method does not support requested historic versions, it always loads the * most recent version. Use <code>{@link #unmarshal(CmsObject, CmsResource, ServletRequest)}</code> * for history support.<p> * * @param cms the current cms object * @param file the file with the XML data to unmarshal * * @return a XML page instance unmarshalled from the provided file * * @throws CmsXmlException if something goes wrong */ public static CmsXmlContent unmarshal(CmsObject cms, CmsFile file) throws CmsXmlException { return unmarshal(cms, file, true); }
/** * Factory method to unmarshal (read) a XML content instance from a OpenCms VFS file * that contains XML data.<p> * * <b>Warning:</b><br/> * This method does not support requested historic versions, it always loads the * most recent version. Use <code>{@link #unmarshal(CmsObject, CmsResource, ServletRequest)}</code> * for history support.<p> * * @param cms the current cms object * @param file the file with the XML data to unmarshal * * @return a XML page instance unmarshalled from the provided file * * @throws CmsXmlException if something goes wrong */ public static CmsXmlContent unmarshal(CmsObject cms, CmsFile file) throws CmsXmlException { return unmarshal(cms, file, true); }
/** * Unmarshalls the content of the encapsulated CmsResource and stores it within the * CmsContentCheckResource. If the xmlcontent is already existing, it is not unmarshalled * again.<p> * * @param cms the CmsObject * @throws CmsException if loading of the content fails */ public void upgradeXmlContent(CmsObject cms) throws CmsException { if (m_xmlcontent == null) { CmsFile file = cms.readFile(m_resource); m_xmlcontent = CmsXmlContentFactory.unmarshal(cms, file); } } }
/** * Helper method for loading the XML content from the configuration file.<p> * * @return the parsed XML document * * @throws CmsException if something goes wrong */ private I_CmsXmlDocument getDocument() throws CmsException { if (m_document == null) { m_file = m_cms.readFile(m_resource); CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, m_file); m_document = content; } return m_document; }
/** * Unmarshals the XML content and adds the file to the bundle files. * @throws CmsException thrown if reading the file or unmarshaling fails. */ 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(); }
/** * 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; }
/** * Parses a given resource.<p> * * @param resource the resource to parse * * @throws CmsException if something goes wrong */ 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); }
/** * Parses a dynamic function bean given a resource.<p> * * @param cms the current CMS context * @param res the resource from which to read the dynamic function * * @return the dynamic function bean created from the resource * * @throws CmsException if something goes wrong */ public CmsDynamicFunctionBean parseFunctionBean(CmsObject cms, CmsResource res) throws CmsException { CmsFile file = cms.readFile(res); CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(cms, file); return parseFunctionBean(cms, xmlContent); }
/** * Parses the sitemap configuration given the configuration file and base path.<p> * * @param basePath the base path * @param configRes the configuration file resource * @return the parsed configuration data * @throws CmsException if something goes wrong */ public CmsADEConfigDataInternal parseSitemapConfiguration(String basePath, CmsResource configRes) throws CmsException { LOG.info("Parsing configuration " + configRes.getRootPath()); CmsFile configFile = m_cms.readFile(configRes); CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, configFile); return parseConfiguration(basePath, content); }
/** * Parses the contents of a file.<p> * * @param file the file to parse * * @throws CmsException if something goes wrong */ public void parse(CmsFile file) throws CmsException { CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file); for (Locale locale : content.getLocales()) { m_currentLocale = locale; CmsXmlContentRootLocation rootLocation = new CmsXmlContentRootLocation(content, locale); parseConfigurationGroup(rootLocation); } }
/** * Unmarshals the descriptor content. * * @throws CmsXmlException thrown if the XML structure of the descriptor is wrong. * @throws CmsException thrown if reading the descriptor file fails. */ private void unmarshalDescriptor() throws CmsXmlException, CmsException { if (null != m_desc) { // unmarshal descriptor m_descContent = CmsXmlContentFactory.unmarshal(m_cms, m_cms.readFile(m_desc)); // configure messages if wanted CmsProperty bundleProp = m_cms.readPropertyObject(m_desc, PROPERTY_BUNDLE_DESCRIPTOR_LOCALIZATION, true); if (!(bundleProp.isNullProperty() || bundleProp.getValue().trim().isEmpty())) { m_configuredBundle = bundleProp.getValue(); } } }
/** * @see org.opencms.workplace.editors.CmsEditor#commitTempFile() */ @Override protected void commitTempFile() throws CmsException { super.commitTempFile(); m_file = getCloneCms().readFile(getParamResource()); m_content = CmsXmlContentFactory.unmarshal(getCloneCms(), m_file); }
/** * @see org.opencms.workplace.editors.CmsEditor#commitTempFile() */ @Override protected void commitTempFile() throws CmsException { super.commitTempFile(); m_file = getCloneCms().readFile(getParamResource()); m_content = CmsXmlContentFactory.unmarshal(getCloneCms(), m_file); }
/** * @see org.opencms.file.types.I_CmsResourceType#writeFile(org.opencms.file.CmsObject, CmsSecurityManager, CmsFile) */ @Override public CmsFile writeFile(CmsObject cms, CmsSecurityManager securityManager, CmsFile resource) throws CmsException { // check if the user has write access and if resource is locked // done here so that all the XML operations are not performed if permissions not granted securityManager.checkPermissions( cms.getRequestContext(), resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL); // read the XML content, use the encoding set in the property CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(cms, resource, true); // call the content handler for post-processing resource = xmlContent.getHandler().prepareForWrite(cms, xmlContent, resource); // now write the file return super.writeFile(cms, securityManager, resource); }
/** * Writes the xml content to the vfs and re-initializes the member variables.<p> * * @throws CmsException if writing the file fails */ private void writeContent() throws CmsException { String decodedContent = m_content.toString(); try { m_file.setContents(decodedContent.getBytes(getFileEncoding())); } catch (UnsupportedEncodingException e) { throw new CmsException(Messages.get().container(Messages.ERR_INVALID_CONTENT_ENC_1, getParamResource()), e); } // the file content might have been modified during the write operation m_file = getCloneCms().writeFile(m_file); m_content = CmsXmlContentFactory.unmarshal(getCloneCms(), m_file); } }
/** * Returns true if the preview is available for the edited xml content.<p> * * This method has to use the resource request parameter and read the file from vfs because the temporary file is * not available in the upper button frame.<p> * * @return true if the preview is enabled, otherwise false */ public boolean isPreviewEnabled() { try { // read the original file because temporary file is not created when opening button frame CmsFile file = getCms().readFile(getParamResource(), CmsResourceFilter.ALL); CmsXmlContent content = CmsXmlContentFactory.unmarshal(getCloneCms(), file); return content.getHandler().getPreview(getCms(), m_content, getParamResource()) != null; } catch (Exception e) { // error reading or unmarshalling, no preview available return false; } }
/** * Writes the xml content to the vfs and re-initializes the member variables.<p> * * @throws CmsException if writing the file fails */ private void writeContent() throws CmsException { String decodedContent = m_content.toString(); try { m_file.setContents(decodedContent.getBytes(getFileEncoding())); } catch (UnsupportedEncodingException e) { throw new CmsException(Messages.get().container(Messages.ERR_INVALID_CONTENT_ENC_1, getParamResource()), e); } // the file content might have been modified during the write operation CmsObject cloneCms = getCloneCms(); CmsUUID tempProjectId = OpenCms.getWorkplaceManager().getTempFileProjectId(); cloneCms.getRequestContext().setCurrentProject(getCms().readProject(tempProjectId)); m_file = cloneCms.writeFile(m_file); m_content = CmsXmlContentFactory.unmarshal(cloneCms, m_file); } }