Example usage for org.jfree.chart.imagemap ImageMapUtilities getImageMap

List of usage examples for org.jfree.chart.imagemap ImageMapUtilities getImageMap

Introduction

In this page you can find the example usage for org.jfree.chart.imagemap ImageMapUtilities getImageMap.

Prototype

public static String getImageMap(String name, ChartRenderingInfo info) 

Source Link

Document

Creates an image map element that complies with the XHTML 1.0 specification.

Usage

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartRenderedGraph.java

/**
 * {@inheritDoc}
 */
@Override
public String getImageMap(String name) {
    return ImageMapUtilities.getImageMap(name, info);
}

From source file:org.efs.openreports.actions.ChartReportAction.java

public String execute() {
    ReportUser user = (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER);

    report = (Report) ActionContext.getContext().getSession().get(ORStatics.REPORT);

    Map reportParameters = getReportParameterMap(user);

    ReportLog reportLog = new ReportLog(user, report, new Date());

    try {//from   w  w w  .j  a  va  2  s. c o  m
        log.debug("Starting Chart Report: " + report.getName());

        reportLogProvider.insertReportLog(reportLog);

        ChartReportEngine chartReportEngine = new ChartReportEngine(dataSourceProvider, directoryProvider,
                propertiesProvider);

        ReportEngineInput input = new ReportEngineInput(report, reportParameters);

        ChartEngineOutput chartOutput = (ChartEngineOutput) chartReportEngine.generateReport(input);

        chartValues = chartOutput.getChartValues();
        if (chartValues.length == 0) {
            addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_EMPTY));
        }

        imageMap = ImageMapUtilities.getImageMap("chart", chartOutput.getChartRenderingInfo());

        HashMap imagesMap = new HashMap();
        imagesMap.put("ChartImage", chartOutput.getContent());

        ActionContext.getContext().getSession().put(ORStatics.IMAGES_MAP, imagesMap);

        reportLog.setEndTime(new Date());
        reportLog.setStatus(ReportLog.STATUS_SUCCESS);
        reportLogProvider.updateReportLog(reportLog);

        log.debug("Finished Chart Report: " + report.getName());
    } catch (Exception e) {
        addActionError(e.getMessage());

        log.error(e.toString());

        reportLog.setMessage(e.getMessage());
        reportLog.setStatus(ReportLog.STATUS_FAILURE);

        reportLog.setEndTime(new Date());

        try {
            reportLogProvider.updateReportLog(reportLog);
        } catch (Exception ex) {
            log.error("Unable to create ReportLog: " + ex.getMessage());
        }

        return ERROR;
    }

    return SUCCESS;
}

From source file:org.pentaho.chart.plugin.jfreechart.outputs.JFreeChartOutput.java

public String getMap(String mapName) {
    return ImageMapUtilities.getImageMap(mapName, info);
}

From source file:org.pentaho.platform.uifoundation.chart.XYSeriesCollectionChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    String contextPath = requestContext.getContextPath();

    setXslProperty("baseUrl", contextPath + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);

    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);//w w w . j a  v a2 s.  c om
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    XYSeriesCollection chartDataDefinition = (XYSeriesCollection) dataDefinition;
    if (chartDataDefinition.getSeriesCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        Element chartElement = root.addElement("chart"); //$NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
        for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) {
                Number value = chartDataDefinition.getY(row, column);
                Comparable rowKey = chartDataDefinition.getSeriesKey(row);
                Number columnKey = chartDataDefinition.getX(row, column);
                Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
                valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
        chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    }
    return result;
}

From source file:org.pentaho.platform.uifoundation.chart.XYZSeriesCollectionChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);

    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);//from  ww w . j  a  va  2 s.co m
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    XYZSeriesCollectionChartDefinition chartDataDefinition = (XYZSeriesCollectionChartDefinition) dataDefinition;
    if (chartDataDefinition.getSeriesCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        Element chartElement = root.addElement("chart"); //$NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
        for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) {
                Number value = chartDataDefinition.getY(row, column);
                Comparable rowKey = chartDataDefinition.getSeriesKey(row);
                Number columnKey = chartDataDefinition.getX(row, column);
                Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
                valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
        chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    }
    return result;
}

