Returns the formatter configuration to the given element.<p>

@param element the element

@return the formatter configuration
177978
protected I_CmsFormatterBean getElementFormatter(CmsContainerElementBean element) {

        if (m_elementInstances == null) {
            initPageData();
        }
        I_CmsFormatterBean formatter = null;
        CmsContainerBean container = m_parentContainers.get(element.getInstanceId());
        if (container == null) {
            // use the current container
            container = getContainer();
        }
        if (container != null) {
            String containerName = container.getName();
            Map<String, String> settings = element.getSettings();
            if (settings != null) {
                String formatterConfigId = settings.get(CmsFormatterConfig.getSettingsKeyForContainer(containerName));
                if (CmsUUID.isValidUUID(formatterConfigId)) {
                    formatter = OpenCms.getADEManager().getCachedFormatters(false).getFormatters().get(
                        new CmsUUID(formatterConfigId));
                }
            }
            if (formatter == null) {
                try {
                    CmsResource resource = m_cms.readResource(m_cms.getRequestContext().getUri());

                    CmsADEConfigData config = OpenCms.getADEManager().lookupConfiguration(
                        m_cms,
                        resource.getRootPath());
                    CmsFormatterConfiguration formatters = config.getFormatters(m_cms, resource);
                    int width = -2;
                    try {
                        width = Integer.parseInt(container.getWidth());
                    } catch (Exception e) {
                        LOG.debug(e.getLocalizedMessage(), e);
                    }
                    formatter = formatters.getDefaultSchemaFormatter(container.getType(), width);
                } catch (CmsException e1) {
                    if (LOG.isWarnEnabled()) {
                        LOG.warn(e1.getLocalizedMessage(), e1);
                    }
                }
            }
        }
        return formatter;
    }
173266
private String getElementText(Element element) {
        Node node = element.getFirstChild();
        if (node == null || node.getNodeType() != Node.TEXT_NODE) {
            return null;
        }
        return node.getNodeValue().trim();
    }
127668
private static Element toDom(final org.jdom.Element element) {
        return toDom(element.getDocument()).getDocumentElement();
    }
190604
public static String getStringValue(final Element element) {
        final StringBuilder buf = new StringBuilder();
        final NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            final Node n = children.item(i);
            switch (n.getNodeType()) {
            case Node.TEXT_NODE:
                buf.append(n.getNodeValue());
                break;
            case Node.ELEMENT_NODE:
                buf.append(getStringValue((Element) n));
                break;
            }
        }
        return buf.toString();
    }
794983
private Element toElement(String xml) {
        DOMResult dom = new DOMResult();
        try {
            TransformerFactory.newInstance().newTransformer().transform(new StreamSource(new StringReader(xml)), dom);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ((Document) dom.getNode()).getDocumentElement();
    }
34532
public static String serialize(Element element) {
        Writer sw = new StringBuilderWriter();
        serialize(new DOMSource(element), sw);
        return sw.toString();
    }
579531
@SuppressWarnings("static-method")
	protected int getIssueAdornment(XtendMember element) {
		final ICompositeNode node = NodeModelUtils.getNode(element);
		if (node == null) {
			return 0;
		}
		// Error markers are more important than warning markers.
		// Order of checks:
		// - parser error (from the resource) or semantic error (from Diagnostician)
		// - parser warning or semantic warning
		final Resource resource = element.eResource();
		if (!resource.getURI().isArchive()) {
			if (hasParserIssue(node, resource.getErrors())) {
				return JavaElementImageDescriptor.ERROR;
			}
			final Diagnostic diagnostic = Diagnostician.INSTANCE.validate(element);
	        switch (diagnostic.getSeverity()) {
	        case Diagnostic.ERROR:
	        	return JavaElementImageDescriptor.ERROR;
	        case Diagnostic.WARNING:
	        	return JavaElementImageDescriptor.WARNING;
	        default:
	        }
			if (hasParserIssue(node, resource.getWarnings())) {
				return JavaElementImageDescriptor.WARNING;
			}
		}
		return 0;
	}
349676
private List<FormatterOption> getFormatterOptions(CmsObject cms, CmsResource resource) {

        List<FormatterOption> options = new ArrayList<FormatterOption>();
        Set<String> containerTypes = new HashSet<>();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(m_displayContainerTypeConfig)) {
            String types = null;

            if (CmsPropertyDefinition.PROPERTY_TEMPLATE_DISPLAY_TYPES.equals(m_displayContainerTypeConfig)) {
                try {
                    CmsProperty prop = cms.readPropertyObject(
                        resource,
                        CmsPropertyDefinition.PROPERTY_TEMPLATE_DISPLAY_TYPES,
                        true);
                    String propValue = prop.getValue();
                    if (!CmsStringUtil.isEmptyOrWhitespaceOnly(propValue)) {
                        types = propValue;
                    } else {
                        // look up template property
                        try {
                            CmsTemplateLoaderFacade loaderFacade = OpenCms.getResourceManager().getTemplateLoaderFacade(
                                cms,
                                null,
                                resource,
                                CmsPropertyDefinition.PROPERTY_TEMPLATE);
                            CmsResource template = loaderFacade.getLoaderStartResource();
                            if (template != null) {
                                prop = cms.readPropertyObject(
                                    template,
                                    CmsPropertyDefinition.PROPERTY_TEMPLATE_DISPLAY_TYPES,
                                    false);
                                propValue = prop.getValue();
                                if (!CmsStringUtil.isEmptyOrWhitespaceOnly(propValue)) {
                                    types = propValue;
                                }
                            }
                        } catch (Exception ex) {
                            LOG.debug(ex.getMessage(), ex);
                        }
                    }
                } catch (CmsException e) {
                    LOG.warn(e.getLocalizedMessage(), e);
                }
            } else {
                types = m_displayContainerTypeConfig;
            }
            if (types != null) {
                containerTypes.addAll(Arrays.asList(types.split(TYPES_SPLITTER)));
            }
        }
        CmsADEConfigData config = OpenCms.getADEManager().lookupConfiguration(cms, resource.getRootPath());

        if (config != null) {
            Locale wpLocale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
            for (I_CmsFormatterBean formatter : config.getDisplayFormatters(cms)) {
                if (!containerTypes.isEmpty()) {
                    if (Sets.intersection(containerTypes, formatter.getContainerTypes()).isEmpty()) {
                        continue;
                    }
                }
                for (String typeName : formatter.getResourceTypeNames()) {
                    String label = formatter.getNiceName(wpLocale)
                        + " ("
                        + CmsWorkplaceMessages.getResourceTypeName(wpLocale, typeName)
                        + ")";
                    options.add(
                        new FormatterOption(
                            typeName + CmsXmlDisplayFormatterValue.SEPARATOR + formatter.getId(),
                            typeName,
                            getDisplayType(formatter),
                            label,
                            formatter.getRank()));
                }
            }
        }
        Collections.sort(options, new FormatterComparator());
        return options;
    }
