Example usage for com.google.gwt.user.client Element getNodeType

List of usage examples for com.google.gwt.user.client Element getNodeType

Introduction

In this page you can find the example usage for com.google.gwt.user.client Element getNodeType.

Prototype

@Override
    public short getNodeType() 

Source Link

Usage

From source file:org.opencms.ade.containerpage.client.CmsContainerpageUtil.java

License:Open Source License

/**
 * Transforms all contained elements into {@link CmsContainerPageElementPanel}.<p>
 * //  ww  w.  j av a  2 s .c om
 * @param container the container
 */
public void consumeContainerElements(I_CmsDropContainer container) {

    // the drag element widgets are created from the existing DOM elements,
    Element child = (Element) container.getElement().getFirstChildElement();
    while (child != null) {
        boolean isContainerElement = CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_START_MARKER, child);
        boolean isGroupcontainerElement = CmsDomUtil.hasClass(CLASS_GROUP_CONTAINER_ELEMENT_MARKER, child);
        if (isContainerElement || isGroupcontainerElement) {
            String clientId = child.getAttribute("clientId");
            String sitePath = child.getAttribute("alt");
            String noEditReason = child.getAttribute("rel");
            String newType = child.getAttribute("newType");
            boolean hasProps = Boolean.parseBoolean(child.getAttribute("hasprops"));
            boolean hasViewPermission = Boolean.parseBoolean(child.getAttribute("hasviewpermission"));
            boolean releasedAndNotExpired = Boolean.parseBoolean(child.getAttribute("releasedandnotexpired"));
            if (isContainerElement) {
                // searching for content element root
                Element elementRoot = (Element) child.getNextSibling();
                while ((elementRoot != null) && (elementRoot.getNodeType() != Node.ELEMENT_NODE)) {
                    Element temp = elementRoot;
                    elementRoot = (Element) elementRoot.getNextSibling();
                    temp.removeFromParent();
                }
                if (elementRoot == null) {
                    child.removeFromParent();
                    child = null;
                    continue;
                }
                if (CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_START_MARKER, elementRoot)) {
                    // broken element, already at next start marker
                    child.removeFromParent();
                    child = elementRoot;
                    continue;
                }
                if (CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_END_MARKER, elementRoot)) {
                    // broken element, no content element root
                    child.removeFromParent();
                    child = (Element) elementRoot.getNextSiblingElement();
                    elementRoot.removeFromParent();
                    continue;
                } else {
                    // looking for the next marker that wraps the current element
                    Element endMarker = (Element) elementRoot.getNextSibling();
                    // only if the end marker node is not null and has neither the end-marker class or start-marker class
                    // remove the current node and check the next sibling 
                    while (!((endMarker == null) || ((endMarker.getNodeType() == Node.ELEMENT_NODE)
                            && (CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_END_MARKER, endMarker) || CmsDomUtil
                                    .hasClass(CLASS_CONTAINER_ELEMENT_START_MARKER, endMarker))))) {
                        Element temp = endMarker;
                        endMarker = (Element) endMarker.getNextSibling();
                        temp.removeFromParent();
                    }
                    if (endMarker == null) {
                        // broken element, end marker missing
                        elementRoot.removeFromParent();
                        child.removeFromParent();
                        child = null;
                        continue;
                    }
                    if (CmsDomUtil.hasClass(CLASS_CONTAINER_ELEMENT_START_MARKER, endMarker)) {
                        // broken element, end marker missing
                        elementRoot.removeFromParent();
                        child.removeFromParent();
                        child = endMarker;
                    }
                    CmsDomUtil.removeScriptTags(elementRoot);
                    CmsContainerPageElementPanel containerElement = createElement(elementRoot, container,
                            clientId, sitePath, noEditReason, hasProps, hasViewPermission,
                            releasedAndNotExpired);
                    if ((newType != null) && (newType.length() > 0)) {
                        containerElement.setNewType(newType);
                    }
                    container.adoptElement(containerElement);
                    child.removeFromParent();
                    child = (Element) endMarker.getNextSiblingElement(); //   (Element)container.getElement().getFirstChildElement();
                    endMarker.removeFromParent();

                }
            } else if (isGroupcontainerElement && (container instanceof CmsContainerPageContainer)) {
                CmsDomUtil.removeScriptTags(child);
                CmsGroupContainerElementPanel groupContainer = createGroupcontainer(child, container, clientId,
                        sitePath, noEditReason, hasProps, hasViewPermission, releasedAndNotExpired);
                groupContainer.setContainerId(container.getContainerId());
                container.adoptElement(groupContainer);
                consumeContainerElements(groupContainer);
                if (groupContainer.getWidgetCount() == 0) {
                    groupContainer
                            .addStyleName(I_CmsLayoutBundle.INSTANCE.containerpageCss().emptyGroupContainer());
                }
                // important: adding the option-bar only after the group-containers have been consumed 
                addOptionBar(groupContainer);
                child = (Element) child.getNextSiblingElement();
            }
        } else {
            Element sibling = (Element) child.getNextSiblingElement();
            DOM.removeChild((Element) container.getElement(), child);
            child = sibling;
            continue;
        }
    }
}