From source file:org.pentaho.platform.uifoundation.chart.PieDatasetChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();

    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);
    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);/*from w  w  w.j  a v a2s . c  o m*/
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);
    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/urlTemplate") != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/urlTemplate").getText(); //$NON-NLS-1$
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    DefaultPieDataset chartDataDefinition = (DefaultPieDataset) dataDefinition;
    // if (chartDataDefinition.getRowCount() > 0) {
    // create temporary file names
    String[] tempFileInfo = createTempFile();
    String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
    String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

    ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
            JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
    applyOuterURLTemplateParam();
    populateInfo(info);
    Element chartElement = root.addElement("chart"); //$NON-NLS-1$
    chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
    chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
    chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
    // for (int row = 0; row < chartDataDefinition.getRowCount(); row++) {
    // for (int column = 0; column < chartDataDefinition.getColumnCount();
    // column++) {
    // Number value = chartDataDefinition.getValue(row, column);
    // Comparable rowKey = chartDataDefinition.getRowKey(row);
    // Comparable columnKey = chartDataDefinition.getColumnKey(column);
    // Element valueElement = chartElement.addElement("value2D");
    // //$NON-NLS-1$
    // valueElement.addElement("value").setText(value.toString());
    // //$NON-NLS-1$
    // valueElement.addElement("row-key").setText(rowKey.toString());
    // //$NON-NLS-1$
    // valueElement.addElement("column-key").setText(columnKey.toString());
    // //$NON-NLS-1$
    // }
    // }
    String mapString = ImageMapUtilities.getImageMap(mapName, info);
    chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
    chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    // }
    return result;
}

From source file:org.pentaho.platform.uifoundation.chart.TimeSeriesCollectionChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);

    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);//from   w w w.  j  a va2  s .  co m
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    TimeSeriesCollection chartDataDefinition = (TimeSeriesCollection) dataDefinition;
    if (chartDataDefinition.getSeriesCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        Element chartElement = root.addElement("chart"); //$NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
        for (int row = 0; row < chartDataDefinition.getSeriesCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getItemCount(row); column++) {
                Number value = chartDataDefinition.getY(row, column);
                Comparable rowKey = chartDataDefinition.getSeriesKey(row);
                RegularTimePeriod columnKey = chartDataDefinition.getSeries(row).getTimePeriod(column);
                Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
                valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
        chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    }
    return result;
}

From source file:org.pentaho.platform.uifoundation.chart.CategoryDatasetChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$

    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);
    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);//from  w w  w  . j a va2 s  . c  o  m
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }
    // create a pie definition from the XML definition
    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
    } catch (NumberFormatException ignored) {
        // go with the default
    }
    try {
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (NumberFormatException ignored) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    DefaultCategoryDataset chartDataDefinition = (DefaultCategoryDataset) dataDefinition;
    if (chartDataDefinition.getRowCount() > 0) {
        // create temporary file names
        String[] tempFileInfo = createTempFile();
        String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
        String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
        applyOuterURLTemplateParam();
        populateInfo(info);
        Element chartElement = root.addElement("chart"); //$NON-NLS-1$
        chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
        chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
        chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
        for (int row = 0; row < chartDataDefinition.getRowCount(); row++) {
            for (int column = 0; column < chartDataDefinition.getColumnCount(); column++) {
                Number value = chartDataDefinition.getValue(row, column);
                Comparable rowKey = chartDataDefinition.getRowKey(row);
                Comparable columnKey = chartDataDefinition.getColumnKey(column);
                Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
                valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
                valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
                valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
            }
        }
        String mapString = ImageMapUtilities.getImageMap(mapName, info);
        chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
        chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    }
    return result;
}

From source file:org.pentaho.platform.uifoundation.chart.DialChartComponent.java

