Example usage for org.dom4j Node selectNodes

List of usage examples for org.dom4j Node selectNodes

Introduction

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

Prototype

List<Node> selectNodes(String xpathExpression);

Source Link

Document

selectNodes evaluates an XPath expression and returns the result as a List of Node instances or String instances depending on the XPath expression.

Usage

From source file:com.dtolabs.client.services.RundeckAPICentralDispatcher.java

License:Apache License

public Collection<IStoredJob> reallistStoredJobs(final IStoredJobsQuery iStoredJobsQuery)
        throws CentralDispatcherException {
    final HashMap<String, String> params = new HashMap<String, String>();
    final String nameMatch = iStoredJobsQuery.getNameMatch();
    String groupMatch = iStoredJobsQuery.getGroupMatch();
    final String projectFilter = iStoredJobsQuery.getProjectFilter();
    final String idlistFilter = iStoredJobsQuery.getIdlist();

    if (null != nameMatch) {
        params.put("jobExactFilter", nameMatch);
    }// w w w  .  ja  va2  s .c o  m
    if (null != groupMatch) {
        final Matcher matcher = Pattern.compile("^/*(.+?)/*$").matcher(groupMatch);
        if (matcher.matches()) {
            //strip leading and trailing slashes
            groupMatch = matcher.group(1);
        }
        params.put("groupPathExact", groupMatch);
    }
    if (null != projectFilter) {
        params.put("project", projectFilter);
    }
    if (null != idlistFilter) {
        params.put("idlist", idlistFilter);
    }

    //2. send request via ServerService
    final WebserviceResponse response;
    try {
        response = serverService.makeRundeckRequest(RUNDECK_API_JOBS_LIST_PATH, params, null, null, null);
    } catch (MalformedURLException e) {
        throw new CentralDispatcherServerRequestException("Failed to make request", e);
    }
    validateResponse(response);
    //extract job list
    final Document resultDoc = response.getResultDoc();
    final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>();

    final Node jobs = resultDoc.selectSingleNode("/result/jobs");
    for (final Object job1 : jobs.selectNodes("job")) {
        final Node job = (Node) job1;
        final String id = job.selectSingleNode("@id").getStringValue();
        final String name = job.selectSingleNode("name").getStringValue();
        final String group = job.selectSingleNode("group").getStringValue();
        final String desc = job.selectSingleNode("description").getStringValue();
        final String url = createJobURL(id);
        list.add(StoredJobImpl.create(id, name, url, group, desc, projectFilter));
    }

    return list;
}

From source file:com.dtolabs.client.services.RundeckCentralDispatcher.java

License:Apache License

public Collection<QueuedItem> listDispatcherQueue(final String project) throws CentralDispatcherException {
    final HashMap<String, String> params = new HashMap<String, String>();
    params.put("xmlreq", "true");
    if (null != project) {
        params.put("projFilter", project);
    }/*from  w ww . ja  v  a2 s . c  o m*/

    final WebserviceResponse response;
    try {
        response = serverService.makeRundeckRequest(RUNDECK_LIST_EXECUTIONS_PATH, params, null, null);
    } catch (MalformedURLException e) {
        throw new CentralDispatcherServerRequestException("Failed to make request", e);
    }

    validateResponse(response);

    ////////////////////
    //parse result list of queued items, return the collection of QueuedItems
    ///////////////////

    final Document resultDoc = response.getResultDoc();

    final Node node = resultDoc.selectSingleNode("/result/items");
    final List items = node.selectNodes("item");
    final ArrayList<QueuedItem> list = new ArrayList<QueuedItem>();
    if (null != items && items.size() > 0) {
        for (final Object o : items) {
            final Node node1 = (Node) o;
            final String id = node1.selectSingleNode("id").getStringValue();
            final String name = node1.selectSingleNode("name").getStringValue();
            String url = node1.selectSingleNode("url").getStringValue();
            url = makeAbsoluteURL(url);
            logger.info("\t" + ": " + name + " [" + id + "] <" + url + ">");
            list.add(QueuedItemResultImpl.createQueuedItem(id, url, name));
        }
    }

    return list;

}

