/** * Copies the contents from a source locale to a number of destination locales by overwriting them.<p> * * @param content the xml content * @param sourceLocale the source locale * @param destLocales a list of destination locales * @throws CmsException if something goes wrong */ protected void transferContents(CmsXmlContent content, Locale sourceLocale, List destLocales) throws CmsException { for (Iterator i = destLocales.iterator(); i.hasNext();) { Locale to = (Locale)i.next(); if (content.hasLocale(to)) { content.removeLocale(to); } content.copyLocale(sourceLocale, to); } } }
/** * Copies the contents from a source locale to a number of destination locales by overwriting them.<p> * * @param content the xml content * @param sourceLocale the source locale * @param destLocales a list of destination locales * @throws CmsException if something goes wrong */ protected void transferContents(CmsXmlContent content, Locale sourceLocale, List<Locale> destLocales) throws CmsException { for (Iterator<Locale> i = destLocales.iterator(); i.hasNext();) { Locale to = i.next(); if (content.hasLocale(to)) { content.removeLocale(to); } content.copyLocale(sourceLocale, to); } } }
if (!content.hasLocale(locale)) { List<Locale> locales = getDefaultLocales(cms, resource); for (Locale defaultLocale : locales) { if (content.hasLocale(defaultLocale)) { locale = defaultLocale; foundLocale = true; locales = getAvailableLocales(cms, resource); for (Locale availableLocale : locales) { if (content.hasLocale(availableLocale)) { locale = availableLocale; foundLocale = true;
/** * Gets the locale to use for parsing the dynamic function.<p> * * @param cms the current CMS context * @param xmlContent the xml content from which the dynamic function should be read * * @return the locale from which the dynamic function should be read */ protected Locale getLocaleToUse(CmsObject cms, CmsXmlContent xmlContent) { Locale contextLocale = cms.getRequestContext().getLocale(); if (xmlContent.hasLocale(contextLocale)) { return contextLocale; } Locale defaultLocale = CmsLocaleManager.getDefaultLocale(); if (xmlContent.hasLocale(defaultLocale)) { return defaultLocale; } if (!xmlContent.getLocales().isEmpty()) { return xmlContent.getLocales().get(0); } else { return defaultLocale; } }
throws CmsXmlException { if (!content.hasLocale(locale)) { content.addLocale(m_cms, locale);
/** * Initialize the key set for an xml bundle. */ private void initKeySetForXmlBundle() { // consider only available locales for (Locale l : m_locales) { if (m_xmlBundle.hasLocale(l)) { Set<Object> keys = new HashSet<Object>(); for (I_CmsXmlContentValue msg : m_xmlBundle.getValueSequence("Message", l).getValues()) { String msgpath = msg.getPath(); keys.add(m_xmlBundle.getStringValue(m_cms, msgpath + "/Key", l)); } m_keyset.updateKeySet(null, keys); } } }
/** * 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()); }
/** * @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); }
SortedProperties props = m_localizations.get(l); if (null != props) { if (m_xmlBundle.hasLocale(l)) { m_xmlBundle.removeLocale(l);
/** * Removes an existing inheritance container entry with a given name from the configuration file.<p> * * This does nothing if no such entry actually exists.<p> * * @param cms the current CMS context * @param content the XML content * @param locale the locale from which to remove the entry * @param name the name of the entry * */ protected void removeExistingEntry(CmsObject cms, CmsXmlContent content, Locale locale, String name) { if (!content.hasLocale(locale)) { return; } String entriesXpath = N_CONFIGURATION; List<I_CmsXmlContentValue> values = content.getValues(entriesXpath, locale); int valueIndex = 0; for (I_CmsXmlContentValue value : values) { String valueXpath = value.getPath(); I_CmsXmlContentValue nameValue = content.getValue(CmsXmlUtils.concatXpath(valueXpath, N_NAME), locale); String currentName = nameValue.getStringValue(cms); if (currentName.equals(name)) { content.removeValue(valueXpath, locale, valueIndex); break; } valueIndex += 1; } }
/** * Returns the content values.<p> * * @return the content values * * @throws CmsException if reading the content fails */ public Map<String, String> getValues() throws CmsException { CmsFile file = m_cms.readFile(m_editResource); CmsXmlContent content = unmarshalXmlContent(file); Locale locale = m_cms.getRequestContext().getLocale(); if (!content.hasLocale(locale)) { content.addLocale(m_cms, locale); } return getContentValues(content, locale); }
if (!content.hasLocale(locale)) { content.addLocale(cms, locale);
String entityId = entity.getId(); Locale contentLocale = CmsLocaleManager.getLocale(CmsContentDefinition.getLocaleFromId(entityId)); if (content.hasLocale(contentLocale)) { content.removeLocale(contentLocale);
/** * 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); }
/** * @see org.opencms.ade.contenteditor.shared.rpc.I_CmsContentService#copyLocale(java.util.Collection, org.opencms.acacia.shared.CmsEntity) */ public void copyLocale(Collection<String> locales, CmsEntity sourceLocale) throws CmsRpcException { try { CmsUUID structureId = CmsContentDefinition.entityIdToUuid(sourceLocale.getId()); CmsResource resource = getCmsObject().readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION); CmsFile file = getCmsObject().readFile(resource); CmsXmlContent content = getSessionCache().getCacheXmlContent(structureId); synchronizeLocaleIndependentForEntity(file, content, Collections.<String> emptyList(), sourceLocale); Locale sourceContentLocale = CmsLocaleManager.getLocale( CmsContentDefinition.getLocaleFromId(sourceLocale.getId())); for (String loc : locales) { Locale targetLocale = CmsLocaleManager.getLocale(loc); if (content.hasLocale(targetLocale)) { content.removeLocale(targetLocale); } content.copyLocale(sourceContentLocale, targetLocale); } } catch (Throwable t) { error(t); } }
if (!hasLocale(locale)) {
if (!hasLocale(locale)) {