Example usage for org.dom4j Node getName

List of usage examples for org.dom4j Node getName

Introduction

In this page you can find the example usage for org.dom4j Node getName.

Prototype

String getName();

Source Link

Document

getName returns the name of this node.

Usage

From source file:fr.cph.stock.language.Language.java

License:Apache License

/**
 * Get the language map/*from   w w w  .  j a v a 2 s.c o  m*/
 *
 * @return a map
 */
public final Map<String, String> getLanguage() {
    Node menuNode = xml.getNode(BASE + MENU);
    @SuppressWarnings("unchecked")
    List<Node> menuNodes = (List<Node>) xml.getListNode(BASE + MENU);
    for (Node node : menuNodes) {
        String name = node.valueOf("@name");
        map.put(menuNode.getName().toUpperCase() + "_" + name.toUpperCase(), node.getStringValue());
    }
    Node node = xml.getNode(BASE + PORTFOLIO);
    List<String> nodes = new ArrayList<>();
    Node node2;
    nodes.add(BASE + PORTFOLIO + "/title");
    nodes.add(BASE + PORTFOLIO + "/review/liquidity");
    nodes.add(BASE + PORTFOLIO + "/review/yieldYear");
    nodes.add(BASE + PORTFOLIO + "/review/shareValue");
    nodes.add(BASE + PORTFOLIO + "/add");
    nodes.add(BASE + PORTFOLIO + "/equities/company");
    nodes.add(BASE + PORTFOLIO + "/equities/quantity");
    nodes.add(BASE + PORTFOLIO + "/equities/unitCostPrice");
    nodes.add(BASE + PORTFOLIO + "/equities/quote");
    nodes.add(BASE + PORTFOLIO + "/equities/currency");
    nodes.add(BASE + PORTFOLIO + "/equities/parities");
    nodes.add(BASE + PORTFOLIO + "/equities/value");
    nodes.add(BASE + PORTFOLIO + "/equities/percentTotal");
    nodes.add(BASE + PORTFOLIO + "/equities/yieldTtm");
    nodes.add(BASE + PORTFOLIO + "/equities/yieldPerUnitCostPrice");
    nodes.add(BASE + PORTFOLIO + "/equities/valueGained");
    nodes.add(BASE + PORTFOLIO + "/equities/stopLoss");
    nodes.add(BASE + PORTFOLIO + "/equities/objective");
    nodes.add(BASE + PORTFOLIO + "/equities/info");
    nodes.add(BASE + PORTFOLIO + "/equities/info");
    nodes.add(BASE + PORTFOLIO + "/equities/modify");
    nodes.add(BASE + PORTFOLIO + "/chartTitle");
    nodes.add(BASE + PORTFOLIO + "/chartTitleValue");
    nodes.add(BASE + PORTFOLIO + "/chart/all");
    nodes.add(BASE + PORTFOLIO + "/chart/fiveYears");
    nodes.add(BASE + PORTFOLIO + "/chart/twoYears");
    nodes.add(BASE + PORTFOLIO + "/chart/oneYear");
    nodes.add(BASE + PORTFOLIO + "/chart/sixMonths");
    nodes.add(BASE + PORTFOLIO + "/chart/threeMonths");
    nodes.add(BASE + PORTFOLIO + "/chart/oneMonth");
    nodes.add(BASE + PORTFOLIO + "/chart/oneWeek");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + CONSTANT);
    nodes = new ArrayList<>();
    nodes.add(BASE + CONSTANT + "/added");
    nodes.add(BASE + CONSTANT + "/updated");
    nodes.add(BASE + CONSTANT + "/modified");
    nodes.add(BASE + CONSTANT + "/deleted");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + PORTFOLIO_HIDDEN);
    nodes = new ArrayList<>();
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/refresh");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/add");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/updateCurrencies");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/yahooId");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/quantity");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/unitCostPrice");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/modifyEquity");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeName");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeName");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeSector");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeIndustry");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/customizeMarketCap");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/defautParity");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/personalParity");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/yahooYield");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/personalYield");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/stopLoss");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/objective");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/modify");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/or");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/delete");
    nodes.add(BASE + PORTFOLIO_HIDDEN + "/deleteConfirm");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + HISTORY);
    nodes = new ArrayList<>();
    nodes.add(BASE + HISTORY + "/title");
    nodes.add(BASE + HISTORY + "/update");
    nodes.add(BASE + HISTORY + "/date");
    nodes.add(BASE + HISTORY + "/account");
    nodes.add(BASE + HISTORY + "/liquidityMovement");
    nodes.add(BASE + HISTORY + "/dividends");
    nodes.add(BASE + HISTORY + "/buy");
    nodes.add(BASE + HISTORY + "/sell");
    nodes.add(BASE + HISTORY + "/taxe");
    nodes.add(BASE + HISTORY + "/portfolioValue");
    nodes.add(BASE + HISTORY + "/shareQuantity");
    nodes.add(BASE + HISTORY + "/shareValue");
    nodes.add(BASE + HISTORY + "/monthlyYield");
    nodes.add(BASE + HISTORY + "/commentary");
    nodes.add(BASE + HISTORY + "/option");
    nodes.add(BASE + HISTORY + "/details");
    nodes.add(BASE + HISTORY + "/all");
    nodes.add(BASE + HISTORY + "/delete");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + HISTORY_HIDDEN);
    nodes = new ArrayList<>();
    nodes.add(BASE + HISTORY_HIDDEN + "/refresh");
    nodes.add(BASE + HISTORY_HIDDEN + "/account");
    nodes.add(BASE + HISTORY_HIDDEN + "/movement");
    nodes.add(BASE + HISTORY_HIDDEN + "/yield");
    nodes.add(BASE + HISTORY_HIDDEN + "/buy");
    nodes.add(BASE + HISTORY_HIDDEN + "/sell");
    nodes.add(BASE + HISTORY_HIDDEN + "/taxe");
    nodes.add(BASE + HISTORY_HIDDEN + "/commentary");
    nodes.add(BASE + HISTORY_HIDDEN + "/update");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + ACCOUNTS);
    nodes = new ArrayList<>();
    nodes.add(BASE + ACCOUNTS + "/title");
    nodes.add(BASE + ACCOUNTS + "/add");
    nodes.add(BASE + ACCOUNTS + "/account");
    nodes.add(BASE + ACCOUNTS + "/currency");
    nodes.add(BASE + ACCOUNTS + "/liquidity");
    nodes.add(BASE + ACCOUNTS + "/parity");
    nodes.add(BASE + ACCOUNTS + "/value");
    nodes.add(BASE + ACCOUNTS + "/option");
    nodes.add(BASE + ACCOUNTS + "/modify");
    nodes.add(BASE + ACCOUNTS + "/total");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + ACCOUNTS_HIDDEN);
    nodes = new ArrayList<>();
    nodes.add(BASE + ACCOUNTS_HIDDEN + "/add");
    nodes.add(BASE + ACCOUNTS_HIDDEN + "/accountName");
    nodes.add(BASE + ACCOUNTS_HIDDEN + "/currency");
    nodes.add(BASE + ACCOUNTS_HIDDEN + "/liquidity");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + LIST);
    nodes = new ArrayList<>();
    nodes.add(BASE + LIST + "/title");
    nodes.add(BASE + LIST + "/add");
    nodes.add(BASE + LIST + "/date");
    nodes.add(BASE + LIST + "/company");
    nodes.add(BASE + LIST + "/quote");
    nodes.add(BASE + LIST + "/lowMaxYear");
    nodes.add(BASE + LIST + "/yield");
    nodes.add(BASE + LIST + "/lowerLimit");
    nodes.add(BASE + LIST + "/higherLimit");
    nodes.add(BASE + LIST + "/info");
    nodes.add(BASE + LIST + "/modify");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + LIST_HIDDEN);
    nodes = new ArrayList<>();
    nodes.add(BASE + LIST_HIDDEN + "/refresh");
    nodes.add(BASE + LIST_HIDDEN + "/confirm");
    nodes.add(BASE + LIST_HIDDEN + "/add");
    nodes.add(BASE + LIST_HIDDEN + "/yahooId");
    nodes.add(BASE + LIST_HIDDEN + "/lowerLimit");
    nodes.add(BASE + LIST_HIDDEN + "/higherLimit");
    nodes.add(BASE + LIST_HIDDEN + "/modify");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + CHARTS);
    nodes = new ArrayList<>();
    nodes.add(BASE + CHARTS + "/title");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + CURRENCIES);
    nodes = new ArrayList<>();
    nodes.add(BASE + CURRENCIES + "/title");
    nodes.add(BASE + CURRENCIES + "/portfolioCurrency");
    nodes.add(BASE + CURRENCIES + "/currency");
    nodes.add(BASE + CURRENCIES + "/lastUpdate");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + CURRENCIES_HIDDEN);
    nodes = new ArrayList<>();
    nodes.add(BASE + CURRENCIES_HIDDEN + "/refresh");
    nodes.add(BASE + CURRENCIES_HIDDEN + "/confirm");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + OPTIONS);
    nodes = new ArrayList<>();
    nodes.add(BASE + OPTIONS + "/title");
    nodes.add(BASE + OPTIONS + "/defautCurrency");
    nodes.add(BASE + OPTIONS + "/format");
    nodes.add(BASE + OPTIONS + "/timeZone");
    nodes.add(BASE + OPTIONS + "/datePattern");
    nodes.add(BASE + OPTIONS + "/portfolioColumn");
    nodes.add(BASE + OPTIONS + "/loadHistory");
    nodes.add(BASE + OPTIONS + "/liquidity");
    nodes.add(BASE + OPTIONS + "/account");
    nodes.add(BASE + OPTIONS + "/load");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    node = xml.getNode(BASE + OPTIONS_HIDDEN);
    nodes = new ArrayList<>();
    nodes.add(BASE + OPTIONS_HIDDEN + "/currency");
    nodes.add(BASE + OPTIONS_HIDDEN + "/format");
    nodes.add(BASE + OPTIONS_HIDDEN + "/timeZone");
    nodes.add(BASE + OPTIONS_HIDDEN + "/datePattern");
    nodes.add(BASE + OPTIONS_HIDDEN + "/columns");
    nodes.add(BASE + OPTIONS_HIDDEN + "/quote");
    nodes.add(BASE + OPTIONS_HIDDEN + "/parities");
    nodes.add(BASE + OPTIONS_HIDDEN + "/yieldTTM");
    nodes.add(BASE + OPTIONS_HIDDEN + "/yieldPerUnitCostPrice");
    nodes.add(BASE + OPTIONS_HIDDEN + "/stopLoss");
    nodes.add(BASE + OPTIONS_HIDDEN + "/objective");
    for (String n : nodes) {
        node2 = xml.getNode(n);
        addToMap(map, node, node2);
    }
    return map;
}

