Example usage for org.dom4j Node valueOf

List of usage examples for org.dom4j Node valueOf

Introduction

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

Prototype

String valueOf(String xpathExpression);

Source Link

Document

valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.

Usage

From source file:it.eng.spagobi.studio.dashboard.editors.model.dashboard.Configuration.java

License:Mozilla Public License

public Parameter[] getConfigurationParametersForMovie(String dashboardMovie, Document document)
        throws Exception {
    Parameter[] toReturn = null;//w  w  w  .  j av  a  2 s .  com
    List dashboards = document.selectNodes("//DASHBOARDS/DASHBOARD");
    if (dashboards == null || dashboards.size() == 0)
        throw new Exception("No dashboards configured");
    for (int i = 0; i < dashboards.size(); i++) {
        Node dashboard = (Node) dashboards.get(i);
        String movie = dashboard.valueOf("@movie");
        if (dashboardMovie.equals(movie)) {
            List configuredParameters = dashboard.selectNodes("CONF/PARAMETER");
            toReturn = new Parameter[configuredParameters.size()];
            for (int j = 0; j < configuredParameters.size(); j++) {
                Node aConfiguredParameter = (Node) configuredParameters.get(j);
                String name = aConfiguredParameter.valueOf("@name");
                String description = aConfiguredParameter.valueOf("@description");
                String typeStr = aConfiguredParameter.valueOf("@type");
                int type;
                if (typeStr.equals("NUMBER"))
                    type = Parameter.NUMBER_TYPE;
                else if (typeStr.equals("STRING"))
                    type = Parameter.STRING_TYPE;
                else if (typeStr.equals("COLOR"))
                    type = Parameter.COLOR_TYPE;
                else if (typeStr.equals("BOOLEAN"))
                    type = Parameter.BOOLEAN_TYPE;
                else
                    throw new Exception("Parameter type for parameter " + name + " not supported");
                toReturn[j] = new Parameter(name, "", description, type);
            }
            break;
        }
    }
    return toReturn;
}

From source file:it.eng.spagobi.studio.dashboard.editors.model.dashboard.DashboardModel.java

License:Mozilla Public License

public String getDashboardTypeForMovie(Document document) throws Exception {
    String toReturn = null;/*ww w.  j av  a 2 s  . co  m*/
    List dashboards = document.selectNodes("//DASHBOARDS/DASHBOARD");
    if (dashboards == null || dashboards.size() == 0)
        throw new Exception("No dashboards configured");
    for (int i = 0; i < dashboards.size(); i++) {
        Node dashboard = (Node) dashboards.get(i);
        String movie = dashboard.valueOf("@movie");
        if (this.movie.equals(movie)) {
            toReturn = dashboard.valueOf("@type");
            break;
        }
    }
    return toReturn;
}

From source file:it.eng.spagobi.studio.dashboard.editors.model.dashboard.DashboardModel.java

License:Mozilla Public License

public static List getConfiguredDashboardTypes() throws Exception {
    List toReturn = new ArrayList();
    InputStream is = getInputStreamFromResource(DASHBOARD_INFO_FILE);
    Document document = new SAXReader().read(is);
    List dashboards = document.selectNodes("//DASHBOARDS/DASHBOARD");
    if (dashboards == null || dashboards.size() == 0)
        throw new Exception("No dashboards configured");
    for (int i = 0; i < dashboards.size(); i++) {
        Node dashboard = (Node) dashboards.get(i);
        String type = dashboard.valueOf("@type");
        if (type == null || type.trim().equals(""))
            continue;
        toReturn.add(type);//from  www.ja v a2 s  .  c o  m
    }
    return toReturn;
}

From source file:it.eng.spagobi.studio.dashboard.editors.model.dashboard.DashboardModel.java

License:Mozilla Public License