From source file:com.dtolabs.client.services.RundeckCentralDispatcher.java

License:Apache License

public Collection<IStoredJob> listStoredJobs(final IStoredJobsQuery iStoredJobsQuery, final OutputStream output,
        final JobDefinitionFileFormat fformat) throws CentralDispatcherException {
    final HashMap<String, String> params = new HashMap<String, String>();
    final String nameMatch = iStoredJobsQuery.getNameMatch();
    String groupMatch = iStoredJobsQuery.getGroupMatch();
    final String projectFilter = iStoredJobsQuery.getProjectFilter();
    final String idlistFilter = iStoredJobsQuery.getIdlist();

    if (null != output && null != fformat) {
        params.put("format", fformat.getName());
    } else {/*from  w w w .j a va2s  .c om*/
        params.put("format", JobDefinitionFileFormat.xml.getName());
    }
    if (null != nameMatch) {
        params.put("jobFilter", nameMatch);
    }
    if (null != groupMatch) {
        final Matcher matcher = Pattern.compile("^/*(.+?)/*$").matcher(groupMatch);
        if (matcher.matches()) {
            //strip leading and trailing slashes
            groupMatch = matcher.group(1);
        }
        params.put("groupPath", groupMatch);
    }
    if (null != projectFilter) {
        params.put("projFilter", projectFilter);
    }
    if (null != idlistFilter) {
        params.put("idlist", idlistFilter);
    }

    //2. send request via ServerService
    final WebserviceResponse response;
    try {
        response = serverService.makeRundeckRequest(RUNDECK_LIST_STORED_JOBS_PATH, params, null, null);
    } catch (MalformedURLException e) {
        throw new CentralDispatcherServerRequestException("Failed to make request", e);
    }

    //if xml, do local validation and listing
    if (null == fformat || fformat == JobDefinitionFileFormat.xml) {
        validateJobsResponse(response);

        ////////////////////
        //parse result list of queued items, return the collection of QueuedItems
        ///////////////////

        final Document resultDoc = response.getResultDoc();

        final Node node = resultDoc.selectSingleNode("/joblist");
        final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>();
        if (null == node) {
            return list;
        }
        final List items = node.selectNodes("job");
        if (null != items && items.size() > 0) {
            for (final Object o : items) {
                final Node node1 = (Node) o;
                final String id = node1.selectSingleNode("id").getStringValue();
                final String name = node1.selectSingleNode("name").getStringValue();
                final String url = createJobURL(id);

                final Node gnode = node1.selectSingleNode("group");
                final String group = null != gnode ? gnode.getStringValue() : null;
                final String description = node1.selectSingleNode("description").getStringValue();
                list.add(StoredJobImpl.create(id, name, url, group, description, projectFilter));
            }
        }

        if (null != output) {
            //write output doc to the outputstream
            final OutputFormat format = OutputFormat.createPrettyPrint();
            try {
                final XMLWriter writer = new XMLWriter(output, format);
                writer.write(resultDoc);
                writer.flush();
            } catch (IOException e) {
                throw new CentralDispatcherServerRequestException(e);
            }
        }
        return list;
    } else if (fformat == JobDefinitionFileFormat.yaml) {
        //do rought yaml parse
        final Collection<Map> mapCollection = validateJobsResponseYAML(response);
        final ArrayList<IStoredJob> list = new ArrayList<IStoredJob>();

        if (null == mapCollection || mapCollection.size() < 1) {
            return list;
        }
        for (final Map map : mapCollection) {
            final String id = map.get("id").toString();
            final String name = (String) map.get("name");
            final String group = map.containsKey("group") ? (String) map.get("group") : null;
            final String desc = map.containsKey("description") ? (String) map.get("description") : "";
            final String url = createJobURL(id);
            list.add(StoredJobImpl.create(id, name, url, group, desc, projectFilter));
        }

        if (null != output) {
            //write output doc to the outputstream
            try {
                final Writer writer = new OutputStreamWriter(output);
                writer.write(response.getResults());
                writer.flush();
            } catch (IOException e) {
                throw new CentralDispatcherServerRequestException(e);
            }
        }
        return list;
    }
    return null;
}