From source file:fr.cph.stock.language.Language.java

License:Apache License

/**
 * Add the informations to the result map
 *
 * @param m    the result map/*from   w  w  w .  java2 s .c o m*/
 * @param base the node base
 * @param node the node
 */
protected final void addToMap(final Map<String, String> m, final Node base, final Node node) {
    m.put(base.getName().toUpperCase() + "_" + node.getName().toUpperCase(), node.getStringValue());
}

From source file:gov.nih.nci.caarray.upgrade.SingleConnectionHibernateHelper.java

License:BSD License

/**
 * @param connection/*from  w ww.j  a  v  a2s .c  o  m*/
 */
public void initialize(Connection connection) {
    HibernateSingleConnectionProvider.setConnection(connection);

    InputStream configurationStream = FixIlluminaGenotypingCsvDesignProbeNamesMigrator.class
            .getResourceAsStream("/hibernate.cfg.xml");
    SAXReader reader = new SAXReader();
    reader.setEntityResolver(new org.hibernate.util.DTDEntityResolver());
    Document configurationDocument = null;
    try {
        configurationDocument = reader.read(configurationStream);
    } catch (DocumentException e) {
        throw new UnhandledException(e);
    }
    Node sessionFactoryNode = configurationDocument
            .selectSingleNode("/hibernate-configuration/session-factory");

    Iterator<?> iter = ((Branch) sessionFactoryNode).nodeIterator();
    while (iter.hasNext()) {
        Node currentNode = (Node) iter.next();
        if (currentNode.getNodeType() == Node.ELEMENT_NODE && !currentNode.getName().equals("mapping")) {
            iter.remove();
        }
    }

    DOMWriter domWriter = new DOMWriter();
    org.w3c.dom.Document document = null;
    try {
        document = domWriter.write(configurationDocument);
    } catch (DocumentException e) {
        throw new UnhandledException(e);
    }

    configuration = new AnnotationConfiguration();
    configuration.setProperty(Environment.CONNECTION_PROVIDER,
            "gov.nih.nci.caarray.upgrade.HibernateSingleConnectionProvider");

    configuration.configure(document);

    configuration.setProperty(Environment.TRANSACTION_STRATEGY,
            "org.hibernate.transaction.JDBCTransactionFactory");
    configuration.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
    configuration.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
    configuration.getProperties().remove(Environment.TRANSACTION_MANAGER_STRATEGY);
    configuration.setNamingStrategy(new NamingStrategy());

    sessionFactory = configuration.buildSessionFactory();
}