public static String getDashboardTemplatePath(String dashboardType) throws Exception {
    String toReturn = null;/*from   ww w  . j  a  v  a 2  s .  c  om*/
    InputStream is = getInputStreamFromResource(DASHBOARD_INFO_FILE);
    Document document = new SAXReader().read(is);
    List dashboards = document.selectNodes("//DASHBOARDS/DASHBOARD");
    if (dashboards == null || dashboards.size() == 0)
        throw new Exception("No dashboards configured");
    for (int i = 0; i < dashboards.size(); i++) {
        Node dashboard = (Node) dashboards.get(i);
        String type = dashboard.valueOf("@type");
        if (dashboardType.equals(type)) {
            String templatePath = dashboard.valueOf("@templatePath");
            toReturn = templatePath;
            break;
        }
    }
    return toReturn;
}

From source file:it.eng.spagobi.studio.dashboard.editors.model.dashboard.DashboardModelFactory.java

License:Mozilla Public License

public static DashboardModel createDashboardModel(IFile file) throws Exception {
    DashboardModel model = new DashboardModel();
    InputStream templateIs = null;
    InputStream configurationIs = null;
    try {//w ww  .  j  av  a 2 s .  co m
        // reads the template file
        templateIs = file.getContents();
        SAXReader reader = new SAXReader();
        Document templateDocument = reader.read(templateIs);

        // reads the dashboards configuration file
        Document configurationDocument = null;
        try {
            configurationIs = DashboardModel.getInputStreamFromResource(DashboardModel.DASHBOARD_INFO_FILE);
            configurationDocument = reader.read(configurationIs);
        } catch (Exception e) {
            throw new Exception(
                    "Error while reading " + DashboardModel.DASHBOARD_INFO_FILE + " file: " + e.getMessage());
        }

        // finds the movie
        Node dashboard = templateDocument.selectSingleNode("//DASHBOARD");
        if (dashboard == null) {
            throw new Exception("xml not valid");
        }
        String movie = dashboard.valueOf("@movie");
        if (movie == null || movie.trim().equals("")) {
            // TODO manage movie not found
            throw new Exception("Movie not found");
        }
        model.setMovie(movie);

        // finds the type
        String type = model.getDashboardTypeForMovie(configurationDocument);
        model.setType(type);

        // finds the displayTitleBar
        String displayTitleBarStr = dashboard.valueOf("@displayTitleBar");
        // TODO control default value
        boolean displayTitleBar = Boolean.parseBoolean(displayTitleBarStr);
        model.setDisplayTitleBar(displayTitleBar);

        // finds the dimension
        Node dimensioneNode = templateDocument.selectSingleNode("//DASHBOARD/DIMENSION");
        if (dimensioneNode == null) {
            // TODO manage exception
            throw new Exception("Dimension is missing");
        }
        String widthStr = dimensioneNode.valueOf("@width");
        String heightStr = dimensioneNode.valueOf("@height");
        int width;
        int height;
        try {
            width = Integer.parseInt(widthStr);
            height = Integer.parseInt(heightStr);
        } catch (NumberFormatException nfe) {
            // TODO manage exception
            throw new Exception("Dimension not valid");
        }
        Dimension dimension = model.new Dimension(width, height);
        model.setDimension(dimension);

        // finds data
        Node dataNode = templateDocument.selectSingleNode("//DASHBOARD/DATA");
        String url = dataNode.valueOf("@url");
        List dataParametersList = templateDocument.selectNodes("//DASHBOARD/DATA/PARAMETER");
        if (dataParametersList == null || dataParametersList.size() == 0) {
            // TODO manage exception
            //throw new Exception("missing data parameters");
        }
        Data data = new Data(url, movie, configurationDocument);
        for (int i = 0; i < dataParametersList.size(); i++) {
            Node node = (Node) dataParametersList.get(i);
            String name = node.valueOf("@name");
            String value = node.valueOf("@value");
            data.setParameterValue(name, value);
        }
        model.setData(data);

        // finds configuration parameters
        Configuration configuration = null;
        /*   if (movie.equals("sbigrid_jsd.lzx.swf")) {
              List confParametersList = templateDocument.selectNodes("//DASHBOARD/CONFIGURATION/PARAMETERS/PARAMETER");
              if (confParametersList == null || confParametersList.size() == 0) {
                 // TODO manage exception
                 throw new Exception("missing configuration parameters");
              }
              configuration = new GridConfiguration(movie, configurationDocument);
              for (int i = 0; i < confParametersList.size(); i++) {
                 Node node = (Node) confParametersList.get(i);
                 String name = node.valueOf("@name");
                 String value = node.valueOf("@value");
                 configuration.setParameterValue(name, value);
              }
              // link columns
              List linkColumnsList = templateDocument.selectNodes("//DASHBOARD/CONFIGURATION/LINKCOLUMNS/COLUMN");
              LinkColumn[] linkColumns = new LinkColumn[linkColumnsList.size()];
              for (int i = 0; i < linkColumnsList.size(); i++) {
                 Node node = (Node) linkColumnsList.get(i);
                 String index = node.valueOf("@index");
                 String onlyheader = node.valueOf("@onlyheader");
                 String fixedquerystring = node.valueOf("@fixedquerystring");
                 String prefixvalue = node.valueOf("@prefixvalue");
                 LinkColumn linkColumn = new LinkColumn();
                 linkColumn.setIndex(Integer.parseInt(index));
                 linkColumn.setOnlyheader(Boolean.parseBoolean(onlyheader));
                 linkColumn.setFixedquerystring(fixedquerystring);
                 linkColumn.setPrefixvalue(prefixvalue);
                 linkColumns[i] = linkColumn;
              }
              ((GridConfiguration) configuration).setLinkColumns(linkColumns);
                      
              // light columns
              List lightColumnsList = templateDocument.selectNodes("//DASHBOARD/CONFIGURATION/LINKCOLUMNS/COLUMN");
              LightColumn[] lightColumns = new LightColumn[lightColumnsList.size()];
              for (int i = 0; i < lightColumnsList.size(); i++) {
                 Node node = (Node) lightColumnsList.get(i);
                 String index = node.valueOf("@index");
                 String defaultcolor = node.valueOf("@defaultcolor");
                 String defaulttooltip = node.valueOf("@defaulttooltip");
                 List conditionsList = node.selectNodes("CONDITIONS/CONDITION");
                 Condition[] conditions = new Condition[conditionsList.size()];
                 for (int j = 0; j < conditions.length; j++) {
          Node aCondition = (Node) conditionsList.get(j);
          Condition condition = new Condition();
          condition.setConditioncolor(node.valueOf("@conditioncolor"));
          condition.setValue1(node.valueOf("@value1"));
          condition.setValue2(node.valueOf("@value2"));
          condition.setOperator(node.valueOf("@operator"));
          condition.setTooltip(node.valueOf("@tooltip"));
          condition.setShowvalueintotooltip(Boolean.parseBoolean(node.valueOf("@conditioncolor")));
          conditions[j] = condition;
                 }
                 LightColumn lightColumn = new LightColumn();
                 lightColumn.setIndex(Integer.parseInt(index));
                 lightColumn.setDefaultcolor(defaultcolor);
                 lightColumn.setDefaulttooltip(defaulttooltip);
                 lightColumn.setConditions(conditions);
                 lightColumns[i] = lightColumn;
              }
              ((GridConfiguration) configuration).setLightColumns(lightColumns);
                      
              // name columns
              List nameColumnsList = templateDocument.selectNodes("//DASHBOARD/CONFIGURATION/NAMECOLUMNS/COLUMN");
              NameColumn[] nameColumns = new NameColumn[nameColumnsList.size()];
              for (int i = 0; i < nameColumnsList.size(); i++) {
                 Node node = (Node) nameColumnsList.get(i);
                 String index = node.valueOf("@index");
                 String assignedName = node.valueOf("@name");
                 NameColumn nameColumn = new NameColumn();
                 nameColumn.setIndex(Integer.parseInt(index));
                 nameColumn.setAssignedName(assignedName);
                 nameColumns[i] = nameColumn;
              }
              ((GridConfiguration) configuration).setNameColumns(nameColumns);
                      
              // dimension columns
              List dimensionColumnsList = templateDocument.selectNodes("//DASHBOARD/CONFIGURATION/DIMENSIONCOLUMNS/COLUMN");
              DimensionColumn[] dimensionColumns = new DimensionColumn[dimensionColumnsList.size()];
              for (int i = 0; i < dimensionColumnsList.size(); i++) {
                 Node node = (Node) dimensionColumnsList.get(i);
                 String index = node.valueOf("@index");
                 String columnWidth = node.valueOf("@width");
                 DimensionColumn dimensionColumn = new DimensionColumn();
                 dimensionColumn.setIndex(Integer.parseInt(index));
                 dimensionColumn.setWidth(Integer.parseInt(columnWidth));
                 dimensionColumns[i] = dimensionColumn;
              }
              ((GridConfiguration) configuration).setDimensionColumns(dimensionColumns);
                      
           } else {
              */
        List confParametersList = templateDocument.selectNodes("//DASHBOARD/CONF/PARAMETER");
        if (confParametersList == null || confParametersList.size() == 0) {
            // TODO manage exception
            logger.warn("missing configuration parameters");
            //throw new Exception("missing configuration parameters");
        }
        configuration = new Configuration(movie, configurationDocument);
        for (int i = 0; i < confParametersList.size(); i++) {
            Node node = (Node) confParametersList.get(i);
            String name = node.valueOf("@name");
            String value = node.valueOf("@value");
            configuration.setParameterValue(name, value);
        }
        //}
        model.setConfiguration(configuration);

        // TODO change to service from spagobi server
        Lov lov = new Lov();
        lov.setColumns(new String[] { "Colonna 0", "Colonna 1", "Colonna 3", "Colonna 4" });
        model.setLov(lov);

    } finally {
        if (templateIs != null)
            templateIs.close();
        if (configurationIs != null)
            configurationIs.close();
    }

    return model;
}

