<p><b>Used for finding element process (to generate xpath address)</b></p>

@param container parent containing element.
@param <T>       the element which calls this method
@return this element
502047
@SuppressWarnings("unchecked")
    public <T extends XPathBuilder> T setContainer(WebLocator container) {
        this.container = container;
        return (T) this;
    }
416207
public Element getElementAtLevel(int level) {
        checkArgument(level >= 0);
        if (level > element.level) return null;
        if (level < element.level) return parent.getElementAtLevel(level);
        return element;
    }
644115
public boolean nextInnerElement(ElementContext parent) throws XMLException, IOException {
		if (event.context.isEmpty()) return false;
		if (Type.START_ELEMENT.equals(event.type) && event.context.getFirst() == parent && event.isClosed)
			return false; // we are one the opening tag of the parent, and it is closed, so it has no content
		if (Type.END_ELEMENT.equals(event.type) && event.context.getFirst() == parent)
			return false;
		try {
			do {
				next();
				if (Type.END_ELEMENT.equals(event.type)) {
					if (event.context.getFirst() == parent)
						return false;
				}
				if (Type.START_ELEMENT.equals(event.type)) {
					if (event.context.size() > 1 && event.context.get(1) == parent)
						return true;
				}
			} while (true);
		} catch (EOFException e) {
			return false;
		}
	}
627280
public AnnotationMetadata getAnnotationMetadata(Element parent, Element element) {
        return newAnnotationBuilder().buildForParent(parent, element);
    }
350268
private CmsResource getContainerpage(CmsObject cms) throws CmsException {

        String currentUri = cms.getRequestContext().getUri();
        CmsResource containerPage = cms.readResource(currentUri);
        if (!CmsResourceTypeXmlContainerPage.isContainerPage(containerPage)) {
            // container page is used as template
            String cntPagePath = cms.readPropertyObject(
                containerPage,
                CmsPropertyDefinition.PROPERTY_TEMPLATE_ELEMENTS,
                true).getValue("");
            try {
                containerPage = cms.readResource(cntPagePath);
            } catch (CmsException e) {
                if (!LOG.isDebugEnabled()) {
                    LOG.warn(e.getLocalizedMessage());
                }
                LOG.debug(e.getLocalizedMessage(), e);
            }
        }
        return containerPage;
    }
502518
public Map<String, List<CmsJspResourceWrapper>> getElementsInContainer() {

        return CmsCollectionsGenericWrapper.createLazyMap(obj -> {
            if (obj instanceof String) {
                List<CmsJspResourceWrapper> elements = new ArrayList<>();
                CmsContainerBean container = getPage().getContainers().get(obj);
                if (container != null) {
                    for (CmsContainerElementBean element : container.getElements()) {
                        try {
                            element.initResource(m_cms);
                            elements.add(CmsJspResourceWrapper.wrap(m_cms, element.getResource()));
                        } catch (Exception e) {
                            LOG.error(e.getLocalizedMessage(), e);
                        }
                    }
                }
                return elements;
            } else {
                return null;
            }
        });

    }
