Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

In this page you can find the example usage for org.jdom2 Element getChildren.

Prototype

public List<Element> getChildren() 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element, as Element objects.

Usage

From source file:com.locutus.outils.graphes.ConvertisseurXGMLGraphe.java

License:Open Source License

/**
 * /*from  w  w w.ja v  a2  s .  c  o  m*/
 * @param dgc
 * @param local2
 */
private void createEdge(DiGraph<String> dgc, Element local2) {
    Iterator<Element> it3 = local2.getChildren().iterator();
    int[] arcId = new int[2];

    while (it3.hasNext()) {

        Element local3 = it3.next();

        if (local3.getAttribute("key") != null && local3.getAttribute("key").getValue().equals("source"))
            arcId[0] = Integer.parseInt(local3.getText());
        else if (local3.getAttribute("key") != null && local3.getAttribute("key").getValue().equals("target"))
            arcId[1] = Integer.parseInt(local3.getText());

    }
    edges.add(arcId);
}

From source file:com.ohnosequences.xml.model.Iteration.java

License:Open Source License

public ArrayList<Hit> getIterationHits() throws XMLElementException {
    ArrayList<Hit> array = new ArrayList<Hit>();

    Element itHits = root.getChild(ITERATION_HITS_TAG_NAME);
    if (itHits != null) {
        List<Element> tempList = itHits.getChildren();
        for (Element elem : tempList) {
            array.add(new Hit(elem));
        }// w  ww. ja v a2 s .  c  o  m
    }

    return array;

}

From source file:com.rhythm.louie.email.MailProperties.java

License:Apache License

public static void processProperties(Element email) {
    for (Element prop : email.getChildren()) {
        String propName = prop.getName().toLowerCase();
        if (null != propName) {
            switch (propName) {
            case JNDI:
                jndi = prop.getText().trim();
                break;
            case CUSTOM:
                for (Element customProp : prop.getChildren()) {
                    props.put(customProp.getName(), customProp.getTextTrim());
                }/* w  w  w .  j ava2  s.  com*/
                break;
            default:
                LoggerFactory.getLogger(MailProperties.class).warn("Unknown Mail Element:{}", propName);
                break;

            }
        }
    }
}

From source file:com.rhythm.louie.jms.MessagingProperties.java

License:Apache License

public static void processMessaging(Element messaging) {
    for (Element prop : messaging.getChildren()) {
        String propName = prop.getName().toLowerCase();
        if (null != propName) {
            switch (propName) {
            case JMSADAPTER:
                adapterClass = prop.getAttributeValue(CLASS, getAdapterClass());
                host = prop.getAttributeValue(JmsAdapter.HOST_KEY, getHost());
                port = prop.getAttributeValue(JmsAdapter.PORT_KEY, getPort());
                failover = prop.getAttributeValue(JmsAdapter.FAILOVER_KEY, getFailover());
                break;
            case SERVER:
                serverPrefix = prop.getAttributeValue(PREFIX, getServerPrefix());
                serverType = prop.getAttributeValue(TYPE, getServerType());
                break;
            case CLIENT:
                clientPrefix = prop.getAttributeValue(PREFIX, getClientPrefix());
                clientType = prop.getAttributeValue(TYPE, getClientType());
                break;
            case UPDATE:
                updatePrefix = prop.getAttributeValue(PREFIX, getUpdatePrefix());
                updateType = prop.getAttributeValue(TYPE, getUpdateType());
                break;
            case CUSTOM:
                for (Element customProp : prop.getChildren()) {
                    String customName = customProp.getName().toLowerCase();
                    CustomProperty custom = new CustomProperty(customName);
                    for (Element child : customProp.getChildren()) {
                        custom.setProperty(child.getName(), child.getText().trim());
                    }/*  w w  w.jav  a2s  .  com*/
                    customProperties.put(customName, custom);
                }
                break;
            default:
                LoggerFactory.getLogger(MessagingProperties.class).warn("Unknown Message Property:{}",
                        propName);
                break;
            }
        }
    }
}

From source file:com.rhythm.louie.server.AccessManager.java