From source file:it.eng.spagobi.studio.dashboard.editors.model.dashboard.Data.java

License:Mozilla Public License

public Parameter[] getDataParametersForMovie(String dashboardMovie, Document document) throws Exception {
    Parameter[] toReturn = null;//from w w  w  .  ja  v  a  2 s.  c o m
    List dashboards = document.selectNodes("//DASHBOARDS/DASHBOARD");
    if (dashboards == null || dashboards.size() == 0)
        throw new Exception("No dashboards configured");
    for (int i = 0; i < dashboards.size(); i++) {
        Node dashboard = (Node) dashboards.get(i);
        String movie = dashboard.valueOf("@movie");
        if (dashboardMovie.equals(movie)) {
            List configuredParameters = dashboard.selectNodes("DATA/PARAMETER");
            toReturn = new Parameter[configuredParameters.size()];
            for (int j = 0; j < configuredParameters.size(); j++) {
                Node aConfiguredParameter = (Node) configuredParameters.get(j);
                String name = aConfiguredParameter.valueOf("@name");
                String description = aConfiguredParameter.valueOf("@description");
                String typeStr = aConfiguredParameter.valueOf("@type");
                int type;
                if (typeStr.equals("NUMBER"))
                    type = Parameter.NUMBER_TYPE;
                else if (typeStr.equals("STRING"))
                    type = Parameter.STRING_TYPE;
                else if (typeStr.equals("COLOR"))
                    type = Parameter.COLOR_TYPE;
                else if (typeStr.equals("BOOLEAN"))
                    type = Parameter.BOOLEAN_TYPE;
                else
                    throw new Exception("Parameter type for parameter " + name + " not supported");
                toReturn[j] = new Parameter(name, "", description, type);
            }
            break;
        }
    }
    return toReturn;
}

