/** * Returns the error handler for error handling of the edited xml content.<p> * * @return the error handler */ private CmsXmlContentErrorHandler getValidationHandler() { if (m_validationHandler == null) { // errors were not yet checked, do this now and store result in member m_validationHandler = m_content.validate(getCms()); } return m_validationHandler; }
/** * Returns the error handler for error handling of the edited xml content.<p> * * @return the error handler */ private CmsXmlContentErrorHandler getValidationHandler() { if (m_validationHandler == null) { // errors were not yet checked, do this now and store result in member m_validationHandler = m_content.validate(getCms()); } return m_validationHandler; }
/** * Sets the edit context URI.<p> * * @param editContext the edit context URI. */ public void setParamEditContext(String editContext) { m_paramEditContext = editContext; CmsObject cms = getCms(); if ((cms != null) && (editContext != null)) { cms.getRequestContext().setAttribute(ATTRIBUTE_EDITCONTEXT, editContext); } }
/** * Determines if the element language selector is shown dependent on the available Locales.<p> * * @return true, if more than one Locale is available, otherwise false */ public boolean showElementLanguageSelector() { List locales = OpenCms.getLocaleManager().getAvailableLocales(getCms(), getParamResource()); if ((locales == null) || (locales.size() < 2)) { // for less than two available locales, do not create language selector return false; } return true; }
/** * Generates the JavaScript initialization calls for the used widgets in the editor form.<p> * * @return the JavaScript initialization calls for the used widgets * @throws JspException if including the error page fails */ public String getXmlEditorInitCalls() throws JspException { StringBuffer result = new StringBuffer(512); try { // iterate over unique widgets from collector Iterator<I_CmsWidget> i = getWidgetCollector().getUniqueWidgets().iterator(); while (i.hasNext()) { I_CmsWidget widget = i.next(); result.append(widget.getDialogInitCall(getCms(), this)); } } catch (Exception e) { showErrorPage(e); } return result.toString(); }
/** * Generates the javascript initialization calls for the used widgets in the editor form.<p> * * @return the javascript initialization calls for the used widgets * @throws JspException if including the error page fails */ public String getXmlEditorInitCalls() throws JspException { StringBuffer result = new StringBuffer(512); try { // iterate over unique widgets from collector Iterator i = getWidgetCollector().getUniqueWidgets().iterator(); while (i.hasNext()) { I_CmsWidget widget = (I_CmsWidget)i.next(); result.append(widget.getDialogInitCall(getCms(), this)); } } catch (Exception e) { showErrorPage(e); } return result.toString(); }
/** * Determines if the element language selector is shown dependent on the available Locales.<p> * * @return true, if more than one Locale is available, otherwise false */ public boolean showElementLanguageSelector() { List<Locale> locales = OpenCms.getLocaleManager().getAvailableLocales(getCms(), getParamResource()); if ((locales == null) || (locales.size() < 2)) { // for less than two available locales, do not create language selector return false; } return true; }
/** * Initializes the element language for the first call of the editor.<p> */ protected void initElementLanguage() { // get the default locale for the resource List<Locale> locales = OpenCms.getLocaleManager().getDefaultLocales(getCms(), getParamResource()); Locale locale = locales.get(0); locale = ensureLocale(locale); setParamElementlanguage(locale.toString()); }
/** * Deletes the temporary file and unlocks the edited resource when in direct edit mode.<p> * * @param forceUnlock if true, the resource will be unlocked anyway */ @Override public void actionClear(boolean forceUnlock) { // delete the temporary file deleteTempFile(); boolean directEditMode = Boolean.valueOf(getParamDirectedit()).booleanValue(); boolean modified = Boolean.valueOf(getParamModified()).booleanValue(); if (directEditMode || forceUnlock || !modified) { // unlock the resource when in direct edit mode, force unlock is true or resource was not modified try { getCms().unlockResource(getParamResource()); } catch (CmsException e) { // should usually never happen if (LOG.isInfoEnabled()) { LOG.info(e.getLocalizedMessage(), e); } } } }
/** * 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(); }
/** * Deletes the temporary file and unlocks the edited resource when in direct edit mode.<p> * * @param forceUnlock if true, the resource will be unlocked anyway */ @Override public void actionClear(boolean forceUnlock) { // delete the temporary file deleteTempFile(); boolean directEditMode = Boolean.valueOf(getParamDirectedit()).booleanValue(); boolean modified = Boolean.valueOf(getParamModified()).booleanValue(); if (directEditMode || forceUnlock || !modified) { // unlock the resource when in direct edit mode, force unlock is true or resource was not modified try { getCms().unlockResource(getParamResource()); } catch (CmsException e) { // should usually never happen if (LOG.isInfoEnabled()) { LOG.info(e.getLocalizedMessage(), e); } } } }
/** * 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(); }
/** * 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; } }
/** * Initializes the element language for the first call of the editor.<p> */ protected void initElementLanguage() { // get the default locale for the resource List locales = OpenCms.getLocaleManager().getDefaultLocales(getCms(), getParamResource()); Locale locale = (Locale)locales.get(0); if (m_content != null) { // to copy anything we need at least one locale if ((locales.size() > 1) && (m_content.getLocales().size() > 0) && !m_content.hasLocale(locale)) { // required locale not available, check if an existing default locale should be copied as "template" try { // a list of possible default locales has been set as property, try to find a match m_content.copyLocale(locales, locale); writeContent(); } catch (CmsException e) { // no match was found for the required locale } } if (!m_content.hasLocale(locale)) { // value may have changed because of the copy operation locale = m_content.getLocales().get(0); } } setParamElementlanguage(locale.toString()); }
/** * Sets the editor values for the locale with the parameters from the request.<p> * * Called before saving the xml content, redisplaying the input form, * changing the language and adding or removing elements.<p> * * @param locale the locale of the content to save * @throws CmsXmlException if something goes wrong */ public void setEditorValues(Locale locale) throws CmsXmlException { List valueNames = getSimpleValueNames(m_content.getContentDefinition(), "", locale); Iterator i = valueNames.iterator(); while (i.hasNext()) { String valueName = (String)i.next(); I_CmsXmlContentValue value = m_content.getValue(valueName, locale); I_CmsWidget widget = value.getContentDefinition().getContentHandler().getWidget(value); widget.setEditorValue(getCms(), getJsp().getRequest().getParameterMap(), this, (I_CmsWidgetParameter)value); } }
/** * Generates the HTML form for the XML content editor.<p> * * @return the HTML that generates the form for the XML editor */ public String getXmlEditorForm() { // set "editor mode" attribute (required for link replacement in the root site) getCms().getRequestContext().setAttribute(CmsRequestContext.ATTRIBUTE_EDITOR, Boolean.TRUE); // add customized message bundle eventually specified in XSD of XML content addMessages(m_content.getContentDefinition().getContentHandler().getMessages(getLocale())); // initialize tab lists for error handling before generating the editor form m_errorTabs = new ArrayList(); m_warningTabs = new ArrayList(); return getXmlEditorForm(m_content.getContentDefinition(), "", true, false).toString(); }
/** * 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; } }
/** * Performs the copy locale action.<p> * * @throws JspException if something goes wrong */ public void actionCopyElementLocale() throws JspException { try { setEditorValues(getElementLocale()); if (!hasValidationErrors()) { // !m_content.validate(getCms()).hasErrors(getElementLocale())) { // save content of the editor only to the temporary file writeContent(); // remove eventual release & expiration date from temporary file to make preview work getCms().setDateReleased(getParamTempfile(), CmsResource.DATE_RELEASED_DEFAULT, false); getCms().setDateExpired(getParamTempfile(), CmsResource.DATE_EXPIRED_DEFAULT, false); } } catch (CmsException e) { // show error page showErrorPage(this, e); } }
/** * Generates the HTML form for the XML content editor.<p> * * @return the HTML that generates the form for the XML editor */ public String getXmlEditorForm() { // set "editor mode" attribute (required for link replacement in the root site) getCms().getRequestContext().setAttribute(CmsRequestContext.ATTRIBUTE_EDITOR, Boolean.TRUE); // add customized message bundle eventually specified in XSD of XML content addMessages(m_content.getHandler().getMessages(getLocale())); ((CmsMultiMessages)getMessages()).setFallbackHandler(m_content.getHandler().getMessageKeyHandler()); // initialize tab lists for error handling before generating the editor form m_errorTabs = new ArrayList<CmsXmlContentTab>(); m_warningTabs = new ArrayList<CmsXmlContentTab>(); return getXmlEditorForm(m_content.getContentDefinition(), "", true, false).toString(); }
/** * 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); } }