From source file:com.genericworkflownodes.knime.config.impl.DOMHelper.java

License:Open Source License

@SuppressWarnings("unchecked")
public static List<Node> selectNodes(Node root, String query) throws Exception {
    List<Node> result = root.selectNodes(query);
    return result;
}

From source file:com.globalsight.smartbox.util.WebClientHelper.java

License:Apache License

/**
 * Download job/*w w  w  . ja v a 2  s.co m*/
 * 
 * @param jobInfo
 * @return
 * @throws Exception
 */
public static boolean jobDownload(JobInfo jobInfo, String baseDir, String server) {
    try {
        String fileXml = ambassador.getJobExportFiles(accessToken, jobInfo.getJobName());
        Document profileDoc = DocumentHelper.parseText(fileXml);
        Node node = profileDoc.selectSingleNode("/jobFiles");
        String root = node.selectSingleNode("root").getText();
        ArrayList<String> filePaths = new ArrayList<String>();
        List<Node> paths = node.selectNodes("paths");
        for (Node n : paths) {
            filePaths.add(n.getText());
        }

        root = replaceHostUrl(root, server);

        String rootNoCompany = root.substring(0, root.lastIndexOf("/"));
        boolean useHttps = root.startsWith("https:");
        boolean useHttp = root.startsWith("http:");

        String commonPath = ZipUtil.getCommonPath(getReplacedPath(jobInfo.getJobName(), filePaths), "");
        File targetFile = null;
        StringBuffer targetFiles = new StringBuffer();
        for (String path : filePaths) {
            int index = path.indexOf(commonPath);
            String savePath = path.substring(index + commonPath.length());
            String[] nodes = path.split("/");
            String locale = nodes[0];
            savePath = rootNoCompany + "/" + jobInfo.getJobName() + "/" + locale + savePath;

            String downloadUrl = root + "/" + path;

            if (useHttps) {
                targetFile = DownLoadHelper.downloadHttps(downloadUrl, baseDir, savePath);
            } else if (useHttp) {
                targetFile = DownLoadHelper.downloadHttp(downloadUrl, baseDir, savePath);
            }
            targetFiles.append(targetFile.getPath()).append("|");
        }
        if (targetFiles.length() > 0) {
            targetFiles.deleteCharAt(targetFiles.length() - 1);
        }
        jobInfo.setTargetFiles(targetFiles.toString());
    } catch (Exception e) {
        String message = "Failed to download job, Job Name:" + jobInfo.getJobName() + ", Job Id:"
                + jobInfo.getId();
        LogUtil.fail(message, e);
        return false;
    }
    return true;
}

From source file:com.google.code.pentahoflashcharts.charts.AbstractChartFactory.java

License:Open Source License

/**
 * Setup colors for the series and also background
 *///  w w  w.j av  a2 s  .  c o  m
protected void setupColors() {

    Node temp = chartNode.selectSingleNode(COLOR_PALETTE_NODE_LOC);
    if (temp != null) {
        Object[] colorNodes = temp.selectNodes(COLOR_NODE_LOC).toArray();
        for (int j = 0; j < colorNodes.length; j++) {
            colors.add(getValue((Node) colorNodes[j]));
        }
    } else {
        for (int i = 0; i < COLORS_DEFAULT.length; i++) {
            colors.add(COLORS_DEFAULT[i]);
        }
    }

    // Use either chart-background or plot-background (chart takes precendence)
    temp = chartNode.selectSingleNode(PLOT_BACKGROUND_NODE_LOC);
    if (getValue(temp) != null) {
        String type = temp.valueOf(PLOT_BACKGROUND_COLOR_XPATH);
        if (type != null && COLOR_TYPE.equals(type)) {
            chart.setBackgroundColour(getValue(temp));
            chart.setInnerBackgroundColour(getValue(temp));
        }
    }
    temp = chartNode.selectSingleNode(CHART_BACKGROUND_NODE_LOC);
    if (getValue(temp) != null) {
        String type = temp.valueOf(CHART_BACKGROUND_COLOR_XPATH);
        if (type != null && COLOR_TYPE.equals(type))
            chart.setBackgroundColour(getValue(temp));
    }
}