License:Apache License

protected static void loadGroups(Element groups) {
    for (Element group : groups.getChildren()) {
        String name = group.getAttributeValue(GROUP_NAME).toLowerCase();
        if (ADMIN.equals(name)) {
            adminUsers.clear(); //to allow re-loading from a default set by a specific louie.xml impl
            wild = false;/*from w  ww  .j  a va 2s.  co  m*/
            for (Element user : group.getChildren()) {
                String u = user.getTextTrim();
                if (WILDCARD.equals(u)) {
                    wild = true;
                    break;
                }
                adminUsers.add(user.getTextTrim());
            }
        } else {
            Set<String> users = new HashSet<>();
            for (Element user : group.getChildren()) {
                users.add(user.getTextTrim());
            }
            groupUsers.put(name, users);
        }
    }
}

From source file:com.rhythm.louie.server.AccessManager.java

License:Apache License

/**
 * Requires loadGroups has already been executed!
 * @param service//from  w w w. j  av  a 2 s. c  o  m
 * @param serviceGroup 
 */
protected static void loadServiceAccess(String service, Element serviceGroup) {
    Set<String> superset = new HashSet<>();
    for (Element child : serviceGroup.getChildren()) {
        String group = child.getTextTrim().toLowerCase();
        Set<String> users = groupUsers.get(group);
        if (users != null) {
            superset.addAll(users);
        }
    }
    serviceUsers.put(service, superset);
}

From source file:com.rhythm.louie.server.AlertProperties.java

License:Apache License

