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,
        ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
        URLTagFragmentGenerator urlTagFragmentGenerator) 

Source Link

Document

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

Usage

From source file:org.webguitoolkit.ui.controls.chart.Chart.java

/**
 * generate the image an send the url to the client
 *///  ww w  . j a va 2s .co m
public void load() {
    HttpSession session = Page.getServletRequest().getSession(true);
    ChartRenderingInfo info = new ChartRenderingInfo();
    JFreeChart chart = getModel().getChart();
    if (chart == null)
        return; // happen for example in the init process

    try {
        String filename = ServletUtilities.saveChartAsPNG(chart, getWidth(), getHeight(), info, session);
        filename = URLEncoder.encode(filename, "UTF-8");
        String mapName = id4Map() + filename + ".name";
        String imagemap = ImageMapUtilities.getImageMap(mapName, info, new OverLIBToolTipTagFragmentGenerator(),
                null); // no urls   

        // transfer image map to clinet
        getContext().add(id4Map(), imagemap, IContext.TYPE_HTML, IContext.STATUS_NOT_EDITABLE);
        // the img-tag to use the map
        getContext().add(id4Img() + ".usemap", "#" + mapName, IContext.TYPE_ATT, IContext.STATUS_NOT_EDITABLE);
        // transfer src- atribute to client

        String imageUrl = "Chart/DisplayChart?filename=" + filename;
        getContext().add(id4Img() + ".src", imageUrl, IContext.TYPE_ATT, IContext.STATUS_NOT_EDITABLE);
    } catch (IOException e) {
        e.printStackTrace();
        throw new WGTException(e);
    }
}

From source file:org.toobsframework.pres.chart.controller.ChartHandler.java

/**
 * /*from w  w w. ja  va 2  s  . com*/
 * Retrieves the URL path to use for lookup and delegates to
 * <code>getViewNameForUrlPath</code>.
 * 
 * @throws Exception Exception fetching or rendering component.
 * @see #getViewNameForUrlPath
 * 
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response,
        UrlDispatchInfo dispatchInfo) throws Exception {

    String chartId = dispatchInfo.getResourceId();
    if (log.isDebugEnabled()) {
        log.debug("Rendering chart '" + chartId + "' for lookup path: " + dispatchInfo.getOriginalPath());
    }

    IRequest componentRequest = this.setupComponentRequest(dispatchInfo, request, response, true);

    Date startTime = null;
    if (log.isDebugEnabled()) {
        startTime = new Date();
    }

    JFreeChart chart = null;
    int height = 400;
    int width = 600;
    ChartDefinition chartDef = null;
    if (null != chartId && !chartId.equals("")) {
        try {
            request.setAttribute("chartId", chartId);
            chartDef = this.chartManager.getChartDefinition(chartId);
        } catch (ChartNotFoundException cnfe) {
            log.warn("Chart " + chartId + " not found.");
            throw cnfe;
        }
        try {

            chart = chartBuilder.build(chartDef, componentRequest);
            width = chartDef.getChartWidth();
            height = chartDef.getChartHeight();

        } catch (ChartException e) {
            Throwable t = e.rootCause();
            log.info("Root cause " + t.getClass().getName() + " " + t.getMessage());
            throw e;
        } catch (Exception e) {
            throw e;
        } finally {
            this.componentRequestManager.unset();
        }

    } else {
        throw new Exception("No chartId specified");
    }

    //Write out to the response.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0
    response.setHeader("Cache-Control", "max-age=0, must-revalidate"); // HTTP 1.1
    ChartRenderingInfo chartRenderingInfo = new ChartRenderingInfo();
    if (chartDef.doImageWithMap()) {
        response.setContentType("text/html; charset=UTF-8");
        String genFileName = chartDef.getId() + "-" + new Date().getTime() + ".png";
        String imageOutputFileName = configuration.getUploadDir() + genFileName;
        File imageOutputFile = new File(imageOutputFileName);
        OutputStream os = null;
        try {
            os = new FileOutputStream(imageOutputFile);
            ChartUtilities.writeChartAsPNG(os, chart, width, height, chartRenderingInfo);
        } finally {
            if (os != null) {
                os.close();
            }
        }
        PrintWriter writer = response.getWriter();
        StringBuffer sb = new StringBuffer();

        // TODO BUGBUG Chart location needs to fixed
        sb.append("<img id=\"chart-").append(chartDef.getId()).append("\" src=\"")
                .append(/*Configuration.getInstance().getMainContext() +*/ "/upload/" + genFileName)
                .append("\" ismap=\"ismap\" usemap=\"#").append(chartDef.getId()).append("Map\" />");
        URLTagFragmentGenerator urlGenerator;
        if (chartDef.getUrlFragmentBean() != null) {
            urlGenerator = (URLTagFragmentGenerator) beanFactory.getBean(chartDef.getUrlFragmentBean());
        } else {
            urlGenerator = new StandardURLTagFragmentGenerator();
        }
        sb.append(ImageMapUtilities.getImageMap(chartDef.getId() + "Map", chartRenderingInfo, null,
                urlGenerator));
        writer.print(sb.toString());
        writer.flush();

    } else {
        response.setContentType("image/png");

        ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, width, height, chartRenderingInfo);

    }

    if (log.isDebugEnabled()) {
        Date endTime = new Date();
        log.debug("Time [" + chartId + "] - " + (endTime.getTime() - startTime.getTime()));
    }
    return null;

}

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