From source file:it.eng.spagobi.studio.extchart.configuration.ExtChartConfigurations.java

License:Mozilla Public License

public static List getConfiguredChartTypes() throws Exception {
    List toReturn = null;/*w  w  w .j  a  v a 2 s  .com*/
    try {
        InputStream is = getInputStreamFromResource(INFO_FILE);
        Document document = new SAXReader().read(is);
        List charts = document.selectNodes("//EXTCHARTS/EXTCHART");
        if (charts == null || charts.size() == 0)
            return null;
        toReturn = new ArrayList();
        for (int i = 0; i < charts.size(); i++) {
            Node chart = (Node) charts.get(i);
            String type = chart.valueOf("@type");
            if (type == null || type.trim().equals(""))
                continue;
            toReturn.add(type);
        }
    } catch (Exception e) {
        logger.error("Error in reading configuration types from file " + INFO_FILE);
    }
    return toReturn;
}

From source file:it.eng.spagobi.studio.extchart.utils.ExtChartUtils.java

License:Mozilla Public License

/** Get the chart image path for the selected type
 * // w  w w  . j  a v  a  2  s . c om
 * @param imageType
 * @return
 * @throws Exception
 */

public static String getChartImagePath(String imageType) throws Exception {
    String toReturn = null;
    InputStream is = getInputStreamFromResource(ExtChartConfigurations.INFO_FILE);
    Document document = new SAXReader().read(is);
    List charts = document.selectNodes("//EXTCHARTS/EXTCHART");
    if (charts == null || charts.size() == 0)
        throw new Exception("No charts configured");
    for (int i = 0; i < charts.size(); i++) {
        Node chart = (Node) charts.get(i);
        String type = chart.valueOf("@type");
        if (imageType.equalsIgnoreCase(type)) {
            String imagePath = chart.valueOf("@imagePath");
            toReturn = imagePath;
            break;
        }
    }
    return toReturn;
}