public static void processProperties(Element alerts) {
    for (Element child : alerts.getChildren()) {
        String alert = child.getName();
        AlertProperties prop = new AlertProperties();
        properties.put(alert, prop);//from w w  w.  j  a va  2s  .  com
        for (Element grandchild : child.getChildren()) {
            String propName = grandchild.getName();
            String value = grandchild.getTextTrim();
            switch (propName) {
            case EMAIL:
                prop.setEmail(value);
                break;
            case REQUEST_DURATION:
                prop.setDuration(Long.parseLong(value));
                break;
            case MONITOR_CYCLE:
                prop.setMonitorPollCycle(Integer.parseInt(value));
                break;
            case SUMMARY_HOUR:
                prop.setSummaryHour(Integer.parseInt(value));
                break;
            case PERCENTAGE:
                int capture = Integer.parseInt(value);
                double adjusted = (double) capture / 100;
                prop.setPercentThreshold(adjusted);
                break;
            default:
                LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected alert property  {}", propName);
                break;
            }
        }
    }
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

public static void processProperties(URL configs, String contextGateway) throws Exception {
    loadInternals(); //this code organization is weird but it's from iterations of design

    if (contextGateway != null) {
        //Overrides a default set by internal properties
        Server.setDefaultGateway(contextGateway);
    }/* ww  w. j  a v a  2s .  c o  m*/

    Document properties = loadDocument(configs);
    if (properties == null) {
        return;
    }

    Element louie = properties.getRootElement();

    //Check for alternate loading point 
    boolean resetRoot = false;
    for (Element elem : louie.getChildren()) {
        if (ALT_PATH.equalsIgnoreCase(elem.getName())) {
            String altPath = elem.getTextTrim();
            LoggerFactory.getLogger(LouieProperties.class).info("Loading Louie configs from alternate file: {}",
                    altPath);
            //overwrite document with values from alternate config 
            properties = loadDocument(new File(altPath).toURI().toURL());
            if (properties == null)
                return;
            resetRoot = true;
        }
    }
    if (resetRoot) {
        //reset root to new properties obj root
        louie = properties.getRootElement();
    }

    Element groups = louie.getChild(GROUPS);
    if (groups != null) {
        AccessManager.loadGroups(groups);
    }

    boolean serversConfigured = false;
    for (Element elem : louie.getChildren()) {
        String elemName = elem.getName().toLowerCase();

        if (null != elemName)
            switch (elemName) {
            case ALT_PATH:
                LoggerFactory.getLogger(LouieProperties.class)
                        .warn("Extra config_path alternate loading point specified. "
                                + "Only one file-switch can be performed.\n"
                                + "  Please verify what is specified in the embedded xml file.\n"
                                + "  Found: {}", elem.getText());
                break;
            case SERVER_PARENT:
                processServers(elem);
                serversConfigured = true;
                break;
            case SERVICE_PARENT:
                processServices(elem, false);
                break;
            case MESSAGING:
                MessagingProperties.processMessaging(elem);
                break;
            case MAIL:
                MailProperties.processProperties(elem);
                break;
            case SCHEDULER:
                TaskSchedulerProperties.processProperties(elem);
                break;
            case ALERTS:
                AlertProperties.processProperties(elem);
                break;
            case CUSTOM:
                processCustomProperties(elem);
                break;
            case GROUPS:
                break;
            default:
                LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected top level property  {}",
                        elemName);
                break;
            }
    }
    if (!serversConfigured)
        processServers(null); //ugly bootstrapping workflow
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static void processServers(Element servers) {
    List<Server> serverList = new ArrayList<>();

    if (servers == null) {
        List<Server> empty = Collections.emptyList();
        Server.processServers(empty);/*from   www  .  j a  v a  2 s.  c  om*/
        return;
    }

    for (Element server : servers.getChildren()) {
        if (!SERVER.equals(server.getName().toLowerCase()))
            continue;

        String name = null;
        for (Attribute attr : server.getAttributes()) {
            if (NAME.equals(attr.getName().toLowerCase()))
                name = attr.getValue();
        }
        if (name == null) {
            LoggerFactory.getLogger(LouieProperties.class)
                    .error("A server was missing it's 'name' attribute and will be skipped!");
            continue;
        }
        Server prop = new Server(name);

        for (Element serverProp : server.getChildren()) {
            String propName = serverProp.getName().toLowerCase();
            String propValue = serverProp.getTextTrim();
            if (null != propName)
                switch (propName) {
                case HOST:
                    prop.setHost(propValue);
                    break;
                case DISPLAY:
                    prop.setDisplay(propValue);
                    break;
                case LOCATION:
                    prop.setLocation(propValue);
                    break;
                case GATEWAY:
                    prop.setGateway(propValue);
                    break;
                case IP:
                    prop.setIp(propValue);
                    break;
                case EXTERNAL_IP:
                    prop.setExternalIp(propValue);
                    break;
                case CENTRAL_AUTH:
                    prop.setCentralAuth(Boolean.parseBoolean(propValue));
                    break;
                case PORT:
                    prop.setPort(Integer.parseInt(propValue));
                    break;
                case SECURE:
                    prop.setSecure(Boolean.parseBoolean(propValue));
                    break;
                case TIMEZONE:
                    prop.setTimezone(propValue);
                    break;
                case CUSTOM:
                    for (Element child : serverProp.getChildren()) {
                        prop.addCustomProperty(child.getName(), child.getTextTrim());
                    }
                    break;
                default:
                    LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected server property  {}:{}",
                            propName, propValue);
                    break;
                }
        }
        serverList.add(prop);
    }
    Server.processServers(serverList);
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static void processServiceDefaults(Element defaults) {
    for (Element defaultProp : defaults.getChildren()) {
        String propName = defaultProp.getName().toLowerCase();
        String propValue = defaultProp.getTextTrim();
        if (null != propName)
            switch (propName) {
            case CACHING:
                ServiceProperties.setDefaultCaching(Boolean.parseBoolean(propValue));
                break;
            case ENABLE:
                ServiceProperties.setDefaultEnable(Boolean.parseBoolean(propValue));
                break;
            case REMOTE_SERVER:
                ServiceProperties.setDefaultRemoteServer(propValue);
                break;
            case READ_ONLY:
                ServiceProperties.setDefaultReadOnly(Boolean.parseBoolean(propValue));
                break;
            default:
                LoggerFactory.getLogger(LouieProperties.class)
                        .warn("Unexpected default service config key {}:{}", propName, propValue);
                break;
            }/*w  ww .ja v a  2s.c  om*/
    }
}