/** * Create a new 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 */ protected CmsXmlContent(CmsObject cms, Locale locale, String encoding, CmsXmlContentDefinition contentDefinition) { // content defition must be set here since it's used during document creation m_contentDefinition = contentDefinition; // create the XML document according to the content definition Document document = m_contentDefinition.createDocument(cms, this, locale); // initialize the XML content structure initDocument(cms, 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); }
/** * 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); }
/** * Create a new 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 */ protected CmsXmlContent(CmsObject cms, Locale locale, String encoding, CmsXmlContentDefinition contentDefinition) { // content defition must be set here since it's used during document creation m_contentDefinition = contentDefinition; // create the XML document according to the content definition Document document = m_contentDefinition.createDocument(cms, this, locale); // initialize the XML content structure initDocument(cms, document, encoding, m_contentDefinition); }
/** * @see java.lang.Object#clone() */ @Override public CmsXmlContent clone() { CmsXmlContent clone = new CmsXmlContent(); clone.m_autoCorrectionEnabled = m_autoCorrectionEnabled; clone.m_contentDefinition = m_contentDefinition; clone.m_conversion = m_conversion; clone.m_document = (Document)(m_document.clone()); clone.m_encoding = m_encoding; clone.m_file = m_file; clone.initDocument(); return clone; }
/** * 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 getHandler().invalidateBrokenLinks(cms, this); } }
/** * 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); } }
/** * @see org.opencms.xml.I_CmsXmlDocument#addLocale(org.opencms.file.CmsObject, java.util.Locale) */ public void addLocale(CmsObject cms, Locale locale) throws CmsXmlException { if (hasLocale(locale)) { throw new CmsXmlException(org.opencms.xml.page.Messages.get().container( org.opencms.xml.page.Messages.ERR_XML_PAGE_LOCALE_EXISTS_1, locale)); } // add element node for Locale m_contentDefinition.createLocale(cms, this, m_document.getRootElement(), locale); // re-initialize the bookmarks initDocument(cms, m_document, m_encoding, m_contentDefinition); }
/** * @see org.opencms.xml.I_CmsXmlDocument#addLocale(org.opencms.file.CmsObject, java.util.Locale) */ public void addLocale(CmsObject cms, Locale locale) throws CmsXmlException { if (hasLocale(locale)) { throw new CmsXmlException( org.opencms.xml.page.Messages.get().container( org.opencms.xml.page.Messages.ERR_XML_PAGE_LOCALE_EXISTS_1, locale)); } // add element node for Locale m_contentDefinition.createLocale(cms, this, m_document.getRootElement(), locale); // re-initialize the bookmarks initDocument(cms, m_document, m_encoding, m_contentDefinition); }
/** * Removes an existing XML content value of the given element name and locale at the given index position * from this XML content document.<p> * * @param name the name of the XML content value element * @param locale the locale where to remove the value * @param index the index where to remove the value (relative to all other values of this type) */ public void removeValue(String name, Locale locale, int index) { // first get the value from the selected locale and index I_CmsXmlContentValue value = getValue(name, locale, index); // check for the min / max occurs constrains List<I_CmsXmlContentValue> values = getValues(name, locale); if (values.size() <= value.getMinOccurs()) { // must not allow removing an element if min occurs would be violated throw new CmsRuntimeException(Messages.get().container( Messages.ERR_XMLCONTENT_ELEM_MINOCCURS_2, name, new Integer(value.getMinOccurs()))); } // detach the value node from the XML document value.getElement().detach(); // re-initialize this XML content initDocument(m_document, m_encoding, m_contentDefinition); }
document.initDocument();
document.initDocument();
/** * Removes an existing XML content value of the given element name and locale at the given index position * from this XML content document.<p> * * @param name the name of the XML content value element * @param locale the locale where to remove the value * @param index the index where to remove the value (relative to all other values of this type) */ public void removeValue(String name, Locale locale, int index) { // first get the value from the selected locale and index I_CmsXmlContentValue value = getValue(name, locale, index); if (!value.isChoiceOption()) { // check for the min / max occurs constrains List<I_CmsXmlContentValue> values = getValues(name, locale); if (values.size() <= value.getMinOccurs()) { // must not allow removing an element if min occurs would be violated throw new CmsRuntimeException( Messages.get().container( Messages.ERR_XMLCONTENT_ELEM_MINOCCURS_2, name, new Integer(value.getMinOccurs()))); } } // detach the value node from the XML document value.getElement().detach(); // re-initialize this XML content initDocument(m_document, m_encoding, m_contentDefinition); }
initDocument(m_document, m_encoding, getContentDefinition());
initDocument(m_document, m_encoding, getContentDefinition());
initDocument(m_document, m_encoding, m_contentDefinition);
/** * Adds the given messages to the vfs message bundle.<p> * * @param messages the messages * @param vfsBundleFile the bundle file * * @throws CmsException if something goes wrong writing the file */ private void addMessagesToVfsBundle(Map<String, String> messages, CmsFile vfsBundleFile) throws CmsException { lockTemporary(vfsBundleFile); CmsObject cms = getCms(); CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, vfsBundleFile); Locale locale = CmsLocaleManager.getDefaultLocale(); if (!content.hasLocale(locale)) { content.addLocale(cms, locale); } Element root = content.getLocaleNode(locale); for (Entry<String, String> entry : messages.entrySet()) { Element message = root.addElement(CmsVfsBundleLoaderXml.N_MESSAGE); Element key = message.addElement(CmsVfsBundleLoaderXml.N_KEY); key.setText(entry.getKey()); Element value = message.addElement(CmsVfsBundleLoaderXml.N_VALUE); value.setText(entry.getValue()); } content.initDocument(); vfsBundleFile.setContents(content.marshal()); cms.writeFile(vfsBundleFile); }
initDocument(m_document, m_encoding, m_contentDefinition);
initDocument(cms, document, model.getEncoding(), m_contentDefinition);
initDocument(cms, document, model.getEncoding(), m_contentDefinition);