/** * @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); }
/** * 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); } }
CmsObject cloneCms = getCloneCms(); CmsUUID tempProjectId = OpenCms.getWorkplaceManager().getTempFileProjectId(); cloneCms.getRequestContext().setCurrentProject(getCms().readProject(tempProjectId));
/** * 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); } }
/** * 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.getContentDefinition().getContentHandler().getPreview( getCms(), m_content, getParamResource()) != null; } catch (Exception e) { // error reading or unmarshalling, no preview available return false; } }
try { m_file = getCms().readFile(getParamTempfile(), CmsResourceFilter.ALL); m_content = CmsXmlContentFactory.unmarshal(getCloneCms(), m_file); } catch (CmsException e) { m_content = CmsXmlContentFactory.unmarshal(getCloneCms(), m_file);
CmsXmlContent template = CmsXmlContentFactory.unmarshal(getCloneCms(), templateFile); Locale locale = OpenCms.getLocaleManager().getDefaultLocales(getCms(), getParamResource()).get(0); getCloneCms().writeFile(newFile);
try { m_file = getCms().readFile(this.getParamTempfile(), CmsResourceFilter.ALL); m_content = CmsXmlContentFactory.unmarshal(getCloneCms(), m_file); } catch (CmsException e) { m_content = CmsXmlContentFactory.unmarshal(getCloneCms(), m_file);
/** * Performs the copy locale action.<p> * * @throws JspException if something goes wrong */ public void actionCopyElementLocale() throws JspException { try { setEditorValues(getElementLocale()); if (!hasValidationErrors()) { // save content of the editor only to the temporary file writeContent(); CmsObject cloneCms = getCloneCms(); CmsUUID tempProjectId = OpenCms.getWorkplaceManager().getTempFileProjectId(); cloneCms.getRequestContext().setCurrentProject(getCms().readProject(tempProjectId)); // remove eventual release & expiration date from temporary file to make preview work cloneCms.setDateReleased(getParamTempfile(), CmsResource.DATE_RELEASED_DEFAULT, false); cloneCms.setDateExpired(getParamTempfile(), CmsResource.DATE_EXPIRED_DEFAULT, false); } } catch (CmsException e) { // show error page showErrorPage(this, e); } }