/** * Helper method for getting the locale from which to read the configuration data.<p> * * @param content the configuration content * * @return the locale from which to read the configuration data */ private Locale getLocale(CmsXmlContent content) { List<Locale> locales = content.getLocales(); if (locales.contains(Locale.ENGLISH) || locales.isEmpty()) { return Locale.ENGLISH; } return locales.get(0); }
/** * Helper method for getting the locale from which to read the configuration data.<p> * * @return the locale from which to read the configuration data * * @throws CmsException if something goes wrong */ private Locale getLocale() throws CmsException { getDocument(); List<Locale> locales = m_document.getLocales(); if (locales.contains(Locale.ENGLISH) || locales.isEmpty()) { return Locale.ENGLISH; } return locales.get(0); }
/** * Removes all values of the given path in the other locales.<p> * * @param elementPath the element path * @param sourceLocale the source locale */ private void removeValuesInOtherLocales(String elementPath, Locale sourceLocale) { for (Locale locale : getLocales()) { if (locale.equals(sourceLocale)) { continue; } while (hasValue(elementPath, locale)) { removeValue(elementPath, locale, 0); } } }
/** * Removes all surplus values of locale independent fields in the other locales.<p> * * @param elementPath the element path * @param valueCount the value count * @param sourceLocale the source locale */ private void removeSurplusValuesInOtherLocales(String elementPath, int valueCount, Locale sourceLocale) { for (Locale locale : getLocales()) { if (locale.equals(sourceLocale)) { continue; } List<I_CmsXmlContentValue> localeValues = getValues(elementPath, locale); for (int i = valueCount; i < localeValues.size(); i++) { removeValue(elementPath, locale, 0); } } }
/** * Parses the given XML content.<p> * * @param content the XML content to parse */ protected void parse(CmsXmlContent content) { List<Locale> availableLocales = content.getLocales(); for (Locale locale : availableLocales) { CmsXmlContentRootLocation location = new CmsXmlContentRootLocation(content, locale); CmsInheritanceReference ref = parseReference(location, locale); if (ref != null) { m_references.put(locale, ref); } } }
/** * 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; } }
continue; for (Locale locale : content.getLocales()) { if (content.hasValue(path, locale)) { continue;
/** * Parses the contents of a file.<p> * * @param file the file to parse * * @throws CmsException if something goes wrong */ public void parse(CmsFile file) throws CmsException { CmsXmlContent content = CmsXmlContentFactory.unmarshal(m_cms, file); for (Locale locale : content.getLocales()) { m_currentLocale = locale; CmsXmlContentRootLocation rootLocation = new CmsXmlContentRootLocation(content, locale); parseConfigurationGroup(rootLocation); } }
/** * 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()); }
List<Locale> locales = m_content.getLocales(); if (locales.size() > 0) {
/** * Returns the configuration value for the specified key from the configuration.<p> * * @param key the key name to look up * @param defaultValue the default value used when no value was found for the key * @return the configuration value for the specified key */ public String getConfigValue(String key, String defaultValue) { String value = null; try { value = m_configuration.getStringValue(getCmsObject(), key, getRequestContext().getLocale()); if (CmsStringUtil.isEmpty(value)) { // value not found for current Locale, try to get it from first found Locale value = m_configuration.getStringValue(getCmsObject(), key, (Locale)m_configuration.getLocales().get(0)); } } catch (Exception e) { // log error in debug mode if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage(), e); } } if (CmsStringUtil.isEmpty(value)) { // no configuration value found, use the default value value = defaultValue; } return value; }
List locales = m_content.getLocales(); if (locales.size() > 0) {
/** * 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); } } }
/** * @see org.opencms.i18n.CmsVfsResourceBundle.I_Loader#loadData(org.opencms.file.CmsObject, org.opencms.i18n.CmsVfsBundleParameters) */ public Map<Locale, Map<String, String>> loadData(CmsObject cms, CmsVfsBundleParameters params) throws Exception { CmsFile file = cms.readFile(params.getBasePath()); CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, file); Map<Locale, Map<String, String>> result = Maps.newHashMap(); for (Locale locale : content.getLocales()) { List<I_CmsXmlContentValue> messages = content.getValues(N_MESSAGE, locale); Map<String, String> currentLocale = new HashMap<String, String>(); for (I_CmsXmlContentValue messageValue : messages) { String path = messageValue.getPath(); I_CmsXmlContentValue keyValue = content.getValue(CmsXmlUtils.concatXpath(path, N_KEY), locale); String keyStr = keyValue.getStringValue(cms); // Ignore leading/trailing spaces in the key to protect from user error keyStr = keyStr.trim(); I_CmsXmlContentValue valueValue = content.getValue(CmsXmlUtils.concatXpath(path, N_VALUE), locale); String valueStr = valueValue.getStringValue(cms); currentLocale.put(keyStr, valueStr); } result.put(locale, currentLocale); } return result; } }
if ((m_content.getLocales().size() > 0)) { locale = m_content.getLocales().get(0);
locales = CmsXmlPageFactory.unmarshal(getCmsObject(), resource, getRequest()).getLocales(); } else if (CmsResourceTypeXmlContent.isXmlContent(resource)) { locales = CmsXmlContentFactory.unmarshal(getCmsObject(), resource, getRequest()).getLocales(); } else if (CmsResourceTypeXmlContainerPage.isContainerPage(resource)) { locales = CmsXmlContainerPageFactory.unmarshal(getCmsObject(), resource).getLocales();
+ newLocale + ", contentLocales=" + content.getLocales());
/** * Sets the value in all other locales.<p> * * @param cms the cms context * @param value the value * @param requiredParent the path to the required parent value */ private void setValueForOtherLocales(CmsObject cms, I_CmsXmlContentValue value, String requiredParent) { if (!value.isSimpleType()) { throw new IllegalArgumentException(); } for (Locale locale : getLocales()) { if (locale.equals(value.getLocale())) { continue; } String valuePath = value.getPath(); if (CmsStringUtil.isEmptyOrWhitespaceOnly(requiredParent) || hasValue(requiredParent, locale)) { ensureParentValues(cms, valuePath, locale); if (hasValue(valuePath, locale)) { I_CmsXmlContentValue localeValue = getValue(valuePath, locale); localeValue.setStringValue(cms, value.getStringValue(cms)); } else { int index = CmsXmlUtils.getXpathIndexInt(valuePath) - 1; I_CmsXmlContentValue localeValue = addValue(cms, valuePath, locale, index); localeValue.setStringValue(cms, value.getStringValue(cms)); } } } }
int locales = xmlContent.getLocales().size();
/** * Saves the inheritance group.<p> * * @param resource the inheritance group resource * @param inheritanceContainer the inherited group container data * * @throws CmsException if something goes wrong */ private void saveInheritanceGroup(CmsResource resource, CmsInheritanceContainer inheritanceContainer) throws CmsException { CmsObject cms = getCmsObject(); CmsFile file = cms.readFile(resource); CmsXmlContent document = CmsXmlContentFactory.unmarshal(cms, file); for (Locale docLocale : document.getLocales()) { document.removeLocale(docLocale); } Locale locale = Locale.ENGLISH; document.addLocale(cms, locale); document.getValue("Title", locale).setStringValue(cms, inheritanceContainer.getTitle()); document.getValue("Description", locale).setStringValue(cms, inheritanceContainer.getDescription()); document.getValue("ConfigName", locale).setStringValue(cms, inheritanceContainer.getName()); byte[] content = document.marshal(); file.setContents(content); cms.writeFile(file); }