Example usage for org.dom4j Node selectSingleNode

List of usage examples for org.dom4j Node selectSingleNode

Introduction

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

Prototype

Node selectSingleNode(String xpathExpression);

Source Link

Document

selectSingleNode evaluates an XPath expression and returns the result as a single Node instance.

Usage

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

License:Apache License

/**
 * Download job//from   www . ja v  a2 s .c  o  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.globalsight.terminology.Validator.java

License:Apache License

/**
 * Validates an entry. Caller must lock Termbase object with
 * Termbase.addReader().//from  w  ww  .  j a  v  a2  s .co m
 */
static public ValidationInfo validate(Entry p_entry, Definition m_definition, long tb_id)
        throws TermbaseException {
    long cid = EntryUtils.getConceptId(p_entry);
    ValidationInfo result = new ValidationInfo(cid);

    if (CATEGORY.isDebugEnabled()) {
        CATEGORY.debug("Validating entry " + cid + "...");
    }

    List langGrps = EntryUtils.getLanguageGrps(p_entry);

    for (int i = 0, max = langGrps.size(); i < max; i++) {
        Node langGrp = (Node) langGrps.get(i);

        String langName = langGrp.valueOf("language/@name");
        Definition.Language language = m_definition.getLanguage(langName);

        List terms = EntryUtils.getTerms(langGrp);

        for (int j = 0, max2 = terms.size(); j < max2; j++) {
            Node termNode = (Node) terms.get(j);
            Node termAttribute = termNode.selectSingleNode("//term/@termId");
            String termId = null;
            if (termAttribute != null) {
                termId = termAttribute.getText();
            }
            String term = termNode.getText();

            // Collect exact matches from the same language.
            Hitlist hits = getDuplicateTerm(tb_id, langName, term, termId);

            addHits(result, langName, term, hits);

            // Should look for fuzzy matches too.
        }
    }

    if (CATEGORY.isDebugEnabled()) {
        CATEGORY.debug("Validating entry " + cid + "... done.");
    }

    return result;
}

From source file:com.globalsight.util.ConfigUtil.java

License:Apache License

public static ConfigBO getConfigBO() {
    String hostName;/*  w w w. j a  va2s. c  o  m*/
    int port = 80;
    String userName;
    String password;
    int intervalTimeForArchive;
    int intervalTime;
    boolean isUseHTTPS = false;

    try {
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read(new File(Constants.CONFIG_FILE_NAME));
        Node serverNode = document.selectSingleNode("/Configuration/server");

        hostName = serverNode.selectSingleNode("host").getText();
        port = Integer.valueOf(serverNode.selectSingleNode("port").getText());
        userName = serverNode.selectSingleNode("username").getText();
        password = serverNode.selectSingleNode("password").getText();
        isUseHTTPS = Boolean.valueOf(serverNode.selectSingleNode("https").getText());

        intervalTimeForArchive = Integer
                .valueOf(document.selectSingleNode("//intervalTimeForArchive").getText());
        intervalTime = Integer.valueOf(document.selectSingleNode("//intervalTime").getText());

        ConfigBO config = new ConfigBO(hostName, port, userName, password, intervalTimeForArchive, intervalTime,
                isUseHTTPS);
        return config;
    } catch (DocumentException e) {
        LogUtil.info("Fail to read configuration info", e);
    }

    return null;
}

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

License:Open Source License

public static String getNodeValue(Node parent, String node) {
    if (parent == null) {
        return null;
    }/*from   www. j ava  2 s .c  o m*/
    Node textNode = parent.selectSingleNode(node);
    return getValue(textNode);
}

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

License:Open Source License