From source file:hk.hku.cecid.piazza.commons.util.PropertyTree.java

License:Open Source License

/**
 * Creates a Properties object which stores the properties retrieved by the specified xpath.
 * /* ww w.j a v a2  s .  c  o  m*/
 * @param xpath the properties xpath.
 * @return a Properties object which stores the retrieved properties.
 * @see hk.hku.cecid.piazza.commons.util.PropertySheet#createProperties(java.lang.String)
 */
public Properties createProperties(String xpath) {
    Properties newProps = new Properties();
    List nodes = getPropertyNodes(xpath);

    for (int i = 0; i < nodes.size(); i++) {
        Node node = (Node) nodes.get(i);

        String key = node.getName();
        int prefixIndex = key.indexOf(':');
        if (prefixIndex != -1) {
            key = key.substring(prefixIndex + 1);
        }

        String tmpkey = ((Element) node).attributeValue("name");
        String tmpvalue = ((Element) node).attributeValue("value");
        String tmptype = ((Element) node).attributeValue("type");
        String value = node.getStringValue();
        if (tmpkey != null) {
            key = tmpkey.trim();
        }
        if (tmpvalue != null) {
            value = tmpvalue;
        }
        if (tmptype != null) {
            String type = tmptype.trim();
            if (!"".equals(type)) {
                key = type + ":" + key;
            }
        }

        if (value != null) {
            newProps.setProperty(key, value);
        }
    }
    return newProps;
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static HashMap<String, Point> graphicalInfoFrom(Document document) {
    HashMap<String, Point> graphicalInfoMap = new HashMap<String, Point>();
    try {/*from w w w  .  j  a va  2 s  .c  o  m*/
        SAXReader reader = new SAXReader();
        Pattern p = Pattern.compile("\\s*<workflow>.*</workflow>\\s*", Pattern.DOTALL);

        @SuppressWarnings("unchecked")
        Iterator<Node> iter = document.nodeIterator();
        while (iter.hasNext()) {

            Node xmlNode = iter.next();
            if (xmlNode.getNodeType() == Node.COMMENT_NODE) {

                String graphicalInfo = xmlNode.getText();
                if (p.matcher(graphicalInfo).find()) {

                    Element graphicalElement = reader.read(new StringReader(graphicalInfo)).getRootElement();
                    @SuppressWarnings("unchecked")
                    Iterator<Node> gIter = graphicalElement.nodeIterator();

                    while (gIter.hasNext()) {
                        Node gNode = gIter.next();
                        if (gNode.getName() != null && gNode.getName().equals("node")) {
                            graphicalInfoMap.put(gNode.valueOf("@name"),
                                    new Point(Integer.parseInt(gNode.valueOf("@x")),
                                            Integer.parseInt(gNode.valueOf("@y"))));
                        }
                    }
                    break;

                }

            }

        }
    } catch (DocumentException ex) {
        ex.printStackTrace();
    }
    return graphicalInfoMap;
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static Node schemaVersionParentNode(Node node) {
    Node[] parentNode = new Node[1];
    node.accept(new VisitorSupport() {
        @Override//from  w  w  w. ja  va 2s. c o  m
        public void visit(Attribute node) {
            if (node.getName().equalsIgnoreCase(XMLUtils.SCHEMA_VERSION_TAG)) {
                parentNode[0] = node.getParent();
            }
        }
    });
    return parentNode[0];
}

From source file:io.mashin.oep.hpdl.XMLReadUtils.java

License:Open Source License

public static List<Node> nodesList(Element rootElement) {
    List<Node> list = new ArrayList<Node>();
    @SuppressWarnings("unchecked")
    Iterator<Node> iter = rootElement.nodeIterator();
    while (iter.hasNext()) {
        Node node = iter.next();
        if (node.getNodeType() == Node.ELEMENT_NODE && node.getName() != null && !node.getName().isEmpty()) {
            switch (node.getName()) {
            case "start":
            case "end":
            case "decision":
            case "fork":
            case "join":
            case "kill":
            case "action":
                list.add(node);/* ww w .j  a  va2 s .  co m*/
            }
        }
    }
    return list;
}

From source file:neat.NEAT.java

License:Open Source License

@Override
public NEAT loadFromXML(Node nd) {
    // Add properties
    loadProperties();// w w w.  jav  a 2s. co  m

    // set generator
    generator = new NESRandom(FrevoMain.getSeed());

    this.input_number = Integer.parseInt(nd.valueOf("./@input_nodes"));
    this.output_number = Integer.parseInt(nd.valueOf("./@output_nodes"));

    this.recurrent = Boolean.parseBoolean(nd.valueOf("./@recurrent"));

    String fitnessString = nd.valueOf("./@fitness");
    if (!fitnessString.isEmpty()) {
        this.setFitness(Double.parseDouble(fitnessString));
    }

    // load genes
    ArrayList<NEATGene> genes = new ArrayList<NEATGene>();
    Node dgenes = nd.selectSingleNode("./genes");

    @SuppressWarnings("unchecked")
    List<? extends Node> gs = dgenes.selectNodes("./*");
    Iterator<? extends Node> it = gs.iterator();

    while (it.hasNext()) {
        Node n = it.next();
        String name = n.getName();

        if (name.equals("NEATlinkGene"))
            genes.add(new NEATLinkGene(n));
        else if (name.equals("NEATNodeGene"))
            genes.add(new NEATNodeGene(n));
        else
            genes.add(new NEATFeatureGene(n));
    }

    this.chromosome = new NEATChromosome(genes);

    updateNetStructure();

    return this;
}

From source file:net.indigital.util.Properties.java

License:Open Source License

public static List<Mapping> configure(String configFileLocation) {
    Document document = getDocument(configFileLocation);
    List<Node> mappingNodes = selectNodes(document, mapping);

    Integer pauseMySQLReconnections; //ms
    Integer pauseCassandraReconnections; //ms
    Integer refresh; //ms
    Integer elementsAtOnce; //num elements

    String mysqlHost;// ww  w  .j a va2 s  . c o m
    Integer mysqlPort;
    String user;
    String pass;
    String db;
    String table;
    String numericKeyStr;
    String cassHost;
    Integer cassPort;
    String keysType;
    Boolean truncateDataBase;

    /* Common to all the mappings. This structure will allow the threads
    *  to know which Cassandra keyspace has already been tried to be removed. */
    Lock lock = new ReentrantLock();
    Map<String, Boolean> keyspaces = new HashMap<String, Boolean>();

    /* All the fields to be mapped. */
    List<Map<String, String>> maps;
    /* A list of parsed Mapping nodes. */
    List<Mapping> listMapping = new ArrayList<Mapping>();

    /*
    * We need to check that we don't have repeated mappings.
    * We based this on calculating an id with the values of the mapping.
    */
    String id;
    List<String> mapsIdList = new ArrayList<String>();

    if (mappingNodes.size() < 1) {
        Log.error("You need at least one mapping node");
        System.exit(0);
    }

    for (Node node : mappingNodes) {
        maps = new ArrayList<Map<String, String>>();

        if ((node.getName() == null) || (!(node.getName().equals("mapping")))
                || (node.selectSingleNode("@refresh") == null)
                || (node.selectSingleNode("@refresh").getStringValue().isEmpty())
                || (node.selectSingleNode("@elementsAtOnce") == null)
                || (node.selectSingleNode("@elementsAtOnce").getStringValue().isEmpty())) {
            Log.error("Found an incorrect mapping node");
            System.exit(0);
        }
        refresh = Integer.parseInt(node.selectSingleNode("@refresh").getStringValue());
        elementsAtOnce = Integer.parseInt(node.selectSingleNode("@elementsAtOnce").getStringValue());

        List<Node> mysqlNodes = node.selectNodes("mysql");
        List<Node> cassandraNodes = node.selectNodes("cassandra");
        List<Node> mapsNodes = node.selectNodes("maps");
        if ((mysqlNodes.size() != 1) || (cassandraNodes.size() != 1) || (mapsNodes.size() != 1)) {
            Log.error("Each mapping needs one mysql|cassandra|maps node");
            System.exit(0);
        }

        /* Parsing mySQL information */
        Node mysqlNode = (Node) mysqlNodes.toArray()[0];
        if ((mysqlNode.selectSingleNode("@host") == null)
                || (mysqlNode.selectSingleNode("@host").getStringValue().isEmpty())
                || (mysqlNode.selectSingleNode("@user") == null)
                || (mysqlNode.selectSingleNode("@user").getStringValue().isEmpty())
                || (mysqlNode.selectSingleNode("@pass") == null)
                || (mysqlNode.selectSingleNode("@pass").getStringValue().isEmpty())
                || (mysqlNode.selectSingleNode("@db") == null)
                || (mysqlNode.selectSingleNode("@db").getStringValue().isEmpty())
                || (mysqlNode.selectSingleNode("@table") == null)
                || (mysqlNode.selectSingleNode("@table").getStringValue().isEmpty())
                || (mysqlNode.selectSingleNode("@numericKeyStr") == null)
                || (mysqlNode.selectSingleNode("@numericKeyStr").getStringValue().isEmpty())
                || (mysqlNode.selectSingleNode("@truncateDataBase") == null)
                || (mysqlNode.selectSingleNode("@truncateDataBase").getStringValue().isEmpty())
                || (mysqlNode.selectSingleNode("@pauseReconnections") == null)
                || (mysqlNode.selectSingleNode("@pauseReconnections").getStringValue().isEmpty())) {
            Log.error("Found an incorrect mysql node");
            System.exit(0);
        }
        /* Setting variables for the mySQL parsed information */
        mysqlHost = mysqlNode.selectSingleNode("@host").getStringValue();
        mysqlPort = Integer.parseInt(mysqlNode.selectSingleNode("@port").getStringValue());
        user = mysqlNode.selectSingleNode("@user").getStringValue();
        pass = mysqlNode.selectSingleNode("@pass").getStringValue();
        db = mysqlNode.selectSingleNode("@db").getStringValue();
        table = mysqlNode.selectSingleNode("@table").getStringValue();
        numericKeyStr = mysqlNode.selectSingleNode("@numericKeyStr").getStringValue();

        if ((!(mysqlNode.selectSingleNode("@truncateDataBase").getStringValue().equals("true")))
                && (!(mysqlNode.selectSingleNode("@truncateDataBase").getStringValue().equals("false")))) {
            Log.error("Found an incorrect type in a column: "
                    + mysqlNode.selectSingleNode("@truncateDataBase").getStringValue());
            System.exit(0);
        }

        if (mysqlNode.selectSingleNode("@truncateDataBase").getStringValue().equals("true")) {
            truncateDataBase = Boolean.TRUE;
        } else {
            truncateDataBase = Boolean.FALSE;
        }

        pauseMySQLReconnections = Integer
                .parseInt(mysqlNode.selectSingleNode("@pauseReconnections").getStringValue());

        /* Parsing cassandra information */
        Node cassandraNode = (Node) cassandraNodes.toArray()[0];
        if ((cassandraNode.selectSingleNode("@host") == null)
                || (cassandraNode.selectSingleNode("@host").getStringValue().isEmpty())
                || (cassandraNode.selectSingleNode("@port") == null)
                || (cassandraNode.selectSingleNode("@port").getStringValue().isEmpty())
                || (cassandraNode.selectSingleNode("@pauseReconnections") == null)
                || (cassandraNode.selectSingleNode("@pauseReconnections").getStringValue().isEmpty())
                || (cassandraNode.selectSingleNode("@keysType") == null)
                || (cassandraNode.selectSingleNode("@keysType").getStringValue().isEmpty())) {
            Log.error("Found an incorrect cassandra node. Host, port, pauseReconnections or keysType non-set");
            System.exit(0);
        }

        if ((!(cassandraNode.selectSingleNode("@keysType").getStringValue().equals("int")))
                && (!(cassandraNode.selectSingleNode("@keysType").getStringValue().equals("string")))) {
            Log.error("Found an incorrect type for the Cassandra keys: "
                    + cassandraNode.selectSingleNode("@keysType").getStringValue());
            System.exit(0);
        }

        /* Setting variables for the Cassandra parsed information */
        cassHost = cassandraNode.selectSingleNode("@host").getStringValue();
        cassPort = Integer.parseInt(cassandraNode.selectSingleNode("@port").getStringValue());
        pauseCassandraReconnections = Integer
                .parseInt(cassandraNode.selectSingleNode("@pauseReconnections").getStringValue());
        keysType = cassandraNode.selectSingleNode("@keysType").getStringValue();

        /* Parsing the columns and adding a 'map' for each column. */
        Node mapsNode = (Node) mapsNodes.toArray()[0];
        List<Node> columnNodes = mapsNode.selectNodes("column");
        if (columnNodes.size() < 2) {
            Log.error("You need at least two columns in the maps");
            System.exit(0);
        }
        for (Node column : columnNodes) {
            if (!(column.getName().equals("column"))) {
                Log.error("Found an incorrect maps");
                System.exit(0);
            }

            if ((column.selectSingleNode("@name") == null)
                    || (column.selectSingleNode("@name").getStringValue().isEmpty())
                    || (column.selectSingleNode("@type") == null)
                    || (column.selectSingleNode("@type").getStringValue().isEmpty())
                    || (column.selectSingleNode("@secondaryIndex") == null)
                    || (column.selectSingleNode("@secondaryIndex").getStringValue().isEmpty())) {
                Log.error("Found an incorrect column node");
                System.exit(0);
            }

            if ((!(column.selectSingleNode("@type").getStringValue().equals("int")))
                    && (!(column.selectSingleNode("@type").getStringValue().equals("string")))
                    && (!(column.selectSingleNode("@type").getStringValue().equals("datetime")))) {
                Log.error("Found an incorrect type in a column: "
                        + column.selectSingleNode("@type").getStringValue());
                System.exit(0);
            }

            if ((!(column.selectSingleNode("@secondaryIndex").getStringValue().equals("true")))
                    && (!(column.selectSingleNode("@secondaryIndex").getStringValue().equals("false")))) {
                Log.error("Found an incorrect type in a column: "
                        + column.selectSingleNode("@secondaryIndex").getStringValue());
                System.exit(0);
            }

            Map<String, String> tmp = new HashMap<String, String>();
            tmp.put("name", column.selectSingleNode("@name").getStringValue());
            tmp.put("type", column.selectSingleNode("@type").getStringValue());
            tmp.put("secondaryIndex", column.selectSingleNode("@secondaryIndex").getStringValue());
            maps.add(tmp);

            Log.debug("name:" + column.selectSingleNode("@name").getStringValue() + ", type:"
                    + column.selectSingleNode("@type").getStringValue() + ", secondaryIndex:"
                    + column.selectSingleNode("@secondaryIndex").getStringValue());
        }

        /* Checking if a mapping node similar to the actual has been inserted.*/
        id = mysqlHost + mysqlPort + db + table + cassHost + cassPort;
        if (mapsIdList.contains(id)) {
            Log.error("Found a repeated mapping node with id: " + id);
            System.exit(0);
        } else {
            mapsIdList.add(id);
        }

        /* Finally creating and adding another mapping node. */
        Mapping m = new Mapping(lock, keyspaces, truncateDataBase, keysType, pauseMySQLReconnections,
                pauseCassandraReconnections, refresh, elementsAtOnce, mysqlHost, mysqlPort, db, user, pass,
                table, numericKeyStr, maps, cassHost, cassPort);
        listMapping.add(m);
        Log.debug("Success while adding another mapping!");

    }

    /* Finally returning the desired object. */
    return listMapping;
}

From source file:nl.nn.ibistesttool.PipeDescriptionProvider.java

License:Apache License

private void addResourceNamesToPipeDescription(Element element, PipeDescription pipeDescription) {
    for (int i = 0, size = element.attributeCount(); i < size; i++) {
        Attribute attribute = element.attribute(i);
        if ("styleSheetName".equals(attribute.getName())
                || "serviceSelectionStylesheetFilename".equals(attribute.getName())
                || "schema".equals(attribute.getName()) || "wsdl".equals(attribute.getName())
                || "fileName".equals(attribute.getName()) || "schemaLocation".equals(attribute.getName())) {
            if ("schemaLocation".equals(attribute.getName())) {
                StringTokenizer st = new StringTokenizer(attribute.getValue(), ", \t\r\n\f");
                while (st.hasMoreTokens()) {
                    st.nextToken();//  w  ww.  j av a  2  s.co m
                    String resourceName = st.nextToken();
                    if (!pipeDescription.containsResourceName(resourceName)) {
                        pipeDescription.addResourceName(resourceName);
                    }
                }
            } else {
                String resourceName = attribute.getValue();
                if (!pipeDescription.containsResourceName(resourceName)) {
                    pipeDescription.addResourceName(resourceName);
                }
            }
        }
    }
    for (int i = 0, size = element.nodeCount(); i < size; i++) {
        Node node = element.node(i);
        if (node instanceof Element && "sender".equals(node.getName())) {
            addResourceNamesToPipeDescription((Element) node, pipeDescription);
        }
    }
}