1099982
public CmsContainerElementData getElementData(
        CmsResource page,
        CmsContainerElementBean element,
        Collection<CmsContainer> containers)
    throws CmsException {

        Locale requestLocale = m_cms.getRequestContext().getLocale();
        m_cms.getRequestContext().setLocale(m_locale);
        element.initResource(m_cms);
        if (element.getResource().isFolder()) {
            return null;
        }
        CmsContainerElementData elementData = getBaseElementData(page, element);
        CmsFormatterConfiguration formatterConfiguraton = getFormatterConfiguration(element.getResource());
        Map<String, String> contents = new HashMap<String, String>();
        if (element.isGroupContainer(m_cms)) {
            Map<String, CmsContainer> containersByName = new HashMap<String, CmsContainer>();
            for (CmsContainer container : containers) {
                containersByName.put(container.getName(), container);
            }
            CmsXmlGroupContainer xmlGroupContainer = CmsXmlGroupContainerFactory.unmarshal(
                m_cms,
                element.getResource(),
                m_req);
            CmsGroupContainerBean groupContainer = xmlGroupContainer.getGroupContainer(m_cms);
            // make sure to use the content title and not the property title
            elementData.setTitle(groupContainer.getTitle());
            elementData.setTypes(groupContainer.getTypes());
            elementData.setDescription(groupContainer.getDescription());
            if (groupContainer.getTypes().isEmpty()) {
                if (groupContainer.getElements().isEmpty()) {
                    String emptySub = "<div>NEW AND EMPTY</div>";
                    for (CmsContainer cont : containersByName.values()) {
                        if (formatterConfiguraton.hasFormatter(cont.getType(), cont.getWidth())) {
                            contents.put(cont.getName(), emptySub);
                        }
                    }
                } else {
                    // TODO: throw appropriate exception
                    return null;
                }
            } else {

                // add formatter and content entries for the supported types
                for (CmsContainer cnt : containersByName.values()) {

                    String type = cnt.getType();
                    if (checkGroupAllowed(type, groupContainer)) {
                        contents.put(cnt.getName(), "<div>should not be used</div>");
                    }
                }
            }
            // add subitems
            List<String> subItems = new ArrayList<String>();

            for (CmsContainerElementBean subElement : groupContainer.getElements()) {
                // collect ids
                subItems.add(subElement.editorHash());
            }
            elementData.setSubItems(subItems);
        } else if (element.isInheritedContainer(m_cms)) {
            CmsInheritanceReferenceParser parser = new CmsInheritanceReferenceParser(m_cms);
            parser.parse(element.getResource());
            CmsInheritanceReference ref = parser.getReference(m_locale);
            String name = null;
            // check for new inheritance reference
            if (ref != null) {
                name = ref.getName();
                elementData.setDescription(ref.getDescription());
                elementData.setTitle(ref.getTitle());
            }
            for (CmsContainer container : containers) {
                if (formatterConfiguraton.hasFormatter(container.getType(), container.getWidth())) {
                    contents.put(container.getName(), "<div>should not be used</div>");
                }
            }

            List<CmsInheritanceInfo> inheritanceInfos = new ArrayList<CmsInheritanceInfo>();
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(name)) {
                CmsInheritedContainerState result = OpenCms.getADEManager().getInheritedContainerState(
                    m_cms,
                    m_cms.addSiteRoot(m_currentPageUri),
                    name);
                for (CmsContainerElementBean subElement : result.getElements(true)) {
                    CmsInheritanceInfo inheritanceInfo = subElement.getInheritanceInfo();
                    inheritanceInfo.setClientId(subElement.editorHash());
                    inheritanceInfos.add(inheritanceInfo);
                }
            } else {
                // setting a new id for name, will be persisted once the inheritance reference is edited and saved.
                // use the structure id so it will always be the same for the resource
                name = element.getResource().getStructureId().toString();
            }
            elementData.setInheritanceInfos(inheritanceInfos);
            elementData.setInheritanceName(name);
        } else {

            for (CmsContainer cnt : containers) {
                boolean missesFormatterSetting = !elementData.getSettings().containsKey(
                    CmsFormatterConfig.getSettingsKeyForContainer(cnt.getName()));
                if (missesFormatterSetting) {
                    if (element.getFormatterId() == null) {
                        I_CmsFormatterBean formatter = getStartFormatter(
                            m_cms,
                            cnt,
                            m_adeConfig,
                            element,
                            CmsADESessionCache.getCache(m_req, m_cms));
                        if (formatter != null) {
                            elementData.getSettings().put(
                                CmsFormatterConfig.getSettingsKeyForContainer(cnt.getName()),
                                formatter.getId());
                            element.addFormatterSetting(cnt.getName(), formatter.getId());
                        }
                    } else {
                        Map<String, I_CmsFormatterBean> formatterSelection = formatterConfiguraton.getFormatterSelection(
                            cnt.getType(),
                            cnt.getWidth());
                        for (Entry<String, I_CmsFormatterBean> formatterEntry : formatterSelection.entrySet()) {
                            I_CmsFormatterBean formatter = formatterEntry.getValue();
                            String id = formatterEntry.getKey();
                            if (element.getFormatterId().equals(formatter.getJspStructureId())) {
                                elementData.getSettings().put(
                                    CmsFormatterConfig.getSettingsKeyForContainer(cnt.getName()),
                                    id);
                                break;
                            }
                        }
                    }
                }
            }
            // get the formatter configuration
            Map<String, String> contentsByName = getContentsByContainerName(element, containers);
            contents = contentsByName;
        }
        elementData.setContents(contents);
        m_cms.getRequestContext().setLocale(requestLocale);
        return elementData;
    }
