Tabnine Logo
CmsXmlContent.getLocales
Code IndexAdd Tabnine to your IDE (free)

How to use
getLocales
method
in
org.opencms.xml.content.CmsXmlContent

Best Java code snippets using org.opencms.xml.content.CmsXmlContent.getLocales (Showing top 20 results out of 315)

origin: org.opencms/opencms-core

/**
 * 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);
}
origin: org.opencms/opencms-core

/**
 * 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);
}
origin: org.opencms/opencms-core

/**
 * 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);
    }
  }
}
origin: org.opencms/opencms-core

/**
 * 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);
    }
  }
}
origin: org.opencms/opencms-core

/**
 * 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);
    }
  }
}
origin: org.opencms/opencms-core

/**
 * 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;
  }
}
origin: org.opencms/opencms-core

  continue;
for (Locale locale : content.getLocales()) {
  if (content.hasValue(path, locale)) {
    continue;
origin: org.opencms/opencms-core

/**
 * 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);
  }
}
origin: org.opencms/opencms-solr

/**
 * 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());
}
origin: org.opencms/opencms-core

List<Locale> locales = m_content.getLocales();
if (locales.size() > 0) {
origin: org.opencms.modules/org.opencms.frontend.templateone

/**
 * 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;
}
origin: org.opencms/opencms-solr

List locales = m_content.getLocales();
if (locales.size() > 0) {
origin: org.opencms/opencms-core

/**
 * 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);
    }
  }
}
origin: org.opencms/opencms-core

  /**
   * @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;
  }
}
origin: org.opencms/opencms-core

  if ((m_content.getLocales().size() > 0)) {
locale = m_content.getLocales().get(0);
origin: org.opencms/opencms-core

  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();
origin: org.opencms/opencms-core

+ newLocale
+ ", contentLocales="
+ content.getLocales());
origin: org.opencms/opencms-core

/**
 * 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));
      }
    }
  }
}
origin: org.opencms/opencms-core

int locales = xmlContent.getLocales().size();
origin: org.opencms/opencms-core

/**
 * 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);
}
org.opencms.xml.contentCmsXmlContentgetLocales

Popular methods of CmsXmlContent

  • getValue
  • getStringValue
  • getValues
  • hasLocale
  • getFile
  • marshal
  • addValue
    Adds a new XML schema type with the default value to the given parent node.
  • getIndexCount
  • hasValue
  • addLocale
  • copyLocale
    Copies the content of the given source locale to the given destination locale in this XML document.
  • correctXmlStructure
  • copyLocale,
  • correctXmlStructure,
  • getEncoding,
  • getLocaleNode,
  • initDocument,
  • removeLocale,
  • setAutoCorrectionEnabled,
  • toString,
  • visitAllValuesWith

Popular in Java

  • Reactive rest calls using spring rest template
  • setRequestProperty (URLConnection)
  • notifyDataSetChanged (ArrayAdapter)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now