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

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

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

origin: org.opencms/opencms-core

SortedProperties props = m_localizations.get(l);
if (null != props) {
  if (m_xmlBundle.hasLocale(l)) {
    m_xmlBundle.removeLocale(l);
  m_xmlBundle.addLocale(m_cms, l);
  int i = 0;
  List<Object> keys = new ArrayList<Object>(props.keySet());
      String value = props.getProperty(key.toString());
      if (!value.isEmpty()) {
        m_xmlBundle.addValue(m_cms, "Message", l, i);
        i++;
        m_xmlBundle.getValue("Message[" + i + "]/Key", l).setStringValue(m_cms, key.toString());
        m_xmlBundle.getValue("Message[" + i + "]/Value", l).setStringValue(m_cms, value);
bundleFile.setContents(m_xmlBundle.marshal());
m_cms.writeFile(bundleFile);
origin: org.opencms/opencms-core

  && content.getValue(changedPaths.iterator().next(), locale).getTypeName().equals(
    CmsXmlBooleanValue.TYPE_NAME)) {
  LOG.error(
    Messages.get().container(
      Messages.ERROR_CONFIGURATION_EDITOR_CHANGE_HANDLER_FORMATTER_SELECTION_1,
      content.getContentDefinition().getSchemaLocation()));
  return content;
String removeAllStringValue = content.getStringValue(cms, removeAllPath, locale);
boolean removeAll = Boolean.valueOf(removeAllStringValue).booleanValue();
if (removeAll && content.hasValue(REMOVE_PATH, locale)) {
  content.removeValue(REMOVE_PATH, locale, 0);
} else if (content.hasValue(ADD_PATH, locale)) {
  String rootPath = content.getFile().getRootPath();
  List<String> optionValues = CmsAddFormatterWidget.getSelectOptionValues(cms, rootPath, false);
  CmsXmlContentValueSequence addSequence = content.getValueSequence(ADD_PATH_SINGLE_NODE, locale);
  List<I_CmsXmlContentValue> values = addSequence.getValues();
  boolean removeMainAddNode = true;
      removeMainAddNode = false;
    } else {
      content.removeValue(ADD_PATH_SINGLE_NODE, locale, i);
    content.removeValue(ADD_PATH, locale, 0);
origin: org.opencms/opencms-core

/**
 * 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;
  }
}
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-solr

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

int defaultValueIndex = -1;
String defaultModelTarget = null;
for (I_CmsXmlContentValue value : content.getValues(CmsConfigurationReader.N_MODEL_PAGE, locale)) {
  I_CmsXmlContentValue linkValue = content.getValue(
    CmsStringUtil.joinPaths(value.getPath(), CmsConfigurationReader.N_PAGE),
    locale);
  I_CmsXmlContentValue isDefaultValue = content.getValue(
    CmsStringUtil.joinPaths(value.getPath(), CmsConfigurationReader.N_IS_DEFAULT),
    locale);
  content.removeValue(CmsConfigurationReader.N_MODEL_PAGE, locale, defaultValueIndex);
  content.addValue(m_cms, CmsConfigurationReader.N_MODEL_PAGE, locale, 0);
  content.getValue(
    CmsConfigurationReader.N_MODEL_PAGE + "[1]/" + CmsConfigurationReader.N_PAGE,
    locale).setStringValue(m_cms, defaultModelTarget);
  content.getValue(
    CmsConfigurationReader.N_MODEL_PAGE + "[1]/" + CmsConfigurationReader.N_DISABLED,
    locale).setStringValue(m_cms, Boolean.FALSE.toString());
  content.getValue(
    CmsConfigurationReader.N_MODEL_PAGE + "[1]/" + CmsConfigurationReader.N_IS_DEFAULT,
    locale).setStringValue(m_cms, Boolean.TRUE.toString());
content.setAutoCorrectionEnabled(true);
content.correctXmlStructure(m_cms);
file.setContents(content.marshal());
m_cms.writeFile(file);
OpenCms.getADEManager().waitForCacheUpdate(false);
origin: org.opencms/opencms-core

/**
 * Adds the given value to the content document.<p>
 *
 * @param content the content document
 * @param locale the content locale
 * @param path the value XPath
 * @param value the value
 */
protected void addContentValue(CmsXmlContent content, Locale locale, String path, String value) {
  boolean hasValue = content.hasValue(path, locale);
  if (!hasValue) {
    String[] pathElements = path.split("/");
    String currentPath = pathElements[0];
    for (int i = 0; i < pathElements.length; i++) {
      if (i > 0) {
        currentPath = CmsStringUtil.joinPaths(currentPath, pathElements[i]);
      }
      while (!content.hasValue(currentPath, locale)) {
        content.addValue(m_cms, currentPath, locale, CmsXmlUtils.getXpathIndexInt(currentPath) - 1);
      }
    }
  }
  content.getValue(path, locale).setStringValue(m_cms, value);
}
origin: org.opencms/opencms-core

String uselocale = configuration.getValue(XPATH_USELOCALE, m_configurationLocale).getStringValue(m_cms);
if (!uselocale.equals("true")) {
  m_locale = null;
int decorationDefCount = configuration.getIndexCount(XPATH_DECORATION, m_configurationLocale);
int excludeValuesCount = configuration.getIndexCount(XPATH_EXCLUDE, m_configurationLocale);
  String excludeValue = configuration.getStringValue(
    m_cms,
    XPATH_EXCLUDE + "[" + i + "]",
origin: org.opencms/opencms-core

/**
 * Reads the referenced formatters.<p>
 *
 * @param xmlContent the XML content
 *
 * @return the referenced formatters
 */
private Map<String, CmsUUID> readReferencedFormatters(CmsXmlContent xmlContent) {
  Map<String, CmsUUID> result = new LinkedHashMap<String, CmsUUID>();
  List<I_CmsXmlContentValue> formatters = xmlContent.getValues(
    CmsMacroFormatterResolver.N_FORMATTERS,
    CmsLocaleManager.MASTER_LOCALE);
  for (I_CmsXmlContentValue formatterValue : formatters) {
    CmsXmlVfsFileValue file = (CmsXmlVfsFileValue)xmlContent.getValue(
      formatterValue.getPath() + "/" + CmsMacroFormatterResolver.N_FORMATTER,
      CmsLocaleManager.MASTER_LOCALE);
    CmsUUID formatterId = file.getLink(m_cms).getStructureId();
    String macroName = xmlContent.getStringValue(
      m_cms,
      formatterValue.getPath() + "/" + CmsMacroFormatterResolver.N_MACRO_NAME,
      CmsLocaleManager.MASTER_LOCALE);
    result.put(macroName, formatterId);
  }
  return result;
}
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);
}
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

  /**
   * @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

/** Helper to read an optional String value.
 * @param path The XML path of the element to read.
 * @return The String value stored in the XML, or <code>null</code> if the value could not be read.
 */
protected String parseOptionalStringValue(final String path) {
  final I_CmsXmlContentValue value = m_xml.getValue(path, m_locale);
  if (value == null) {
    return null;
  } else {
    return value.getStringValue(null);
  }
}
origin: org.opencms/opencms-core

  /**
   * Writes a single item of detail page information to the XML content.<p>
   *
   * @param type the type which the detail page should render
   * @param id the page id of the detail page
   * @param index the position at which the detail page info should be added
   */
  private void writeValue(String type, CmsUUID id, int index) {

    Locale locale = CmsLocaleManager.getLocale("en");
    // todo: check actual locale.
    m_document.addValue(m_cms, N_DETAIL_PAGE, locale, index);
    String typePath = N_DETAIL_PAGE + "[" + (1 + index) + "]/" + N_TYPE;
    I_CmsXmlContentValue typeVal = m_document.getValue(typePath, locale);
    String pagePath = N_DETAIL_PAGE + "[" + (1 + index) + "]/" + N_PAGE;
    CmsXmlVfsFileValue pageVal = (CmsXmlVfsFileValue)m_document.getValue(pagePath, locale);
    typeVal.setStringValue(m_cms, type);
    pageVal.setIdValue(m_cms, id);
  }
}
origin: org.opencms/opencms-core

boolean matched = false;
String requestedLocale = m_settings.getLocale();
for (Locale locale : xmlContent.getLocales()) {
  if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(requestedLocale)
    && !locale.toString().equalsIgnoreCase(requestedLocale)) {
  List<String> paths = xmlContent.getNames(locale);
  for (String xpath : paths) {
    I_CmsXmlContentValue value = xmlContent.getValue(xpath, locale);
    if (value.isSimpleType()) {
      try {
  return xmlContent.marshal();
origin: org.opencms/org.opencms.workplace.tools.modules

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

/**
 * Returns the parameters of the collector with resolved macros.<p>
 * 
 * @return the parameters of the collector with resolved macros
 */
public String getParameter() {
  Locale locale = getRequestContext().getLocale();
  String params = m_content.getStringValue(getCmsObject(), NODE_PARAMETER, locale);
  List links = m_content.getValues(NODE_LINKS, locale);
  CmsMacroResolver macroResolver = CmsMacroResolver.newInstance();
  macroResolver.setKeepEmptyMacros(true);
  for (int i = 0; i < links.size(); i++) {
    I_CmsXmlContentValue xmlValue = (I_CmsXmlContentValue)links.get(i);
    String value = xmlValue.getStringValue(getCmsObject());
    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value)) {
      StringBuffer macro = new StringBuffer(10);
      macro.append(MACRO_LINK_PREFIX).append(i + 1);
      macroResolver.addMacro(macro.toString(), getRequestContext().removeSiteRoot(value));
    }
  }
  return macroResolver.resolveMacros(params);
}
origin: org.opencms/opencms-core

/** Returns a map with additional request parameters, mapping the parameter names to Solr query parts.
 * @return A map with additional request parameters, mapping the parameter names to Solr query parts.
 */
private Map<String, String> getAdditionalRequestParameters() {
  List<I_CmsXmlContentValue> parametersToParse = m_xml.getValues(XML_ELEMENT_ADDITIONAL_PARAMETERS, m_locale);
  Map<String, String> result = new HashMap<String, String>(parametersToParse.size());
  for (I_CmsXmlContentValue additionalParam : parametersToParse) {
    String param = m_xml.getValue(
      additionalParam.getPath() + "/" + XML_ELEMENT_ADDITIONAL_PARAMETERS_PARAM,
      m_locale).getStringValue(null);
    String solrQuery = m_xml.getValue(
      additionalParam.getPath() + "/" + XML_ELEMENT_ADDITIONAL_PARAMETERS_SOLRQUERY,
      m_locale).getStringValue(null);
    result.put(param, solrQuery);
  }
  return result;
}
origin: org.opencms/opencms-solr

/**
 * Reads the link exclude definition file and extracts all excluded links stored in it.<p>
 * 
 * @param cms the current CmsObject
 * @return list of Strings, containing link exclude paths
 */
private List readLinkExcludes(CmsObject cms) {
  List linkExcludes = new ArrayList();
  try {
    // get the link exclude file
    CmsResource res = cms.readResource(LINK_EXCLUDE_DEFINIFITON_FILE);
    CmsFile file = cms.readFile(res);
    CmsXmlContent linkExcludeDefinitions = CmsXmlContentFactory.unmarshal(cms, file);
    // get number of excludes
    int count = linkExcludeDefinitions.getIndexCount(XPATH_LINK, Locale.ENGLISH);
    for (int i = 1; i <= count; i++) {
      String exclude = linkExcludeDefinitions.getStringValue(cms, XPATH_LINK + "[" + i + "]", Locale.ENGLISH);
      linkExcludes.add(exclude);
    }
  } catch (CmsException e) {
    LOG.error(e);
  }
  return linkExcludes;
}
org.opencms.xml.contentCmsXmlContent

Javadoc

Implementation of a XML content object, used to access and manage structured content.

Use the org.opencms.xml.content.CmsXmlContentFactory to generate an instance of this class.

Most used methods

  • getValue
  • getStringValue
  • getValues
  • hasLocale
  • getFile
  • getLocales
  • 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.
  • addLocale,
  • copyLocale,
  • correctXmlStructure,
  • getEncoding,
  • getLocaleNode,
  • initDocument,
  • removeLocale,
  • setAutoCorrectionEnabled,
  • toString,
  • visitAllValuesWith

Popular in Java

  • Finding current android device location
  • getSystemService (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • compareTo (BigDecimal)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • Permission (java.security)
    Legacy security code; do not use.
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • BoxLayout (javax.swing)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • Best plugins for Eclipse
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