Example usage for org.dom4j Element elements

List of usage examples for org.dom4j Element elements

Introduction

In this page you can find the example usage for org.dom4j Element elements.

Prototype

List<Element> elements();

Source Link

Document

Returns the elements contained in this element.

Usage

From source file:com.google.jenkins.flakyTestHandler.junit.FlakyCaseResult.java

License:Open Source License

private static List<Element> getAllFlakyElements(Element testCase) {
    List<Element> flakyElements = new ArrayList<Element>();
    for (Object object : testCase.elements()) {
        Element element = (Element) object;
        if (element.getName().equals("flakyFailure") || element.getName().equals("flakyError")
                || element.getName().equals("rerunFailure") || element.getName().equals("rerunError")) {
            flakyElements.add(element);/*from   ww w  .j  ava 2 s. c  o m*/
        }
    }
    return flakyElements;
}

From source file:com.hand.hemp.push.server.xmpp.net.StanzaHandler.java

License:Open Source License

private void processIQ(Element doc) {
    log.debug("processIQ()...");
    IQ packet;//from  w w  w.ja v a  2  s .  co m
    try {
        packet = getIQ(doc);
    } catch (IllegalArgumentException e) {
        log.debug("Rejecting packet. JID malformed", e);
        IQ reply = new IQ();
        if (!doc.elements().isEmpty()) {
            reply.setChildElement(((Element) doc.elements().get(0)).createCopy());
        }
        reply.setID(doc.attributeValue("id"));
        reply.setTo(session.getAddress());
        String to = doc.attributeValue("to");
        if (to != null) {
            reply.getElement().addAttribute("from", to);
        }
        reply.setError(PacketError.Condition.jid_malformed);
        session.process(reply);
        return;
    }

    //        if (packet.getID() == null) {
    //            // IQ packets MUST have an 'id' attribute
    //            StreamError error = new StreamError(
    //                    StreamError.Condition.invalid_xml);
    //            session.deliverRawText(error.toXML());
    //            session.close();
    //            return;
    //        }
    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();
}

From source file:com.haulmont.bali.util.Dom4j.java

License:Apache License

@SuppressWarnings("unchecked")
public static List<Element> elements(Element element) {
    return element.elements();
}

From source file:com.haulmont.cuba.core.global.filter.FilterParser.java

License:Apache License

public FilterParser(Element element) {
    if (element.elements().isEmpty())
        throw new IllegalArgumentException("filter element is empty");
    Element rootElem = (Element) element.elements().get(0);
    root = createCondition(rootElem);/* www .j a  v  a  2 s  .co  m*/
    parse(rootElem, root.getConditions());
}

From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeLoaderImpl.java

License:Apache License

private void loadThemeFromXml(DesktopThemeImpl theme, Resource resource) throws IOException {
    log.info("Loading theme file " + resource.getURL());

    Document doc = readXmlDocument(resource);
    final Element rootElement = doc.getRootElement();

    for (Element element : (List<Element>) rootElement.elements()) {
        String elementName = element.getName();
        if ("lookAndFeel".equals(elementName)) {
            String lookAndFeel = element.getTextTrim();
            if (StringUtils.isNotEmpty(lookAndFeel)) {
                theme.setLookAndFeel(lookAndFeel);
            }//w  w w  .  j a  va2 s  .c o m
        } else if ("ui-defaults".equals(elementName)) {
            loadUIDefaults(theme.getUiDefaults(), element);
        } else if ("layout".equals(elementName)) {
            loadLayoutSettings(theme, element);
        } else if ("style".equals(elementName)) {
            DesktopStyle style = loadStyle(element);
            theme.addStyle(style);
        } else if ("include".equals(elementName)) {
            includeThemeFile(theme, element, resource);
        } else if ("class".equals(elementName)) {
            // ignore it
        } else {
            log.error("Unknown tag: " + elementName);
        }
    }
}

From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeLoaderImpl.java

License:Apache License

private DesktopStyle loadStyle(Element element) {
    final String componentsSubTag = "components";

    String styleName = element.attributeValue("name");

    List<Class> components = null;
    if (element.attributeValue("component") != null) {
        String className = element.attributeValue("component");
        try {//ww w .java 2s. c  o m
            components = Collections.singletonList((Class) Class.forName(className));
        } catch (ClassNotFoundException e) {
            log.error("Unknown component class: " + className);
        }
    } else {
        Element componentsElement = element.element(componentsSubTag);
        if (componentsElement != null) {
            String componentsStr = componentsElement.getTextTrim();
            StrTokenizer tokenizer = new StrTokenizer(componentsStr);
            components = new ArrayList<>();
            for (String className : tokenizer.getTokenArray()) {
                try {
                    components.add(Class.forName(className));
                } catch (ClassNotFoundException e) {
                    log.error("Unknown component class: " + className);
                }
            }
        }
    }

    List<ComponentDecorator> decorators = new ArrayList<>();
    for (Element childElement : (List<Element>) element.elements()) {
        if (!componentsSubTag.equals(childElement.getName())) {
            ComponentDecorator decorator = loadDecorator(childElement);
            if (decorator != null) {
                decorators.add(decorator);
            }
        }
    }

    return new DesktopStyle(styleName, decorators, components);
}