From source file:com.google.code.pentahoflashcharts.charts.BarChartFactory.java

License:Open Source License

@Override
public void setupStyles() {
    super.setupStyles();
    barchartstyle = BARCHART_STYLE_DEFAULT;

    // 3d// w  w  w. j  a  v  a2 s  .  c  o  m
    Node temp = chartNode.selectSingleNode(IS3D_NODE_LOC);
    if (getValue(temp) != null && "true".equals(getValue(temp))) { //$NON-NLS-1$
        barchartstyle = BarChart.Style.THREED;

        // also load 3d height
        temp = chartNode.selectSingleNode(HEIGHT_3D_NODE_LOC);
        if (getValue(temp) != null) {
            threedheight = Integer.parseInt(getValue(temp));
        }
    }
    // Glass
    temp = chartNode.selectSingleNode(ISGLASS_NODE_LOC);
    if (getValue(temp) != null && "true".equals(getValue(temp))) { //$NON-NLS-1$
        barchartstyle = BarChart.Style.GLASS;
    }
    // Sketch
    temp = chartNode.selectSingleNode(ISSKETCH_NODE_LOC);
    if (getValue(temp) != null && "true".equals(getValue(temp))) { //$NON-NLS-1$
        issketch = true;
        // Also load fun factor
        temp = chartNode.selectSingleNode(FUN_FACTOR_NODE_LOC);
        if (getValue(temp) != null) {
            sketchBarFunFactor = Integer.parseInt(getValue(temp));
        } else {
            sketchBarFunFactor = SKETCH_FUNFACTOR_DEFAULT;
        }
    } else {
        issketch = false;
    }

    // Stacked
    temp = chartNode.selectSingleNode(ISSTACKED_NODE_LOC);
    if (getValue(temp) != null) {
        isstacked = "true".equals(getValue(temp)); //$NON-NLS-1$
    }

    temp = chartNode.selectSingleNode(OUTLINE_COLOR_PALETTE_NODE_LOC);
    if (temp != null) {
        Object[] colorNodes = temp.selectNodes(COLOR_NODE_LOC).toArray();
        for (int j = 0; j < colorNodes.length; j++) {
            outlineColors.add(getValue((Node) colorNodes[j]));
        }
    } else {
        for (int i = 0; i < COLORS_DEFAULT.length; i++) {
            outlineColors.add(COLORS_DEFAULT[i]);
        }
    }
}

From source file:com.google.code.pentahoflashcharts.charts.pfcxml.AreaChartBuilder.java

License:Open Source License