private void writeImageHtml(int width, int height, int imgID, ChartRenderingInfo info) throws IOException {
    String tooltip = getParameter("tooltip");
    if (!StringUtils.hasValue(tooltip))
        tooltip = resources.getHTML("More_Detail_Here_Instruction");

    String href = getParameter("href");
    if (StringUtils.hasValue(href)) {
        // create a copy of the entity collection, and place an entity for
        // the entire chart at the beginning of the list.  This will
        // make it appear last in the image map (which is important,
        // because browsers process the image map areas in the order that
        // they appear; having the entire chart area listed first would
        // obscure all of the other image map areas).
        EntityCollection entities = new StandardEntityCollection();
        entities.add(new ChartEntity(info.getChartArea(), tooltip, href));
        if (info.getEntityCollection() != null)
            entities.addAll(info.getEntityCollection());

        // Next: most of our chart entities will not have URLs. URL values
        // don't inherit in the imagemap, so if we want the entire image
        // to have a single URL, we need to assign that URL to every
        // area in the chart.
        for (Iterator i = entities.iterator(); i.hasNext();) {
            ChartEntity ce = (ChartEntity) i.next();
            // check for no-op chart entity - these won't appear in the
            // image map anyway, so they don't need to be adjusted
            if (ce.getToolTipText() == null && ce.getURLText() == null)
                continue;
            // for other entities, add a tooltip and a URL as needed.
            if (!StringUtils.hasValue(ce.getToolTipText()))
                ce.setToolTipText(tooltip);
            if (!StringUtils.hasValue(ce.getURLText()))
                ce.setURLText(href);/*ww w  . j a  v  a 2  s  .c  om*/
        }

        // install our modified version of the entity collection into
        // the chart info object, so it will be used when generating
        // the image map later.
        info.setEntityCollection(entities);
    }

    // write the image tag
    out.write("<img width=\"" + width + "\" height=\"" + height + "\" src=\"/reports/pngCache?id=" + imgID
            + "\" usemap=\"#IMG" + imgID + '"');

    // imagemaps have hyperlink borders by default, even if we don't
    // have a URL we're pointing to.  Turn that border off.
    if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder"))
        out.write(" border=\"0\"");

    // Our client might want to add attributes to the image tag. Look
    // through the query parameters we received for arbitrary attributes
    // starting with the prefix "img", and copy them into the tag.
    for (Iterator i = parameters.entrySet().iterator(); i.hasNext();) {
        Map.Entry e = (Map.Entry) i.next();
        String attrName = (String) e.getKey();
        if (attrName.startsWith("img") && !attrName.endsWith("_ALL")) {
            out.write(" " + attrName.substring(3) + "=\"");
            out.write(HTMLUtils.escapeEntities(e.getValue().toString()));
            out.write('"');
        }
    }

    out.write(">");

    // finally, write the image map.  Note that we have to strip line
    // break characters from the resulting HTML, otherwise firefox seems
    // to decide that the <map> tag actually takes up space on the page
    String imageMapHtml = ImageMapUtilities.getImageMap("IMG" + imgID, info, getToolTipGenerator(tooltip),
            new StandardURLTagFragmentGenerator());
    for (int i = 0; i < imageMapHtml.length(); i++) {
        char c = imageMapHtml.charAt(i);
        if (c != '\r' && c != '\n')
            out.write(c);
    }
    out.flush();
}