1222892
static final String xpath(Element element) {
        StringBuilder sb = new StringBuilder();

        Node iterator = element;
        while (iterator.getNodeType() == Node.ELEMENT_NODE) {
            sb.insert(0, "]");
            sb.insert(0, siblingIndex((Element) iterator) + 1);
            sb.insert(0, "[");
            sb.insert(0, ((Element) iterator).getTagName());
            sb.insert(0, "/");

            iterator = iterator.getParentNode();
        }

        return sb.toString();
    }
362570
public static TreeMember getTreeMember(final EntityContainer container) {
	// Must be identifiable to be a tree member
	if (!(container instanceof Identifiable)) {
	    return null;
	}
	// Entity with no identifable parent (or JALSE).
	if (!(container instanceof Entity) || ((Entity) container).getContainer() == null) {
	    return TreeMember.ROOT;
	}
	// Entity with children
	else if (container.hasEntities()) {
	    return TreeMember.NODE;
	}
	// Entity with no children
	else {
	    return TreeMember.LEAF;
	}
    }
1053653
<T extends Component> List<T> getFormRowChildren(AbstractComponentContainer container, final Class<T> cls) {

        final List<T> result = Lists.newArrayList();
        CmsVaadinUtils.visitDescendants(container, new Predicate<Component>() {

            public boolean apply(Component comp) {

                if (cls.isAssignableFrom(comp.getClass())) {
                    result.add(cls.cast(comp));
                }
                return true;
            }
        });
        return result;
    }
34641
@SuppressWarnings("unchecked")
    public <T extends ElementBase> T findChildElement(Class<T> clazz) {
        for (ElementBase child : getChildren()) {
            if (clazz.isInstance(child)) {
                return (T) child;
            }
        }
        
        for (ElementBase child : getChildren()) {
            T child2 = child.findChildElement(clazz);
            
            if (child2 != null) {
                return child2;
            }
        }
        
        return null;
    }
410683
public static Iterator<Element> iterator(Element parent) {
        return parent != null ? new ChildrenIterator(parent) : Collections.<Element>emptyList().iterator();
    }
1201300
protected CmsContainerElementBean transformContainerElement(
        CmsObject cms,
        CmsTemplateMapperConfiguration config,
        CmsContainerElementBean element) {

        if (m_forSave) {
            try {
                element.initResource(cms);
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
                return null;
            }
        }
        Map<String, String> settings = element.getIndividualSettings();
        if (settings == null) {
            settings = new HashMap<>();
        }
        Map<String, String> newSettings = new HashMap<>();
        for (Map.Entry<String, String> entry : settings.entrySet()) {
            String key = entry.getKey();
            if (CmsTemplateContextInfo.SETTING.equals(key)) {
                continue;
            }
            String value = entry.getValue();
            if (value == null) {
                continue;
            }
            String newValue = value;
            if (key.startsWith(CmsFormatterConfig.FORMATTER_SETTINGS_KEY)) {
                if (CmsUUID.isValidUUID(value)) {
                    String newId = config.getMappedFormatterConfiguration(value);
                    if (newId != null) {
                        newValue = newId;
                    }
                } else if (value.startsWith(CmsFormatterConfig.SCHEMA_FORMATTER_ID)) {
                    String schemaFormatterIdStr = value.substring(CmsFormatterConfig.SCHEMA_FORMATTER_ID.length());
                    if (CmsUUID.isValidUUID(schemaFormatterIdStr)) {
                        CmsUUID schemaFormatterId = new CmsUUID(schemaFormatterIdStr);
                        CmsUUID mappedFormatterId = config.getMappedFormatterJspId(schemaFormatterId);
                        if (mappedFormatterId != null) {
                            newValue = CmsFormatterConfig.SCHEMA_FORMATTER_ID + mappedFormatterId;
                        }
                    }
                }
            }
            newSettings.put(key, newValue);
        }
        CmsContainerElementBean newElement = element.clone();
        newElement.updateIndividualSettings(newSettings);
        CmsUUID formatterId = element.getFormatterId();
        if ((formatterId == null) && m_forSave) {
            try {
                if (element.isGroupContainer(cms)) {
                    // ID for group-container.jsp
                    formatterId = new CmsUUID("e7029fa2-761e-11e0-bd7f-9ffeadaf4d46");
                    newElement.setFormatterId(formatterId);
                } else if (OpenCms.getResourceManager().matchResourceType(
                    "function",
                    element.getResource().getTypeId())) {
                    formatterId = new CmsUUID("087ba7c9-e7fc-4336-acb8-d3416a4eb1fd");
                    newElement.setFormatterId(formatterId);
                }
            } catch (CmsException e) {
                LOG.warn(e.getLocalizedMessage(), e);
            }
        }
        CmsUUID mappedFormatterJspId = config.getMappedFormatterJspId(formatterId);
        if (mappedFormatterJspId != null) {
            newElement.setFormatterId(mappedFormatterJspId);
        }
        return newElement;
    }