From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeLoaderImpl.java

License:Apache License

private Border loadBorder(Element element) {
    String type = element.attributeValue("type");
    if ("empty".equals(type)) {
        String value = element.attributeValue("margins");
        String[] values = value.split(" ");
        if (values.length != 4) {
            log.error("Border margins value should be like '0 0 0 0': " + value);
            return null;
        }/*from www. j a va 2s. c o m*/
        try {
            int top = Integer.parseInt(values[0]);
            int right = Integer.parseInt(values[1]);
            int bottom = Integer.parseInt(values[2]);
            int left = Integer.parseInt(values[3]);
            return BorderFactory.createEmptyBorder(top, left, bottom, right);
        } catch (NumberFormatException e) {
            log.error("Border margins value should be like '0 0 0 0': " + value);
        }
    } else if ("line".equals(type)) {
        String color = element.attributeValue("color");
        String width = element.attributeValue("width");
        Color borderColor = loadColorValue(color);
        if (borderColor == null) {
            log.error("Invalid line border color");
            return null;
        }
        if (width != null) {
            return BorderFactory.createLineBorder(borderColor, Integer.parseInt(width));
        } else {
            return BorderFactory.createLineBorder(borderColor);
        }
    } else if ("compound".equals(type)) {
        if (element.elements().size() < 2) {
            log.error("Compound border should have two child borders");
            return null;
        }
        final Element child1 = (Element) element.elements().get(0);
        final Element child2 = (Element) element.elements().get(1);
        if (!BORDER_TAG.equals(child1.getName()) || !BORDER_TAG.equals(child2.getName())) {
            log.error("Compound border should have two child borders");
            return null;
        }
        Border outsideBorder = loadBorder(child1);
        Border insideBorder = loadBorder(child2);
        if (outsideBorder == null || insideBorder == null) {
            return null;
        }
        return BorderFactory.createCompoundBorder(outsideBorder, insideBorder);
    } else {
        log.error("Unknown border type: " + type);
    }
    return null;
}

From source file:com.haulmont.cuba.desktop.theme.impl.DesktopThemeLoaderImpl.java

License:Apache License

private void loadUIDefaults(Map<String, Object> uiDefaults, Element rootElement) {
    for (Element element : (List<Element>) rootElement.elements()) {
        String propertyName = element.attributeValue("property");

        Object value = loadUIValue(element);
        if (value != null) {
            uiDefaults.put(propertyName, value);
        }//from www . j  a v  a2 s .c  om
    }
}

From source file:com.haulmont.cuba.gui.config.MenuConfig.java

License:Apache License

protected void loadMenuItems(Element parentElement, MenuItem parentItem) {
    //noinspection unchecked
    for (Element element : ((List<Element>) parentElement.elements())) {
        MenuItem menuItem = null;
        MenuItem currentParentItem = parentItem;
        MenuItem nextToItem = null;
        boolean before = true;
        String nextTo = element.attributeValue("insertBefore");
        if (StringUtils.isBlank(nextTo)) {
            before = false;//from ww w  . j a va2 s .co m
            nextTo = element.attributeValue("insertAfter");
        }
        if (!StringUtils.isBlank(nextTo)) {
            for (MenuItem rootItem : rootItems) {
                nextToItem = findItem(nextTo, rootItem);
                if (nextToItem != null) {
                    if (nextToItem.getParent() != null)
                        currentParentItem = nextToItem.getParent();
                    break;
                }
            }
        }

        if ("menu".equals(element.getName())) {
            String id = element.attributeValue("id");

            if (StringUtils.isBlank(id)) {
                log.warn("Invalid menu-config: 'id' attribute not defined");
            }

            menuItem = new MenuItem(currentParentItem, id);
            menuItem.setMenu(true);
            menuItem.setDescriptor(element);
            loadIcon(element, menuItem);
            loadShortcut(menuItem, element);
            loadStylename(element, menuItem);
            loadExpanded(element, menuItem);
            loadDescription(element, menuItem);
            loadMenuItems(element, menuItem);
        } else if ("item".equals(element.getName())) {
            menuItem = createMenuItem(element, currentParentItem);

            if (menuItem == null) {
                continue;
            }
        } else if ("separator".equals(element.getName())) {
            String id = element.attributeValue("id");
            if (StringUtils.isBlank(id))
                id = "-";
            menuItem = new MenuItem(currentParentItem, id);
            menuItem.setSeparator(true);
            if (!StringUtils.isBlank(id)) {
                menuItem.setDescriptor(element);
            }
        } else {
            log.warn(String.format("Unknown tag '%s' in menu-config", element.getName()));
        }

        if (currentParentItem != null) {
            addItem(currentParentItem.getChildren(), menuItem, nextToItem, before);
        } else {
            addItem(rootItems, menuItem, nextToItem, before);
        }
    }
}

From source file:com.haulmont.cuba.gui.model.impl.ScreenDataImpl.java

License:Apache License

@Override
public void load(Element element) {
    for (Element el : element.elements()) {
        if (el.getName().equals("collection")) {
            loadCollectionContainer(el);
        } else if (el.getName().equals("instance")) {
            loadInstanceContainer(el);/*from   w w  w  . j  a  v  a  2s .co m*/
        }
    }
}