1103005
public Map<String, CmsXmlContentProperty> getSettingConfig(String containerName) {

        CmsFormatterConfig formatterConfig = getFormatterConfig(containerName);
        return formatterConfig != null
        ? formatterConfig.getSettingConfig()
        : Collections.<String, CmsXmlContentProperty> emptyMap();
    }
776402
public CmsFormatterConfig getFormatterConfig(String containerName) {

        CmsFormatterConfig formatterConfig = null;
        if (m_formatters != null) {
            String formatterId = getSettings().get(CmsFormatterConfig.getSettingsKeyForContainer(containerName));
            if ((formatterId != null)
                && getFormatters().containsKey(containerName)
                && getFormatters().get(containerName).containsKey(formatterId)) {
                // if the settings contain the formatter id, use the matching config
                formatterConfig = getFormatters().get(containerName).get(formatterId);
            } else if (getFormatters().containsKey(containerName) && !getFormatters().get(containerName).isEmpty()) {
                // otherwise use the first entry for the given container
                formatterConfig = getFormatters().get(containerName).values().iterator().next();
            }
        }
        return formatterConfig;
    }
958689
public static Map<String, String> toMap(Element element) {
        Map<String, String> rest = new HashMap<String, String>();
        List<Element> els = element.elements();
        for (Element el : els) {
            rest.put(el.getName().toLowerCase(), el.getTextTrim());
        }
        return rest;
    }
612571
void storeFormatterSelection(CmsContainerElementBean elementBean, Map<String, String> settings) {

        Entry<String, String> previousFormatterEntry = null;
        for (Entry<String, String> entry : elementBean.getIndividualSettings().entrySet()) {
            if (entry.getKey().startsWith(CmsFormatterConfig.FORMATTER_SETTINGS_KEY)) {
                previousFormatterEntry = entry;
                break;
            }
        }
        Entry<String, String> formatterEntry = null;
        for (Entry<String, String> entry : settings.entrySet()) {
            if (entry.getKey().startsWith(CmsFormatterConfig.FORMATTER_SETTINGS_KEY)) {
                formatterEntry = entry;
                break;
            }
        }
        if ((formatterEntry != null)
            && ((previousFormatterEntry == null)
                || !formatterEntry.getKey().equals(previousFormatterEntry.getKey())
                || !formatterEntry.getValue().equals(previousFormatterEntry.getValue()))) {
            String idString = formatterEntry.getValue();
            if (CmsUUID.isValidUUID(idString)) { // TODO: Make this work for schema formatters
                // the formatter setting has changed
                I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(elementBean.getResource());
                getSessionCache().addRecentFormatter(resType.getTypeName(), new CmsUUID(idString));
            }
        }
    }
283642
static
  public
  void configure (Element element) {
    DOMConfigurator configurator = new DOMConfigurator();
    configurator.doConfigure(element,  LogManager.getLoggerRepository());
  }
943743
public static String getValueFromElement(Element element, String tagName) {
        NodeList elementNodeList = element.getElementsByTagName(tagName);
        if (elementNodeList == null) {
            return "";
        } else {
            Element tagElement = (Element) elementNodeList.item(0);
            if (tagElement == null) {
                return "";
            }

            NodeList tagNodeList = tagElement.getChildNodes();
            if (tagNodeList == null || tagNodeList.getLength() == 0) {
                return "";
            }
            return tagNodeList.item(0).getNodeValue();
        }
    }
1296336
private Map<String, String> getContentsByContainerName(
        CmsContainerElementBean element,
        Collection<CmsContainer> containers) {

        CmsFormatterConfiguration configs = getFormatterConfiguration(element.getResource());
        Map<String, String> result = new HashMap<String, String>();
        for (CmsContainer container : containers) {
            String content = getContentByContainer(element, container, configs);
            if (content != null) {
                content = removeScriptTags(content);
            }
            result.put(container.getName(), content);
        }
        return result;
    }
817329
public static String getValue(Element element) {
        if (element != null) {
            Node dataNode = element.getFirstChild();
            if (dataNode != null) {
                return ((Text) dataNode).getData();
            }
        }
        return null;
    }
1232018
public T addElement(T element) {
		// make sure that elements are initialized
		getElements();
		if (!containsElement(this.elements, element)) {
			this.elements.add(element);
			element.addChangeListener(this.elementChangeListener);
			element.notifyState();
			return element;
		}
		throw new RuntimeException(element.toString() + " already exists");
	}