879950
public Element toElement(final HadoopClusterInformation hadoopClusterInformation) {
        final Element hadoopClusterElement = getDocument().createElement("hadoop-cluster");

        hadoopClusterElement.setAttribute("name", hadoopClusterInformation.getName());

        final String description = hadoopClusterInformation.getDescription();
        if (!Strings.isNullOrEmpty(description)) {
            hadoopClusterElement.setAttribute("description", description);
        }

        // These inherit each other, so order is important
        if (hadoopClusterInformation instanceof DirectConnectionHadoopClusterInformation) {
            appendElement(hadoopClusterElement, "namenode-url",
                    ((DirectConnectionHadoopClusterInformation) hadoopClusterInformation).getNameNodeUri().toString());
        } else if (hadoopClusterInformation instanceof EnvironmentBasedHadoopClusterInformation) {
            appendElement(hadoopClusterElement, "environment-configured", "");
        } else if (hadoopClusterInformation instanceof DirectoryBasedHadoopClusterInformation) {
            final DirectoryBasedHadoopClusterInformation directoryBasedHadoopClusterInformation =
                    (DirectoryBasedHadoopClusterInformation) hadoopClusterInformation;
            final Element directoriesElement = getDocument().createElement("directories");
            hadoopClusterElement.appendChild(directoriesElement);
            for (final String directory : directoryBasedHadoopClusterInformation.getDirectories()) {
                appendElement(directoriesElement, "directory", directory);
            }
        } else {
            throw new UnsupportedOperationException("Unknown Hadoop cluster configuration");
        }

        return hadoopClusterElement;
    }
166074
public static EntityContainer getRootContainer(final EntityContainer container) {
	Objects.requireNonNull(container);

	if (container instanceof Entity) {
	    final EntityContainer parent = ((Entity) container).getContainer();
	    if (parent != null) {
		return getRootContainer(parent);
	    }
	}
	return container;
    }
662133
public static Element getChildElementByName(Element parent, String name)
    {
        NodeList children = parent.getChildNodes();

        for(int i = 0; i < children.getLength(); i++) {
            Node node = children.item(i);
            if(node.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) node;
                if(element.getTagName().equals(name)) {
                    return element;
                }
            }
        }

        return null;
    }
1135379
public TypeElement findParent(TypeElement typeElement, Set<TypeElement> parents) {
    TypeMirror type;
    while (true) {
      type = typeElement.getSuperclass();
      if (type.getKind() == TypeKind.NONE) {
        return null;
      }
      typeElement = (TypeElement) ((DeclaredType) type).asElement();
      if (containsTypeMirror(parents, type)) {
        return typeElement;
      }
    }
  }