@SuppressWarnings("unchecked")
public static String generateChartJson(Node chartNode, IPentahoResultSet data, boolean byRow, Log log) {
    String chartType = null;//from   www. j  a v a  2s. c o m
    String factoryClassString = null;
    try {
        Node temp = chartNode.selectSingleNode(CHART_TYPE_NODE_LOC);
        if (AbstractChartFactory.getValue(temp) != null) {
            chartType = AbstractChartFactory.getValue(temp);
        } else {
            // This should NEVER happen.
            chartType = CHART_TYPE_DEFAULT;
        }

        factoryClassString = (String) getChartFactories().get(chartType);
        if (factoryClassString == null) {
            throw new RuntimeException(Messages.getErrorString(
                    "PentahoOFC4JChartHelper.ERROR_0001_FACTORY_INIT", chartType, factoryClassString)); //$NON-NLS-1$
        } else {

            Class factoryClass = Class.forName(factoryClassString);

            // throw exception if factoryClass not found

            IChartFactory factory = (IChartFactory) factoryClass.getConstructor(new Class[0])
                    .newInstance(new Object[0]);
            factory.setChartNode(chartNode);
            factory.setLog(log);
            if (byRow) {
                factory.setData(PentahoDataTransmuter.pivot(data));
            } else {
                factory.setData(data);
            }
            return factory.convertToJson();
        }
    } catch (Exception e) {
        logger.error(Messages.getErrorString("PentahoOFC4JChartHelper.ERROR_0001_FACTORY_INIT", chartType, //$NON-NLS-1$
                factoryClassString), e);
        throw new RuntimeException(e);
    }
}

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

License:Open Source License

private String setupDotType(Node root) {
    if (getValue(root.selectSingleNode("/chart/dot-style")) != null) {
        return getNodeValue(root.selectSingleNode("/chart/dot-style"));
    }//from   ww  w  . j av  a 2  s  . c o m
    return "normal";
}

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

License:Open Source License

protected void setupLineElements(Chart c, Node root, IPentahoResultSet data, int rowCount) {
    Style lineStyle = setupLineStyle(root);
    LineChart e = new LineChart(lineStyle);

    Node colIndexNode = root.selectSingleNode("/chart/line/sql-column-index");
    Node linetooltipNode = root.selectSingleNode("/chart/line/tooltip");
    if (getValue(linetooltipNode) != null) {
        e.setTooltip(getValue(linetooltipNode));
    }/*from   ww w.  j  av a  2s .  co  m*/

    if (colIndexNode != null && colIndexNode.getText().length() > 0) {
        int index = Integer.parseInt(colIndexNode.getText().trim());

        for (int j = 0; j < rowCount; j++) {
            double value = ((Number) data.getValueAt(j, index - 1)).doubleValue();
            e.addValues(value);

        }
    } else {
        for (int j = 0; j < rowCount; j++) {
            double value = ((Number) data.getValueAt(j, data.getColumnCount() - 1)).doubleValue();
            e.addValues(value);

        }
    }

    Node colorNode = root.selectSingleNode("/chart/line/color");
    if (colorNode != null && colorNode.getText().length() > 0) {
        e.setColour(colorNode.getText().trim());
    }
    Node textNode = root.selectSingleNode("/chart/line/text");
    if (textNode != null && textNode.getText().length() > 0) {
        e.setText(textNode.getText().trim());
    }
    e.setRightYAxis();
    c.addElements(e);
}

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;/*from   ww w.  j  ava2  s  .  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.ChartBuilder.java

License:Open Source License

public static void setOnClick(jofc2.model.elements.Element e, Node root, String xpath) {
    if (getValue(root.selectSingleNode(xpath)) != null) {
        e.setOnClick(getNodeValue(root.selectSingleNode(xpath)));
    }//from  ww w  .  j  ava 2  s.  c  o m

}

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

License:Open Source License

public static void setLink(jofc2.model.elements.Element e, Node root, String xpath) {
    if (getValue(root.selectSingleNode(xpath)) != null) {
        // TODO: this was setLink() before.  need to figure out what that was.
        e.setOnClick(getNodeValue(root.selectSingleNode(xpath)));
    }/*from   ww w.  j a  va 2 s.co  m*/

}