@Override
public Document getXmlContent() {

    // Create a document that describes the result
    Document result = DocumentHelper.createDocument();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    setXslProperty("baseUrl", requestContext.getContextPath()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    setXslProperty("fullyQualifiedServerUrl", //$NON-NLS-1$
            PentahoSystem.getApplicationContext().getFullyQualifiedServerURL()); //$NON-NLS-2$ //$NON-NLS-3$
    String mapName = "chart" + AbstractChartComponent.chartCount++; //$NON-NLS-1$
    Document chartDefinition = jcrHelper.getSolutionDocument(definitionPath, RepositoryFilePermission.READ);

    if (chartDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0001_CHART_DEFINIION_MISSING", //$NON-NLS-1$
                definitionPath);/*www . ja  v  a  2s  .c om*/
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        error(message);
        return result;
    }

    dataDefinition = createChart(chartDefinition);

    if (dataDefinition == null) {
        Element errorElement = result.addElement("error"); //$NON-NLS-1$
        errorElement.addElement("title").setText( //$NON-NLS-1$
                Messages.getInstance().getString("ABSTRACTCHARTEXPRESSION.ERROR_0001_ERROR_GENERATING_CHART")); //$NON-NLS-1$
        String message = Messages.getInstance().getString("CHARTS.ERROR_0002_CHART_DATA_MISSING", actionPath); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        errorElement.addElement("message").setText(message); //$NON-NLS-1$
        // System .out.println( result.asXML() );
        return result;
    }

    // create an image for the dial using the JFreeChart engine
    PrintWriter printWriter = new PrintWriter(new StringWriter());
    // we'll dispay the title in HTML so that the dial image does not have
    // to
    // accommodate it
    String chartTitle = ""; //$NON-NLS-1$
    try {
        if (width == -1) {
            width = Integer.parseInt(chartDefinition.selectSingleNode("/chart/width").getText()); //$NON-NLS-1$
        }
        if (height == -1) {
            height = Integer.parseInt(chartDefinition.selectSingleNode("/chart/height").getText()); //$NON-NLS-1$
        }
    } catch (Exception e) {
        // go with the default
    }
    if (chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) != null) { //$NON-NLS-1$
        urlTemplate = chartDefinition.selectSingleNode("/chart/" + AbstractChartComponent.URLTEMPLATE_NODE_NAME) //$NON-NLS-1$
                .getText();
    }

    if (chartDefinition.selectSingleNode("/chart/paramName") != null) { //$NON-NLS-1$
        paramName = chartDefinition.selectSingleNode("/chart/paramName").getText(); //$NON-NLS-1$
    }

    Element root = result.addElement("charts"); //$NON-NLS-1$
    DefaultValueDataset chartDataDefinition = (DefaultValueDataset) dataDefinition;

    // if (dataDefinition.getRowCount() > 0) {
    // create temporary file names
    String[] tempFileInfo = createTempFile();
    String fileName = tempFileInfo[AbstractChartComponent.FILENAME_INDEX];
    String filePathWithoutExtension = tempFileInfo[AbstractChartComponent.FILENAME_WITHOUT_EXTENSION_INDEX];

    ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
    JFreeChartEngine.saveChart(chartDataDefinition, chartTitle, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
            JFreeChartEngine.OUTPUT_PNG, printWriter, info, this);
    applyOuterURLTemplateParam();
    populateInfo(info);
    Element chartElement = root.addElement("chart"); //$NON-NLS-1$
    chartElement.addElement("mapName").setText(mapName); //$NON-NLS-1$
    chartElement.addElement("width").setText(Integer.toString(width)); //$NON-NLS-1$
    chartElement.addElement("height").setText(Integer.toString(height)); //$NON-NLS-1$
    // for (int row = 0; row < chartDataDefinition.getRowCount(); row++) {
    // for (int column = 0; column < chartDataDefinition.getColumnCount(); column++) {
    // Number value = chartDataDefinition.getValue(row, column);
    // Comparable rowKey = chartDataDefinition.getRowKey(row);
    // Comparable columnKey = chartDataDefinition.getColumnKey(column);
    //                    Element valueElement = chartElement.addElement("value2D"); //$NON-NLS-1$
    //                    valueElement.addElement("value").setText(value.toString()); //$NON-NLS-1$
    //                    valueElement.addElement("row-key").setText(rowKey.toString()); //$NON-NLS-1$
    //                    valueElement.addElement("column-key").setText(columnKey.toString()); //$NON-NLS-1$
    // }
    // }
    String mapString = ImageMapUtilities.getImageMap(mapName, info);
    chartElement.addElement("imageMap").setText(mapString); //$NON-NLS-1$
    chartElement.addElement("image").setText(fileName); //$NON-NLS-1$
    // }
    return result;
}