/** * @see org.opencms.xml.I_CmsXmlDocument#getHandler() */ public I_CmsXmlContentHandler getHandler() { return getContentDefinition().getContentHandler(); }
/** * Creates a new error handler node visitor.<p> * * @param cms the initialized OpenCms user context (required for VFS access) * @param content the XML content to resolve the mappings for */ public CmsXmlContentMappingVisitor(CmsObject cms, CmsXmlContent content) { // store references m_cms = cms; m_content = content; m_handler = content.getContentDefinition().getContentHandler(); }
/** * Creates a new XML content based on the provided XML document.<p> * * The given encoding is used when marshalling the XML again later.<p> * * @param cms the cms context, if <code>null</code> no link validation is performed * @param document the document to create the xml content from * @param encoding the encoding of the xml content * @param resolver the XML entitiy resolver to use */ protected CmsXmlContent(CmsObject cms, Document document, String encoding, EntityResolver resolver) { // must set document first to be able to get the content definition m_document = document; // for the next line to work the document must already be available m_contentDefinition = getContentDefinition(resolver); // initialize the XML content structure initDocument(cms, m_document, encoding, m_contentDefinition); }
/** * Creates a new XML content based on the provided XML document.<p> * * The given encoding is used when marshalling the XML again later.<p> * * @param cms the cms context, if <code>null</code> no link validation is performed * @param document the document to create the xml content from * @param encoding the encoding of the xml content * @param resolver the XML entitiy resolver to use */ protected CmsXmlContent(CmsObject cms, Document document, String encoding, EntityResolver resolver) { // must set document first to be able to get the content definition m_document = document; // for the next line to work the document must already be available m_contentDefinition = getContentDefinition(resolver); // initialize the XML content structure initDocument(cms, m_document, encoding, m_contentDefinition); }
/** * Synchronizes the locale independent fields for the given locale.<p> * * @param cms the cms context * @param skipPaths the paths to skip * @param sourceLocale the source locale */ public void synchronizeLocaleIndependentValues(CmsObject cms, Collection<String> skipPaths, Locale sourceLocale) { if (getContentDefinition().getContentHandler().hasSynchronizedElements() && (getLocales().size() > 1)) { for (String elementPath : getContentDefinition().getContentHandler().getSynchronizations()) { synchronizeElement(cms, elementPath, skipPaths, sourceLocale); } } }
/** * 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(); }
/** * Initializes an XML document based on the provided document, encoding and content definition.<p> * * Checks the links and removes invalid ones in the initialized document.<p> * * @param cms the current users OpenCms content * @param document the base XML document to use for initializing * @param encoding the encoding to use when marshalling the document later * @param definition the content definition to use */ protected void initDocument(CmsObject cms, Document document, String encoding, CmsXmlContentDefinition definition) { initDocument(document, encoding, definition); // check invalid links if (cms != null) { // this will remove all invalid links getContentDefinition().getContentHandler().invalidateBrokenLinks(cms, this); } }
/** * Create a new instance of an XML content based on the given default content, * hat will have all language nodes of the default content and ensures the presence of the given locale.<p> * * The given encoding is used when marshalling the XML again later.<p> * * @param cms the current users OpenCms content * @param locale the locale to generate the default content for * @param modelUri the absolute path to the XML content file acting as model * * @throws CmsException in case the model file is not found or not valid * * @return the created XML content */ public static CmsXmlContent createDocument(CmsObject cms, Locale locale, String modelUri) throws CmsException { // create the XML content CmsXmlContent content = new CmsXmlContent(cms, locale, modelUri); // call prepare for use content handler and return the result return content.getContentDefinition().getContentHandler().prepareForUse(cms, content); }
/** * Create a new instance of an XML content based on the given default content, * hat will have all language nodes of the default content and ensures the presence of the given locale.<p> * * The given encoding is used when marshalling the XML again later.<p> * * @param cms the current users OpenCms content * @param locale the locale to generate the default content for * @param modelUri the absolute path to the XML content file acting as model * * @throws CmsException in case the model file is not found or not valid * * @return the created XML content */ public static CmsXmlContent createDocument(CmsObject cms, Locale locale, String modelUri) throws CmsException { // create the XML content CmsXmlContent content = new CmsXmlContent(cms, locale, modelUri); // call prepare for use content handler and return the result return content.getContentDefinition().getContentHandler().prepareForUse(cms, content); }
/** * Factory method to unmarshal (generate) a XML content instance from a XML document.<p> * * The given encoding is used when marshalling the XML again later.<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 cms context, if <code>null</code> no link validation is performed * @param document the XML document to generate the XML content from * @param encoding the encoding to use when marshalling the XML content later * @param resolver the XML entitiy resolver to use * * @return a XML content instance unmarshalled from the String */ public static CmsXmlContent unmarshal(CmsObject cms, Document document, String encoding, EntityResolver resolver) { CmsXmlContent content = new CmsXmlContent(cms, document, encoding, resolver); // call prepare for use content handler and return the result return content.getContentDefinition().getContentHandler().prepareForUse(cms, content); }
/** * Create a new instance of an XML content based on the given content definiton, * that will have one language node for the given locale all initialized with default values.<p> * * The given encoding is used when marshalling the XML again later.<p> * * @param cms the current users OpenCms content * @param locale the locale to generate the default content for * @param encoding the encoding to use when marshalling the XML content later * @param contentDefinition the content definiton to create the content for * * @return the created XML content */ public static CmsXmlContent createDocument( CmsObject cms, Locale locale, String encoding, CmsXmlContentDefinition contentDefinition) { // create the XML content CmsXmlContent content = new CmsXmlContent(cms, locale, encoding, contentDefinition); // call prepare for use content handler and return the result return content.getContentDefinition().getContentHandler().prepareForUse(cms, content); }
/** * Checks whether GWT widgets are available for all fields of a content.<p> * * @param cms the current CMS context * @param resource the resource to check * * @return false if for some fields the new Acacia widgets are not available * * @throws CmsException if something goes wrong */ public static boolean checkAcaciaEditorAvailable(CmsObject cms, CmsResource resource) throws CmsException { if (resource == null) { try { // we want a stack trace throw new Exception(); } catch (Exception e) { LOG.error("Can't check widget availability because resource is null!", e); } return false; } CmsFile file = (resource instanceof CmsFile) ? (CmsFile)resource : cms.readFile(resource); CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, file); if (content.getContentDefinition().getContentHandler().isAcaciaEditorDisabled()) { return false; } CmsContentTypeVisitor visitor = new CmsContentTypeVisitor(cms, file, cms.getRequestContext().getLocale()); return visitor.isEditorCompatible(content.getContentDefinition()); }
/** * 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.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(); }
String schema = xmlContent.getContentDefinition().getSchemaLocation(); if (schema.startsWith(CmsXmlEntityResolver.OPENCMS_SCHEME)) { if (CmsXmlEntityResolver.isInternalId(schema)) {
/** * Returns the available sub choices for a nested choice element.<p> * * @return the available sub choices for a nested choice element as JSON array string */ public String buildSubChoices() { String elementPath = getParamElementName(); // we have to add a choice element, first check if the element to add itself is part of a choice or not boolean choiceType = Boolean.valueOf(getParamChoiceType()).booleanValue(); I_CmsXmlSchemaType elemType = m_content.getContentDefinition().getSchemaType(elementPath); if (!choiceType || (elemType.isChoiceOption() && elemType.isChoiceType())) { // this is a choice option or a nested choice type to add, remove last element name from xpath elementPath = CmsXmlUtils.removeLastXpathElement(elementPath); } elementPath = CmsXmlUtils.concatXpath(elementPath, getParamChoiceElement()); return buildElementChoices(elementPath, choiceType, false).toString(); }
/** * @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, false); // call the content handler for post-processing resource = xmlContent.getContentDefinition().getContentHandler().prepareForWrite(cms, xmlContent, resource); // now write the file return super.writeFile(cms, securityManager, resource); } }
/** * Generates a new content sequence element from the given type, content and content definition.<p> * * @param path the path in the document to generate the value sequence for * @param locale the locale to get the content values from * @param content the XML content to generate the sequence element out of */ public CmsXmlContentValueSequence(String path, Locale locale, CmsXmlContent content) { m_locale = locale; m_content = content; m_path = CmsXmlUtils.removeXpathIndex(path); I_CmsXmlSchemaType type = m_content.getContentDefinition().getSchemaType(m_path); m_isChoiceSequence = type.isChoiceOption(); if (m_isChoiceSequence) { m_values = m_content.getSubValues(CmsXmlUtils.removeLastXpathElement(m_path), m_locale); } else { m_values = m_content.getValues(path, m_locale); } if (type.getContentDefinition().getChoiceMaxOccurs() > 1) { m_minOccurs = 0; m_maxOccurs = type.getContentDefinition().getChoiceMaxOccurs(); } else { if (m_isChoiceSequence && !m_values.isEmpty()) { type = m_values.get(0); } m_minOccurs = type.getMinOccurs(); m_maxOccurs = type.getMaxOccurs(); } }
I_CmsXmlContentValue value = content.getValue(contentPath, locale); value.setStringValue(cms, newValue); for (I_CmsXmlContentEditorChangeHandler handler : content.getContentDefinition().getContentHandler().getEditorChangeHandlers()) { Set<String> handlerScopes = evaluateScope(handler.getScope(), content.getContentDefinition()); if (handlerScopes.contains(contentPath)) { handler.handleChange(cms, content, locale, Collections.singletonList(contentPath));
/** * 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; } }