Processes a single field definition.<p>

@param elem the parent element
@param contentDef the content definition

@throws CmsXmlException if something goes wrong
540579
protected void initField(Element elem, CmsXmlContentDefinition contentDef) throws CmsXmlException {

        String nameVal = elem.elementText(CmsConfigurationReader.N_PROPERTY_NAME);
        if (nameVal == null) {
            throw new CmsXmlException(Messages.get().container(Messages.ERR_XMLCONTENT_BAD_FIELD_NAME_1, nameVal));
        }
        final String name = nameVal.trim();

        String ruleRegex = elem.elementText(CmsConfigurationReader.N_RULE_REGEX);
        String ruleType = elem.elementText(CmsConfigurationReader.N_RULE_TYPE);
        String error = elem.elementText(CmsConfigurationReader.N_ERROR);
        if (error == null) {
            error = "";
        }
        if (!CmsStringUtil.isEmptyOrWhitespaceOnly(ruleRegex)) {
            addValidationRule(contentDef, name, ruleRegex, error, "warning".equalsIgnoreCase(ruleType));
        }

        String defaultValue = elem.elementText(CmsConfigurationReader.N_DEFAULT);
        String defaultResolveMacros = elem.elementTextTrim(FieldSettingElems.DefaultResolveMacros.name());
        if (!CmsStringUtil.isEmptyOrWhitespaceOnly(defaultValue)) {
            addDefault(contentDef, name, defaultValue, defaultResolveMacros);
        }

        String widget = elem.elementText(CmsConfigurationReader.N_WIDGET);
        String widgetConfig = elem.elementText(CmsConfigurationReader.N_WIDGET_CONFIG);
        if (widget != null) {
            addWidget(contentDef, name, widget);
        }
        if (widgetConfig != null) {
            widgetConfig = widgetConfig.trim();
            addConfiguration(contentDef, name, widgetConfig);
        }

        String niceName = elem.elementText(CmsConfigurationReader.N_DISPLAY_NAME);
        if (niceName != null) {
            m_fieldNiceNames.put(name, niceName);
        }
        String description = elem.elementText(CmsConfigurationReader.N_DESCRIPTION);
        if (description != null) {
            m_fieldDescriptions.put(name, description);
        }
        for (Element mappingElem : elem.elements(FieldSettingElems.Mapping.name())) {
            String mapTo = mappingElem.elementText(FieldSettingElems.MapTo.name());
            String useDefault = mappingElem.elementText(FieldSettingElems.UseDefault.name());
            if (mapTo != null) {
                addMapping(contentDef, name, mapTo, useDefault);
            }
        }
        String display = elem.elementTextTrim(FieldSettingElems.Display.name());
        if (!CmsStringUtil.isEmptyOrWhitespaceOnly(display)) {
            try {
                addDisplayType(contentDef, name, DisplayType.valueOf(display));
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
            }
        }
        String synchronization = elem.elementTextTrim(FieldSettingElems.Synchronization.name());
        if (Boolean.parseBoolean(synchronization)) {
            m_synchronizations.add(name);
        }
        for (Element relElem : elem.elements(FieldSettingElems.Relation.name())) {
            String type = relElem.elementTextTrim(FieldSettingElems.Type.name());
            String invalidate = relElem.elementTextTrim(FieldSettingElems.Invalidate.name());
            if (type != null) {
                type = type.toLowerCase();
            }
            if (invalidate != null) {
                invalidate = invalidate.toLowerCase();
            }
            addCheckRule(contentDef, name, invalidate, type);
        }

        for (Element visElem : elem.elements(FieldSettingElems.Visibility.name())) {
            String params = visElem.getText();
            VisibilityConfiguration visConfig = createVisibilityConfiguration(null, params);
            m_visibilityConfigurations.put(name, visConfig);
        }

        for (Element visElem : elem.elements(FieldSettingElems.FieldVisibility.name())) {
            String className = visElem.elementTextTrim(FieldSettingElems.Class.name());
            String params = visElem.elementTextTrim(FieldSettingElems.Params.name());
            VisibilityConfiguration visConfig = createVisibilityConfiguration(className, params);
            m_visibilityConfigurations.put(name, visConfig);
        }

        String nestedFormatter = elem.elementTextTrim(FieldSettingElems.NestedFormatter.name());
        if (Boolean.parseBoolean(nestedFormatter)) {
            m_nestedFormatterElements.add(name);
        }

        String search = elem.elementTextTrim(FieldSettingElems.Search.name());
        if (search != null) {
            addSimpleSearchSetting(contentDef, name, search);
        }
    }