protected void setupElements(Chart c, Node root, IPentahoResultSet data) {
    String dotType = setupDotType(root);
    int rowCount = data.getRowCount();
    int columnCount = data.getMetaData().getColumnCount();
    LineChart[] elements = null;/*w  w w.  j av a 2s .  c o m*/
    if (columnCount > 1) {
        if (DOT_TYPE_HOLLOW.equalsIgnoreCase(dotType))
            elements = new AreaHollowChart[rowCount];
        else
            elements = new AreaLineChart[rowCount];
        List colors = root.selectNodes("/chart/color-palette/color");
        for (int n = 0; n < rowCount; n++) {
            LineChart e = null;
            if (DOT_TYPE_HOLLOW.equalsIgnoreCase(dotType)) {
                e = new AreaHollowChart();
            } else {
                e = new AreaLineChart();
            }

            Number[] datas = new Number[columnCount - 1];
            for (int i = 1; i <= columnCount - 1; i++) {
                datas[i - 1] = (Number) data.getValueAt(n, i);
                e.addValues(datas[i - 1].doubleValue());
            }
            String colour;
            if (colors != null && colors.size() > 1) {
                colour = ((Node) colors.get(n)).getText().trim();
                e.setColour(colour);
            }
            e.setText("" + data.getValueAt(n, 0));
            setLink(e, root, "/chart/link");
            setOnClick(e, root, "/chart/on-click");
            elements[n] = e;
            //TODO
            setWidth(e, null);

        }
        setupXAxisLabels(data, c, columnCount);
    }

    c.addElements(elements);
}

From source file:com.google.code.pentahoflashcharts.charts.pfcxml.BarLineChartBuilder.java

License:Open Source License

protected void setupBarElements(Chart c, Node root, IPentahoResultSet data) {
    List bars = root.selectNodes("/chart/bars/bar");
    Node is_3DNode = root.selectSingleNode("/chart/is-3D");
    Node is_glassNode = root.selectSingleNode("/chart/is-glass");
    //      Node is_sketchNode = root.selectSingleNode("/chart/is-sketch");
    BarChart.Style style = null;// w  w  w.j  a v a  2s . c o  m
    if (getValue(is_3DNode) != null) {
        String str = is_3DNode.getText().trim();
        if (str.equalsIgnoreCase("true")) {
            style = BarChart.Style.THREED;
        }
    }
    if (getValue(is_glassNode) != null) {
        String str = is_glassNode.getText().trim();
        if (str.equalsIgnoreCase("true")) {
            style = BarChart.Style.GLASS;
        }
    }
    if (style == null)
        style = BarChart.Style.NORMAL;
    BarChart[] values = null;
    int rowCount = data.getRowCount();

    int barNum = bars.size();
    values = new BarChart[barNum];
    for (int i = 0; i < barNum; i++) {
        Node bar = (Node) bars.get(i);
        Node colorNode = bar.selectSingleNode("color");
        Node textNode = bar.selectSingleNode("text");
        BarChart e = new BarChart(style);

        Number[] datas = new Number[rowCount];
        if (colorNode != null && colorNode.getText().length() > 2) {
            String str = colorNode.getText().trim();
            e.setColour(str);
        }
        if (textNode != null && textNode.getText().length() > 0) {
            e.setText(textNode.getText().trim());
        }
        Node colIndexNode = bar.selectSingleNode("sql-column-index");
        if (colIndexNode != null && colIndexNode.getText().length() > 0) {
            int index = Integer.parseInt(colIndexNode.getText().trim());
            for (int j = 0; j < rowCount; j++) {
                datas[j] = (Number) data.getValueAt(j, index - 1);
                e.addBars(new BarChart.Bar(datas[j].doubleValue()));
                // e.addValues(datas[j].doubleValue());
            }
        }
        values[i] = e;
    }
    c.addElements(values);

}

From source file:com.google.code.pentahoflashcharts.charts.pfcxml.HorizontalBarChartBuilder.java

License:Open Source License

protected void setupElements(Chart c, Node root, IPentahoResultSet data) {
    HorizontalBarChart hbc = new HorizontalBarChart();
    for (int i = 0; i < data.getRowCount(); i++) {
        double d = ((Number) data.getValueAt(i, 1)).doubleValue();
        hbc.addBars(new HorizontalBarChart.Bar(d));
    }//from   w  w w  . ja v  a  2 s  .c om
    if (getValue(root.selectSingleNode("/chart/color-palette")) != null) {
        List colors = root.selectNodes("/chart/color-palette/color");
        String colour = getNodeValue((Node) colors.get(0));
        hbc.setColour(colour);
    } else
        hbc.setColour("#86BBEF");
    c.addElements(hbc);

}