From source file:it.eng.spagobi.studio.extchart.utils.ExtChartUtils.java

License:Mozilla Public License

public static String getXAxeTypeFromChartType(String chartType) throws Exception {
    String toReturn = null;//www. j  a  v a  2 s. c  o m
    InputStream is = getInputStreamFromResource(ExtChartConfigurations.INFO_FILE);
    Document document = new SAXReader().read(is);
    List charts = document.selectNodes("//EXTCHARTS/EXTCHART");
    if (charts == null || charts.size() == 0)
        throw new Exception("No charts configured");
    for (int i = 0; i < charts.size(); i++) {
        Node chart = (Node) charts.get(i);
        String type = chart.valueOf("@type");
        if (chartType.equalsIgnoreCase(type)) {
            String imagePath = chart.valueOf("@xAxeName");
            toReturn = imagePath;
            break;
        }
    }
    return toReturn;
}

From source file:it.eng.spagobi.studio.extchart.utils.ExtChartUtils.java

License:Mozilla Public License

public static String getYAxeTypeFromChartType(String chartType) throws Exception {
    String toReturn = null;/*from www  .j  a  va2  s .  c  o  m*/
    InputStream is = getInputStreamFromResource(ExtChartConfigurations.INFO_FILE);
    Document document = new SAXReader().read(is);
    List charts = document.selectNodes("//EXTCHARTS/EXTCHART");
    if (charts == null || charts.size() == 0)
        throw new Exception("No charts configured");
    for (int i = 0; i < charts.size(); i++) {
        Node chart = (Node) charts.get(i);
        String type = chart.valueOf("@type");
        if (chartType.equalsIgnoreCase(type)) {
            String imagePath = chart.valueOf("@yAxeName");
            toReturn = imagePath;
            break;
        }
    }
    return toReturn;
}