169971
private void initXmlBundle() throws CmsException {

        CmsFile file = m_cms.readFile(m_resource);
        m_bundleFiles.put(null, m_resource);
        m_xmlBundle = CmsXmlContentFactory.unmarshal(m_cms, file);
        initKeySetForXmlBundle();

    }
428989
@Override
    protected void initContent() {

        if (CmsStringUtil.isNotEmpty(getParamContent())) {
            if (CmsStringUtil.isNotEmpty(getParamElementname())
                && getParamElementname().equals(getParamOldelementname())) {
                if (CmsStringUtil.isNotEmpty(getParamElementlanguage())
                    && getParamElementlanguage().equals(getParamOldelementlanguage())) {
                    return;
                }
            }
        }
        getCms().getRequestContext().setAttribute(CmsRequestContext.ATTRIBUTE_EDITOR, Boolean.TRUE);

        String elementData;
        if (m_page.hasValue(getParamElementname(), getElementLocale())) {
            // element value is available in the page
            elementData = m_page.getStringValue(getCms(), getParamElementname(), getElementLocale());
        } else {
            // value is not available in the page
            if (Boolean.valueOf(getParamDirectedit()).booleanValue()) {
                // direct edit on a non-existing element: create new element with this name
                m_page.addValue(getParamElementname(), getElementLocale());
            }
            elementData = "";
        }
        setParamContent(elementData);
    }
1356827
public static CmsXmlContentDefinition getContentDefinitionForResource(CmsObject cms, CmsResource resource)
    throws CmsException {

        CmsXmlContentDefinition contentDef = null;
        I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(resource.getTypeId());
        String schema = resType.getConfiguration().get(CmsResourceTypeXmlContent.CONFIGURATION_SCHEMA);
        if (schema != null) {
            try {
                // this wont in most cases read the file content because of caching
                contentDef = unmarshal(cms, schema);
            } catch (CmsException e) {
                // this should never happen, unless the configured schema is different than the schema in the XML
                if (!LOG.isDebugEnabled()) {
                    LOG.warn(e);
                }
                LOG.debug(e.getLocalizedMessage(), e);
            }
        }
        if (contentDef == null) {
            // could still be empty since it is not mandatory to configure the resource type in the XML configuration
            // try through the XSD relation
            List<CmsRelation> relations = cms.getRelationsForResource(
                resource,
                CmsRelationFilter.TARGETS.filterType(CmsRelationType.XSD));
            if ((relations != null) && !relations.isEmpty()) {
                CmsXmlEntityResolver entityResolver = new CmsXmlEntityResolver(cms);
                String xsd = cms.getSitePath(relations.get(0).getTarget(cms, CmsResourceFilter.ALL));
                contentDef = entityResolver.getCachedContentDefinition(xsd);
            }
        }
        if (contentDef == null) {
            // could still be empty if the XML content has been saved with an OpenCms before 8.0.0
            // so, to unmarshal is the only possibility left
            CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, cms.readFile(resource));
            contentDef = content.getContentDefinition();
        }

        return contentDef;
    }
117789
function( elem, context, xml ) {
			var data, cache, outerCache,
				dirkey = dirruns + " " + doneName;

			// We can't set arbitrary data on XML nodes, so they don't benefit from dir caching
			if ( xml ) {
				while ( (elem = elem[ dir ]) ) {
					if ( elem.nodeType === 1 || checkNonElements ) {
						if ( matcher( elem, context, xml ) ) {
							return true;
						}
					}
				}
			} else {
				while ( (elem = elem[ dir ]) ) {
					if ( elem.nodeType === 1 || checkNonElements ) {
						outerCache = elem[ expando ] || (elem[ expando ] = {});
						if ( (cache = outerCache[ dir ]) && cache[0] === dirkey ) {
							if ( (data = cache[1]) === true || data === cachedruns ) {
								return data === true;
							}
						} else {
							cache = outerCache[ dir ] = [ dirkey ];
							cache[1] = matcher( elem, context, xml ) || cachedruns;
							if ( cache[1] === true ) {
								return true;
							}
						}
					}
				}
			}
		}