From source file:org.pentaho.platform.plugin.action.jfreechart.ChartComponent.java

@Override
protected boolean executeAction() {
    int height = -1;
    int width = -1;
    String title = ""; //$NON-NLS-1$
    Node chartDocument = null;/* w w  w .  j a v  a 2s.  c o m*/
    IPentahoResultSet data = (IPentahoResultSet) getInputValue(ChartComponent.CHART_DATA_PROP);
    if (!data.isScrollable()) {
        getLogger().debug("ResultSet is not scrollable. Copying into memory"); //$NON-NLS-1$
        IPentahoResultSet memSet = data.memoryCopy();
        data.close();
        data = memSet;
    }

    String urlTemplate = (String) getInputValue(ChartComponent.URL_TEMPLATE);

    Node chartAttributes = null;
    String chartAttributeString = null;

    // Attempt to get chart attributes as an input string or as a resource file
    // If these don't trip, then we assume the chart attributes are defined in
    // the component-definition of the chart action.

    if (getInputNames().contains(ChartComponent.CHART_ATTRIBUTES_PROP)) {
        chartAttributeString = getInputStringValue(ChartComponent.CHART_ATTRIBUTES_PROP);
    } else if (isDefinedResource(ChartComponent.CHART_ATTRIBUTES_PROP)) {
        IActionSequenceResource resource = getResource(ChartComponent.CHART_ATTRIBUTES_PROP);
        chartAttributeString = getResourceAsString(resource);
    }

    // Realize chart attributes as an XML document
    if (chartAttributeString != null) {
        try {
            chartDocument = XmlDom4JHelper.getDocFromString(chartAttributeString, new PentahoEntityResolver());
        } catch (XmlParseException e) {
            getLogger().error(
                    Messages.getInstance().getString("ChartComponent.ERROR_0005_CANT_DOCUMENT_FROM_STRING"), e); //$NON-NLS-1$
            return false;
        }

        chartAttributes = chartDocument.selectSingleNode(ChartComponent.CHART_ATTRIBUTES_PROP);

        // This line of code handles a discrepancy between the schema of a chart definition
        // handed to a dashboard versus a ChartComponent schema. The top level node for the dashboard charts
        // is <chart>, whereas the ChartComponent expects <chart-attributes>.

        // TODO:
        // This discrepancy should be resolved when we have ONE chart solution.

        if (chartAttributes == null) {
            chartAttributes = chartDocument.selectSingleNode(ChartComponent.ALTERNATIVE_CHART_ATTRIBUTES_PROP);
        }
    }

    // Default chart attributes are in the component-definition section of the action definition.
    if (chartAttributes == null) {
        chartAttributes = getComponentDefinition(true).selectSingleNode(ChartComponent.CHART_ATTRIBUTES_PROP);
    }

    // URL click-through attributes (useBaseURL, target) are only processed IF we
    // have an urlTemplate attribute
    if ((urlTemplate == null) || (urlTemplate.length() == 0)) {
        if (chartAttributes.selectSingleNode(ChartComponent.URL_TEMPLATE) != null) {
            urlTemplate = chartAttributes.selectSingleNode(ChartComponent.URL_TEMPLATE).getText();
        }
    }

    // These parameters are replacement variables parsed into the
    // urlTemplate specifically when we have a URL that is a drill-through
    // link in a chart intended to drill down into the chart data.
    String parameterName = (String) getInputValue(ChartComponent.PARAMETER_NAME);
    if ((parameterName == null) || (parameterName.length() == 0)) {
        if (chartAttributes.selectSingleNode(ChartComponent.PARAMETER_NAME) != null) {
            parameterName = chartAttributes.selectSingleNode(ChartComponent.PARAMETER_NAME).getText();
        }
    }

    // These parameters are replacement variables parsed into the
    // urlTemplate specifically when we have a URL that is a drill-through
    // link in a chart intended to drill down into the chart data.
    String outerParameterName = (String) getInputValue(ChartComponent.OUTER_PARAMETER_NAME);
    if ((outerParameterName == null) || (outerParameterName.length() == 0)) {
        if (chartAttributes.selectSingleNode(ChartComponent.OUTER_PARAMETER_NAME) != null) {
            outerParameterName = chartAttributes.selectSingleNode(ChartComponent.OUTER_PARAMETER_NAME)
                    .getText();
        }
    }

    String chartType = chartAttributes.selectSingleNode(ChartDefinition.TYPE_NODE_NAME).getText();

    // --------------- This code allows inputs to override the chartAttributes
    // of width, height, and title
    Object widthObj = getInputValue(ChartDefinition.WIDTH_NODE_NAME);
    if (widthObj != null) {
        width = Integer.parseInt(widthObj.toString());
        if (width != -1) {
            if (chartAttributes.selectSingleNode(ChartDefinition.WIDTH_NODE_NAME) == null) {
                ((Element) chartAttributes).addElement(ChartDefinition.WIDTH_NODE_NAME);
            }
            chartAttributes.selectSingleNode(ChartDefinition.WIDTH_NODE_NAME).setText(Integer.toString(width));
        }
    }
    Object heightObj = getInputValue(ChartDefinition.HEIGHT_NODE_NAME);
    if (heightObj != null) {
        height = Integer.parseInt(heightObj.toString());
        if (height != -1) {
            if (chartAttributes.selectSingleNode(ChartDefinition.HEIGHT_NODE_NAME) == null) {
                ((Element) chartAttributes).addElement(ChartDefinition.HEIGHT_NODE_NAME);
            }
            chartAttributes.selectSingleNode(ChartDefinition.HEIGHT_NODE_NAME)
                    .setText(Integer.toString(height));
        }
    }
    Object titleObj = getInputValue(ChartDefinition.TITLE_NODE_NAME);
    if (titleObj != null) {
        if (chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME) == null) {
            ((Element) chartAttributes).addElement(ChartDefinition.TITLE_NODE_NAME);
        }
        chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME).setText(titleObj.toString());
    }
    // ----------------End of Override

    // ---------------Feed the Title and Subtitle information through the input substitution
    Node titleNode = chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME);
    if (titleNode != null) {
        String titleStr = titleNode.getText();
        if (titleStr != null) {
            title = titleStr;
            String newTitle = applyInputsToFormat(titleStr);
            titleNode.setText(newTitle);
        }
    }

    List subtitles = chartAttributes.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME);

    if ((subtitles == null) || (subtitles.isEmpty())) {
        Node subTitlesNode = chartAttributes.selectSingleNode(ChartDefinition.SUBTITLES_NODE_NAME);
        if (subTitlesNode != null) {
            subtitles = chartAttributes.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME);
        }
    } else {
        // log a deprecation warning for this property...
        getLogger().warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", //$NON-NLS-1$
                ChartDefinition.SUBTITLE_NODE_NAME, ChartDefinition.SUBTITLES_NODE_NAME));
        getLogger().warn(Messages.getInstance().getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", //$NON-NLS-1$
                ChartDefinition.SUBTITLE_NODE_NAME));
    }

    if (subtitles != null) {
        for (Iterator iter = subtitles.iterator(); iter.hasNext();) {
            Node subtitleNode = (Node) iter.next();
            if (subtitleNode != null) {
                String subtitleStr = subtitleNode.getText();
                if (subtitleStr != null) {
                    String newSubtitle = applyInputsToFormat(subtitleStr);
                    subtitleNode.setText(newSubtitle);
                }
            }
        }
    }

    // ----------------End of Format

    // Determine if we are going to read the chart data set by row or by column
    boolean byRow = false;
    if (getInputStringValue(ChartComponent.BY_ROW_PROP) != null) {
        byRow = Boolean.valueOf(getInputStringValue(ChartComponent.BY_ROW_PROP)).booleanValue();
    }

    // TODO Figure out why these overrides are called here. Seems like we are doing the same thing we just did above,
    // but
    // could possibly step on the height and width values set previously.

    if (height == -1) {
        height = (int) getInputLongValue(
                ChartComponent.CHART_ATTRIBUTES_PROP + "/" + ChartDefinition.HEIGHT_NODE_NAME, 50); //$NON-NLS-1$
    }
    if (width == -1) {
        width = (int) getInputLongValue(
                ChartComponent.CHART_ATTRIBUTES_PROP + "/" + ChartDefinition.WIDTH_NODE_NAME, 100); //$NON-NLS-1$      
    }

    if (title.length() <= 0) {
        title = getInputStringValue(
                ChartComponent.CHART_ATTRIBUTES_PROP + "/" + ChartDefinition.TITLE_NODE_NAME); //$NON-NLS-1$
    }

    // Select the right dataset to use based on the chart type
    // Default to category dataset
    String datasetType = ChartDefinition.CATEGORY_DATASET_STR;
    boolean isStacked = false;
    Node datasetTypeNode = chartAttributes.selectSingleNode(ChartDefinition.DATASET_TYPE_NODE_NAME);
    if (datasetTypeNode != null) {
        datasetType = datasetTypeNode.getText();
    }
    Dataset dataDefinition = null;
    if (ChartDefinition.XY_SERIES_COLLECTION_STR.equalsIgnoreCase(datasetType)) {
        dataDefinition = new XYSeriesCollectionChartDefinition(data, byRow, chartAttributes, getSession());
    } else if (ChartDefinition.TIME_SERIES_COLLECTION_STR.equalsIgnoreCase(datasetType)) {

        Node stackedNode = chartAttributes.selectSingleNode(ChartDefinition.STACKED_NODE_NAME);
        if (stackedNode != null) {
            isStacked = Boolean.valueOf(stackedNode.getText()).booleanValue();
        }
        if ((isStacked) && (ChartDefinition.AREA_CHART_STR.equalsIgnoreCase(chartType))) {
            dataDefinition = new TimeTableXYDatasetChartDefinition(data, byRow, chartAttributes, getSession());
        } else {
            dataDefinition = new TimeSeriesCollectionChartDefinition(data, byRow, chartAttributes,
                    getSession());
        }
    } else if (ChartDefinition.PIE_CHART_STR.equalsIgnoreCase(chartType)) {
        dataDefinition = new PieDatasetChartDefinition(data, byRow, chartAttributes, getSession());
    } else if (ChartDefinition.DIAL_CHART_STR.equalsIgnoreCase(chartType)) {
        dataDefinition = new DialWidgetDefinition(data, byRow, chartAttributes, width, height, getSession());
    } else if (ChartDefinition.BAR_LINE_CHART_STR.equalsIgnoreCase(chartType)) {
        dataDefinition = new BarLineChartDefinition(data, byRow, chartAttributes, getSession());
    } else if (ChartDefinition.BUBBLE_CHART_STR.equalsIgnoreCase(chartType)) {
        dataDefinition = new XYZSeriesCollectionChartDefinition(data, byRow, chartAttributes, getSession());
    } else {
        dataDefinition = new CategoryDatasetChartDefinition(data, byRow, chartAttributes, getSession());
    }

    // Determine what we are sending back - Default to OUTPUT_PNG output
    // OUTPUT_PNG = the chart gets written to a file in .png format
    // OUTPUT_SVG = the chart gets written to a file in .svg (XML) format
    // OUTPUT_CHART = the chart in a byte stream gets stored as as an IContentItem
    // OUTPUT_PNG_BYTES = the chart gets sent as a byte stream in .png format

    int outputType = JFreeChartEngine.OUTPUT_PNG;

    if (getInputStringValue(ChartComponent.OUTPUT_TYPE_PROP) != null) {
        if (ChartComponent.SVG_TYPE.equalsIgnoreCase(getInputStringValue(ChartComponent.OUTPUT_TYPE_PROP))) {
            outputType = JFreeChartEngine.OUTPUT_SVG;
        } else if (ChartComponent.CHART_TYPE
                .equalsIgnoreCase(getInputStringValue(ChartComponent.OUTPUT_TYPE_PROP))) {
            outputType = JFreeChartEngine.OUTPUT_CHART;
        } else if (ChartComponent.PNG_BYTES_TYPE
                .equalsIgnoreCase(getInputStringValue(ChartComponent.OUTPUT_TYPE_PROP))) {
            outputType = JFreeChartEngine.OUTPUT_PNG_BYTES;
        }
    }

    boolean keepTempFile = false;
    if (isDefinedInput(KEEP_TEMP_FILE_PROP)) {
        keepTempFile = getInputBooleanValue(KEEP_TEMP_FILE_PROP, false);
    }

    JFreeChart chart = null;

    switch (outputType) {

    /**************************** OUTPUT_PNG_BYTES *********************************************/
    case JFreeChartEngine.OUTPUT_PNG_BYTES:

        chart = JFreeChartEngine.getChart(dataDefinition, title, "", width, height, this); //$NON-NLS-1$

        // TODO Shouldn't the mime types and other strings here be constant somewhere? Where do we
        // put this type of general info ?

        String mimeType = "image/png"; //$NON-NLS-1$
        IContentItem contentItem = getOutputItem("chartdata", mimeType, ".png"); //$NON-NLS-1$ //$NON-NLS-2$
        contentItem.setMimeType(mimeType);
        try {

            OutputStream output = contentItem.getOutputStream(getActionName());
            ChartUtilities.writeChartAsPNG(output, chart, width, height);

        } catch (Exception e) {
            error(Messages.getInstance().getErrorString("ChartComponent.ERROR_0004_CANT_CREATE_IMAGE"), e); //$NON-NLS-1$
            return false;
        }

        break;

    /**************************** OUTPUT_SVG && OUTPUT_PNG *************************************/
    case JFreeChartEngine.OUTPUT_SVG:
        // intentionally fall through to PNG

    case JFreeChartEngine.OUTPUT_PNG:

        // Don't include the map in a file if HTML_MAPPING_HTML is specified, as that
        // param sends the map back on the outputstream as a string
        boolean createMapFile = !isDefinedOutput(ChartComponent.HTML_MAPPING_HTML);
        boolean hasTemplate = urlTemplate != null && urlTemplate.length() > 0;

        File[] fileResults = createTempFile(outputType, hasTemplate, !keepTempFile);

        if (fileResults == null) {
            error(Messages.getInstance().getErrorString("ChartComponent.ERROR_0003_CANT_CREATE_TEMP_FILES")); //$NON-NLS-1$
            return false;
        }

        String chartId = fileResults[ChartComponent.FILE_NAME].getName().substring(0,
                fileResults[ChartComponent.FILE_NAME].getName().indexOf('.'));
        String filePathWithoutExtension = ChartComponent.TEMP_DIRECTORY + chartId;
        PrintWriter printWriter = new PrintWriter(new StringWriter());
        ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

        JFreeChartEngine.saveChart(dataDefinition, title, "", filePathWithoutExtension, width, height, //$NON-NLS-1$
                outputType, printWriter, info, this);

        // Creating the image map
        boolean useBaseUrl = true;
        String urlTarget = "pentaho_popup"; //$NON-NLS-1$

        // Prepend the base url to the front of every drill through link
        if (chartAttributes.selectSingleNode(ChartComponent.USE_BASE_URL_TAG) != null) {
            Boolean booleanValue = new Boolean(
                    chartAttributes.selectSingleNode(ChartComponent.USE_BASE_URL_TAG).getText());
            useBaseUrl = booleanValue.booleanValue();
        }

        // What target for link? _parent, _blank, etc.
        if (chartAttributes.selectSingleNode(ChartComponent.URL_TARGET_TAG) != null) {
            urlTarget = chartAttributes.selectSingleNode(ChartComponent.URL_TARGET_TAG).getText();
        }

        String mapString = null;
        if (hasTemplate) {
            try {
                String mapId = fileResults[ChartComponent.MAP_NAME].getName().substring(0,
                        fileResults[ChartComponent.MAP_NAME].getName().indexOf('.'));
                mapString = ImageMapUtilities.getImageMap(mapId, info,
                        new StandardToolTipTagFragmentGenerator(),
                        new PentahoChartURLTagFragmentGenerator(urlTemplate, urlTarget, useBaseUrl,
                                dataDefinition, parameterName, outerParameterName));

                if (createMapFile) {
                    BufferedWriter out = new BufferedWriter(
                            new FileWriter(fileResults[ChartComponent.MAP_NAME]));
                    out.write(mapString);
                    out.flush();
                    out.close();
                }
            } catch (IOException e) {
                error(Messages.getInstance().getErrorString("ChartComponent.ERROR_0001_CANT_WRITE_MAP", //$NON-NLS-1$
                        fileResults[ChartComponent.MAP_NAME].getPath()));
                return false;
            } catch (Exception e) {
                error(e.getLocalizedMessage(), e);
                return false;
            }

        }

        /*******************************************************************************************************
         * Legitimate outputs for the ChartComponent in an action sequence:
         * 
         * CHART_OUTPUT (chart-output) Stores the chart in the content repository as an IContentItem.
         * 
         * CHART_FILE_NAME_OUTPUT (chart-filename) Returns the name of the chart file, including the file extension
         * (with no path information) as a String.
         * 
         * HTML_MAPPING_OUTPUT (chart-mapping) Returns the name of the file that the map has been saved to, including
         * the file extension (with no path information) as a String. Will be empty if url-template is undefined
         * 
         * HTML_MAPPING_HTML (chart-map-html) Returns the chart image map HTML as a String. Will be empty if
         * url-template is undefined
         * 
         * BASE_URL_OUTPUT (base-url) Returns the web app's base URL (ie., http://localhost:8080/pentaho) as a String.
         * 
         * HTML_IMG_TAG (image-tag) Returns the HTML snippet including the image map, image (<IMG />) tag for the chart
         * image with src, width, height and usemap attributes defined. Usemap will not be included if url-template is
         * undefined.
         * 
         *******************************************************************************************************/

        // Now set the outputs
        Set outputs = getOutputNames();

        if ((outputs != null) && (outputs.size() > 0)) {

            Iterator iter = outputs.iterator();
            while (iter.hasNext()) {

                String outputName = (String) iter.next();
                String outputValue = null;

                if (outputName.equals(ChartComponent.CHART_FILE_NAME_OUTPUT)) {

                    outputValue = fileResults[ChartComponent.FILE_NAME].getName();

                } else if (outputName.equals(ChartComponent.HTML_MAPPING_OUTPUT)) {
                    if (hasTemplate) {
                        outputValue = fileResults[ChartComponent.MAP_NAME].getName();
                    }
                } else if (outputName.equals(ChartComponent.HTML_MAPPING_HTML)) {

                    outputValue = mapString;

                } else if (outputName.equals(ChartComponent.BASE_URL_OUTPUT)) {
                    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
                    outputValue = requestContext.getContextPath();

                } else if (outputName.equals(ChartComponent.CONTEXT_PATH_OUTPUT)) {
                    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
                    outputValue = requestContext.getContextPath();
                } else if (outputName.equals(ChartComponent.FULLY_QUALIFIED_SERVER_URL_OUTPUT)) {

                    IApplicationContext applicationContext = PentahoSystem.getApplicationContext();
                    if (applicationContext != null) {
                        outputValue = applicationContext.getFullyQualifiedServerURL();
                    } else {
                        IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
                        outputValue = requestContext.getContextPath();
                    }
                } else if (outputName.equals(ChartComponent.HTML_IMG_TAG)) {

                    outputValue = hasTemplate ? mapString : ""; //$NON-NLS-1$

                    outputValue += "<img border=\"0\" "; //$NON-NLS-1$
                    outputValue += "width=\"" + width + "\" "; //$NON-NLS-1$//$NON-NLS-2$
                    outputValue += "height=\"" + height + "\" "; //$NON-NLS-1$//$NON-NLS-2$
                    if (hasTemplate) {
                        outputValue += "usemap=\"#" + fileResults[ChartComponent.MAP_NAME].getName().substring(
                                0, fileResults[ChartComponent.MAP_NAME].getName().indexOf('.')) + "\" "; //$NON-NLS-1$//$NON-NLS-2$
                    }
                    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
                    String contextPath = requestContext.getContextPath();
                    outputValue += "src=\"" + contextPath + "getImage?image=" //$NON-NLS-1$//$NON-NLS-2$
                            + fileResults[ChartComponent.FILE_NAME].getName() + "\"/>"; //$NON-NLS-1$

                }

                if (outputValue != null) {
                    setOutputValue(outputName, outputValue);
                }
            }
        }

        break;

    /************************** OUTPUT_CHART && DEFAULT *************************************/
    case JFreeChartEngine.OUTPUT_CHART:
        // intentionally fall through to default

    default:

        String chartName = ChartComponent.CHART_OUTPUT;
        if (isDefinedInput(ChartComponent.CHART_NAME_PROP)) {
            chartName = getInputStringValue(ChartComponent.CHART_NAME_PROP);
        }
        chart = JFreeChartEngine.getChart(dataDefinition, title, "", width, height, this); //$NON-NLS-1$
        setOutputValue(chartName, chart);

        break;
    }

    return true;
}