1076321
public void registerContentDefinition(CmsContentDefinition definition) {

        getWidgetService().addConfigurations(definition.getConfigurations());
        CmsType baseType = definition.getTypes().get(definition.getEntityTypeName());
        m_entityBackend.registerTypes(baseType, definition.getTypes());
        for (CmsEntity entity : definition.getEntities().values()) {
            CmsEntity previousValue = m_entityBackend.getEntity(entity.getId());
            if (previousValue != null) {
                m_entityBackend.changeEntityContentValues(previousValue, entity);
            } else {
                m_entityBackend.registerEntity(entity);
                m_registeredEntities.add(entity.getId());
            }
        }
        for (Map.Entry<String, CmsComplexWidgetData> entry : definition.getComplexWidgetData().entrySet()) {
            String attrName = entry.getKey();
            CmsComplexWidgetData widgetData = entry.getValue();
            getWidgetService().registerComplexWidgetAttribute(
                attrName,
                widgetData.getRendererName(),
                widgetData.getConfiguration());
        }
    }
224785
protected void deleteContentValue(CmsXmlContent content, Locale locale, String path) {

        boolean hasValue = content.hasValue(path, locale);
        if (hasValue) {
            int index = CmsXmlUtils.getXpathIndexInt(path) - 1;
            I_CmsXmlContentValue val = content.getValue(path, locale);
            if (index >= val.getMinOccurs()) {
                content.removeValue(path, locale, index);
            } else {
                val.setStringValue(m_cms, "");
            }
        }
    }
115657
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);

    }
1138190
public static void doParse(Element element, BeanDefinitionBuilder builder) {
        Element descriptionElement = DomUtils.getChildElementByTagName(element, "description");
        if (descriptionElement != null) {
            builder.addPropertyValue("description", DomUtils.getTextValue(descriptionElement).trim());
        }
    }
625246
private byte[] replaceInXml(CmsFile cmsFile) throws Exception {

        Exception e = null;
        CmsXmlContent xmlContent = CmsXmlContentFactory.unmarshal(getCms(), cmsFile);
        Pattern pattern = Pattern.compile(m_settings.getSearchpattern());
        // loop over the locales of the content
        boolean modified = false;
        boolean matched = false;
        String requestedLocale = m_settings.getLocale();
        for (Locale locale : xmlContent.getLocales()) {
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(requestedLocale)
                && !locale.toString().equalsIgnoreCase(requestedLocale)) {
                // does not match the requested locale, skip it
                continue;
            }
            // loop over the available element paths of the current content locale
            List<String> paths = xmlContent.getNames(locale);
            for (String xpath : paths) {
                // try to get the value extraction for the current element path
                I_CmsXmlContentValue value = xmlContent.getValue(xpath, locale);
                if (value.isSimpleType()) {
                    try {
                        String currPath = value.getPath();
                        if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_settings.getXpath())
                            || currPath.equals(m_settings.getXpath())
                            || (CmsXmlUtils.removeXpath(currPath).equals(m_settings.getXpath()))) {
                            // xpath match
                            String oldVal = value.getStringValue(getCms());
                            Matcher matcher = pattern.matcher(oldVal);
                            matcher = Pattern.compile(m_settings.getSearchpattern()).matcher(oldVal);
                            if (matcher.find()) {
                                matched = true;
                                m_matchedResources.add(cmsFile);
                                if (m_replace) {
                                    String newVal = matcher.replaceAll(m_settings.getReplacepattern());
                                    if (!oldVal.equals(newVal)) {
                                        value.setStringValue(getCms(), newVal);
                                        modified = true;
                                    }
                                }
                            }
                        }
                    } catch (Exception ex) {
                        // log and go on
                        LOG.error(ex.getMessage(), ex);
                        e = ex;
                    }
                }
            }
        }
        if (e != null) {
            throw e;
        }
        if (matched) {
            getReport().println(Messages.get().container(Messages.RPT_SOURCESEARCH_MATCHED_0), I_CmsReport.FORMAT_OK);
        } else {
            getReport().println(
                Messages.get().container(Messages.RPT_SOURCESEARCH_NOT_MATCHED_0),
                I_CmsReport.FORMAT_NOTE);
        }
        if (modified) {
            return xmlContent.marshal();
        }
        return null;
    }
460950
protected void initSettings(Element root, CmsXmlContentDefinition contentDefinition) {

        Iterator<Element> itProperties = CmsXmlGenericWrapper.elementIterator(root, APPINFO_SETTING);
        while (itProperties.hasNext()) {
            Element element = itProperties.next();
            CmsXmlContentProperty setting = new CmsXmlContentProperty(
                element.attributeValue(APPINFO_ATTR_NAME),
                element.attributeValue(APPINFO_ATTR_TYPE),
                element.attributeValue(APPINFO_ATTR_WIDGET),
                element.attributeValue(APPINFO_ATTR_WIDGET_CONFIG),
                element.attributeValue(APPINFO_ATTR_RULE_REGEX),
                element.attributeValue(APPINFO_ATTR_RULE_TYPE),
                element.attributeValue(APPINFO_ATTR_DEFAULT),
                element.attributeValue(APPINFO_ATTR_NICE_NAME),
                element.attributeValue(APPINFO_ATTR_DESCRIPTION),
                element.attributeValue(APPINFO_ATTR_ERROR),
                element.attributeValue(APPINFO_ATTR_PREFERFOLDER));
            String name = setting.getName();
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(name)) {
                m_settings.put(name, setting);
            }
        }
    }
1127252
@Deprecated
    protected void addSearchField(CmsXmlContentDefinition contentDefinition, CmsSearchField field) {

        addSearchField(contentDefinition, field, I_CmsXmlContentHandler.MappingType.ELEMENT);
    }
1049023
public void actionDeleteElementLocale() throws JspException {

        try {
            Locale loc = getElementLocale();
            m_content.removeLocale(loc);
            //write the modified xml content
            writeContent();
            List<Locale> locales = m_content.getLocales();
            if (locales.size() > 0) {
                // set first locale as new display locale
                Locale newLoc = locales.get(0);
                setParamElementlanguage(newLoc.toString());
                m_elementLocale = newLoc;
            } else {
                if (LOG.isErrorEnabled()) {
                    LOG.error(Messages.get().getBundle().key(Messages.LOG_GET_LOCALES_1, getParamResource()));
                }
            }

        } catch (CmsXmlException e) {
            // an error occurred while trying to delete the locale, stop action
            showErrorPage(e);
        } catch (CmsException e) {
            // should usually never happen
            if (LOG.isInfoEnabled()) {
                LOG.info(e.getLocalizedMessage(), e);
            }
        }
    }
242131
public static void removeFromParent(Element elem) {
    if(elem != null && elem.getParentNode() != null) {
      elem.getParentNode().removeChild(elem);
    }
  }
43539
private void parseElementDecl() throws Exception {
        String name;

        requireWhitespace();
        // Read the element type name.
        name = readNmtoken(true);

        requireWhitespace();
        // Read the content model.
        parseContentspec(name);

        skipWhitespace();
        require('>');
    }
1373209
public CmsXmlContentErrorHandler validateContent(Map<String, String> contentValues) throws CmsUgcException {

        checkNotFinished();
        try {
            CmsFile file = m_cms.readFile(m_editResource);
            CmsXmlContent content = addContentValues(file, contentValues);
            return content.validate(m_cms);
        } catch (CmsException e) {
            LOG.error(e.getLocalizedMessage(), e);
            throw new CmsUgcException(e, CmsUgcConstants.ErrorCode.errMisc, e.getLocalizedMessage());
        }
    }
963297
void addContentDefinition(CmsContentDefinition definition) {

        m_definitions.put(definition.getLocale(), definition);
        m_contentLocales.add(definition.getLocale());
    }