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:org.pentaho.platform.uifoundation.chart.DialWidgetDefinition.java

License:Open Source License

/**
 * Create a dial definition object from an XML document
 * /*ww  w .jav  a2  s .  c  o m*/
 * @param doc
 *          definition XML document
 * @return Dial definition object
 */
public static void createDial(final DialWidgetDefinition widgetDefinition, final Node dialNode, final int width,
        final int height, final IPentahoSession session) {

    Node node = dialNode.selectSingleNode("units"); //$NON-NLS-1$
    if (node != null) {
        String units = node.getText();
        widgetDefinition.setUnits(units);
    }

    // set the background Paint
    Paint paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("background-color")); //$NON-NLS-1$
    if (paint == null) {
        Element backgroundNode = (Element) dialNode.selectSingleNode("chart-background"); //$NON-NLS-1$
        if (backgroundNode != null) {
            String backgroundType = backgroundNode.attributeValue("type"); //$NON-NLS-1$
            if ("texture".equals(backgroundType)) { //$NON-NLS-1$
                paint = JFreeChartEngine.getTexturePaint(backgroundNode, width, height, session);
            } else if ("gradient".equals(backgroundType)) { //$NON-NLS-1$
                paint = JFreeChartEngine.getGradientPaint(backgroundNode, width, height);
            }
        }
    } else {
        // log a deprecation warning for background-color ...
        DialWidgetDefinition.getLogger().warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_PROPERTY", //$NON-NLS-1$
                "background-color", "chart-background")); //$NON-NLS-1$ //$NON-NLS-2$    
        DialWidgetDefinition.getLogger().warn(
                Messages.getInstance().getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "background-color")); //$NON-NLS-1$ //$NON-NLS-2$     
    }

    if (paint != null) {
        widgetDefinition.setChartBackgroundPaint(paint);
    }

    // set the dial background Paint
    paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("plot-background-color")); //$NON-NLS-1$
    if (paint == null) {
        Element backgroundNode = (Element) dialNode.selectSingleNode("plot-background"); //$NON-NLS-1$
        if (backgroundNode != null) {
            String backgroundType = backgroundNode.attributeValue("type"); //$NON-NLS-1$
            if ("texture".equals(backgroundType)) { //$NON-NLS-1$
                paint = JFreeChartEngine.getTexturePaint(backgroundNode, width, height, session);
            } else if ("gradient".equals(backgroundType)) { //$NON-NLS-1$
                paint = JFreeChartEngine.getGradientPaint(backgroundNode, width, height);
            }
        }
    } else {
        // log a deprecation warning for plot-background-color ...
        DialWidgetDefinition.getLogger().warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_PROPERTY", //$NON-NLS-1$
                "plot-background-color", "plot-background")); //$NON-NLS-1$ //$NON-NLS-2$    
        DialWidgetDefinition.getLogger().warn(Messages.getInstance()
                .getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "plot-background-color")); //$NON-NLS-1$ //$NON-NLS-2$     
    }

    if (paint != null) {
        widgetDefinition.setPlotBackgroundPaint(paint);
    }

    // set the needle Paint
    paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("needle-color")); //$NON-NLS-1$
    if (paint != null) {
        widgetDefinition.setNeedlePaint(paint);
    }

    // set the tick Paint
    paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("tick-color")); //$NON-NLS-1$
    if (paint != null) {
        widgetDefinition.setTickPaint(paint);
    }

    Node tmpNode = dialNode.selectSingleNode("tick-interval"); //$NON-NLS-1$
    if (tmpNode != null) {
        widgetDefinition.setTickSize(Integer.parseInt(dialNode.selectSingleNode("tick-interval").getText())); //$NON-NLS-1$
    }

    // set the value Paint
    paint = JFreeChartEngine.getPaint(dialNode.selectSingleNode("value-color")); //$NON-NLS-1$
    if (paint != null) {
        widgetDefinition.setValuePaint(paint);
    }

    // TODO get this from the XML document
    widgetDefinition.setDialShape(DialShape.CHORD);

    Node titleFontNode = dialNode.selectSingleNode("title-font"); //$NON-NLS-1$
    if (titleFontNode != null) {
        Node fontNode = titleFontNode.selectSingleNode("font"); //$NON-NLS-1$
        if (fontNode != null) {
            String titleFontStr = fontNode.getText().trim();
            if (!"".equals(titleFontStr)) { //$NON-NLS-1$
                Node titleFontSizeNode = titleFontNode.selectSingleNode("size"); //$NON-NLS-1$
                int size = titleFontSizeNode != null ? Integer.parseInt(titleFontSizeNode.getText()) : 12;
                widgetDefinition.setTitleFont(new Font(titleFontStr, Font.BOLD, size));
            }
        } else {
            String titleFontStr = titleFontNode.getText().trim();
            if (!"".equals(titleFontStr)) { //$NON-NLS-1$
                widgetDefinition.setTitleFont(new Font(titleFontStr, Font.ITALIC, 24));
            }
        }
    }

    Node valueFontNode = dialNode.selectSingleNode("domain-tick-font"); //$NON-NLS-1$
    if (valueFontNode != null) {
        Node fontNode = valueFontNode.selectSingleNode("font"); //$NON-NLS-1$
        if (fontNode != null) {
            String fontStr = fontNode.getText().trim();
            if (!"".equals(fontStr)) { //$NON-NLS-1$
                Node valueFontSizeNode = valueFontNode.selectSingleNode("size"); //$NON-NLS-1$
                int size = valueFontSizeNode != null ? Integer.parseInt(valueFontSizeNode.getText()) : 12;
                widgetDefinition.setValueFont(new Font(fontStr, Font.BOLD, size));
            }
        } else {
            String fontStr = valueFontNode.getText().trim();
            if (!"".equals(fontStr)) { //$NON-NLS-1$
                widgetDefinition.setValueFont(new Font(fontStr, Font.ITALIC, 24));
            }
        }
    }

    // set any intervals that are defined in the document

    // A list of interval nodes should not be allowed to exist as a child of the main XML element (for XML schema
    // to
    // be well constructed and validate the XML .
    // We have deprecated <interval> as a child of the main node , and now require an <intervals> parent node
    // under which <intervals> can exist.

    List intervals = dialNode.selectNodes("interval"); //$NON-NLS-1$

    if ((intervals == null) || (intervals.isEmpty())) {
        Node intervalsNode = dialNode.selectSingleNode("intervals"); //$NON-NLS-1$
        if (intervalsNode != null) {
            intervals = intervalsNode.selectNodes("interval"); //$NON-NLS-1$
        }
    } else {
        // log a deprecation warning for this property...
        DialWidgetDefinition.getLogger()
                .warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", "interval", "intervals")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$    
        DialWidgetDefinition.getLogger()
                .warn(Messages.getInstance().getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "interval")); //$NON-NLS-1$ //$NON-NLS-2$     
    }

    if (intervals != null) {

        Iterator intervalIterator = intervals.iterator();
        while (intervalIterator.hasNext()) {
            // get the interval node
            Node intervalNode = (Node) intervalIterator.next();

            // get the interval name
            String label = intervalNode.selectSingleNode("label").getText(); //$NON-NLS-1$

            // get the range of the interval
            double minimum = Double.parseDouble(intervalNode.selectSingleNode("minimum").getText()); //$NON-NLS-1$
            double maximum = Double.parseDouble(intervalNode.selectSingleNode("maximum").getText()); //$NON-NLS-1$
            Range range = new Range(minimum, maximum);

            Paint backgroundPaint = JFreeChartEngine.getPaint(intervalNode.selectSingleNode("color")); //$NON-NLS-1$
            if (backgroundPaint == null) {
                Element backgroundNode = (Element) intervalNode.selectSingleNode("interval-background"); //$NON-NLS-1$
                if (backgroundNode != null) {
                    String backgroundType = backgroundNode.attributeValue("type"); //$NON-NLS-1$
                    if ("texture".equals(backgroundType)) { //$NON-NLS-1$
                        backgroundPaint = JFreeChartEngine.getTexturePaint(backgroundNode, width, height,
                                session);
                    } else if ("gradient".equals(backgroundType)) { //$NON-NLS-1$
                        backgroundPaint = JFreeChartEngine.getGradientPaint(backgroundNode, width, height);
                    }
                }
            }

            // get the text color of the interval
            String textColor = intervalNode.selectSingleNode("text-color").getText(); //$NON-NLS-1$
            Stroke outlineStroke;
            if (intervalNode.selectSingleNode("stroke-width") != null) { //$NON-NLS-1$
                outlineStroke = new BasicStroke(
                        Float.parseFloat(intervalNode.selectSingleNode("stroke-width").getText())); //$NON-NLS-1$
            } else {
                outlineStroke = new BasicStroke();
            }
            Paint outlinePaint = JFreeChartEngine.getPaint(textColor);

            // create the interval object
            MeterInterval interval = new MeterInterval(label, range, outlinePaint, outlineStroke,
                    backgroundPaint);

            // add the interval to the widget
            widgetDefinition.addInterval(interval);
        }
    }

    // get the chart subtitles

    // A list of <subtitle> nodes should not be allowed to exist as a child of the main XML element (for XML schema
    // to
    // be well constructed and validate the XML .
    // We have deprecated <subtitle> as a child of the main node , and now require a <subtitles> parent node
    // under which <subtitle> can exist.

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

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

    if (subtitles != null) {
        widgetDefinition.addSubTitles(subtitles);
    }

}

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

License:Open Source License

/**
 * Creates a java.awt.Paint object from an XML node from the dial definition document
 * /*ww w  . ja v  a  2 s  .c  om*/
 * @param width
 *          of the chart
 * @param height
 *          of the chart
 * @param node
 *          XML Node from the dial definition
 * @return Paint object defined by the node
 */
public static Paint getPaint(final Node node, final int width, final int height,
        final IPentahoSession session) {
    if (node == null) {
        return null;
    }
    // TODO support gradient and texture paints
    if (null != node.selectSingleNode("gradient")) { //$NON-NLS-1$
        return JFreeChartEngine.getGradientPaint((node.selectSingleNode("gradient")), width, height); //$NON-NLS-1$
    } else if (null != node.selectSingleNode("texture")) { //$NON-NLS-1$
        return JFreeChartEngine.getTexturePaint((node.selectSingleNode("texture")), width, height, session); //$NON-NLS-1$
    } else {
        String htmlColor = node.getText();
        return JFreeChartEngine.getPaint(htmlColor);
    }

}

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

License:Open Source License

/**
 * Creates a java.awt.TexturePaint object from an XML node from the dial definition document
 * //from  w  w w . ja va2 s  .com
 * @param XML
 *          Node from the dial definition
 * @param width
 *          of the chart
 * @param height
 *          of the chart
 * @return Paint object defined by the node / public static Paint getTexturePaint( Node node, int width, int
 *         height ) {
 * 
 *         if( node == null ) { return null; } int rectWidth=width; int rectHeight=height; int x=0; int y=0; //
 *         Get Image try{ Node imageNode = node.selectSingleNode( "background-image" ); //$NON-NLS-1$ if(
 *         imageNode != null ) { String imageName = imageNode.getText().toString(); String fileName =
 *         PentahoSystem.getApplicationContext().getSolutionPath( imageName ); int offset = fileName.lastIndexOf(
 *         "." ); //$NON-NLS-1$ String type = offset == -1 ? "jpg" : fileName.substring(offset + 1);
 *         //$NON-NLS-1$
 * 
 *         BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB);
 * 
 *         ImageIO.write(image, type, new File( fileName ));
 * 
 *         Node rectangle= node.selectSingleNode("rectangle"); //$NON-NLS-1$ if( rectangle != null ) { Node
 *         tmpNode = rectangle.selectSingleNode("width"); //$NON-NLS-1$ if( tmpNode != null ) {
 *         rectWidth=Integer.parseInt(tmpNode.getText().toString().trim()); //$NON-NLS-1$ } tmpNode =
 *         rectangle.selectSingleNode("height"); //$NON-NLS-1$ if( tmpNode != null ) {
 *         rectHeight=Integer.parseInt(tmpNode.getText().toString().trim()); //$NON-NLS-1$ } tmpNode =
 *         rectangle.selectSingleNode("x"); //$NON-NLS-1$ if( tmpNode != null ) {
 *         x=Integer.parseInt(tmpNode.getText().toString().trim()); //$NON-NLS-1$ } tmpNode =
 *         rectangle.selectSingleNode("y"); //$NON-NLS-1$ if( tmpNode != null ) {
 *         y=Integer.parseInt(tmpNode.getText().toString().trim()); //$NON-NLS-1$ } }
 * 
 *         Rectangle2D rect = new Rectangle2D.Double(x,y,rectWidth,rectHeight);
 * 
 *         return new TexturePaint(image,rect); }
 * 
 *         }catch(Exception e){e.printStackTrace();} return null; }
 */
public static Font getFont(final Node fontNode) {
    Font font = null;
    if (fontNode != null) {
        String fontFamily = TextTitle.DEFAULT_FONT.getFamily();
        int fontStyle = Font.PLAIN;
        int fontSize = TextTitle.DEFAULT_FONT.getSize();

        Node fontFamilyNode = fontNode.selectSingleNode(JFreeChartEngine.FONT_FAMILY_NODE_NAME);
        if ((fontFamilyNode != null) && (fontFamilyNode.getText().length() > 0)) {
            fontFamily = fontFamilyNode.getText();
        }
        Node isBoldNode = fontNode.selectSingleNode(JFreeChartEngine.IS_BOLD_NODE_NAME);
        if (isBoldNode != null) {
            boolean bold = Boolean.valueOf(isBoldNode.getText()).booleanValue();
            if (bold) {
                fontStyle += Font.BOLD;
            }
        }
        Node isItalicNode = fontNode.selectSingleNode(JFreeChartEngine.IS_ITALIC_NODE_NAME);
        if (isItalicNode != null) {
            boolean italic = Boolean.valueOf(isItalicNode.getText()).booleanValue();
            if (italic) {
                fontStyle += Font.ITALIC;
            }
        }
        Node sizeNode = fontNode.selectSingleNode(JFreeChartEngine.SIZE_NODE_NAME);
        if ((sizeNode != null) && (sizeNode.getText().length() > 0)) {
            fontSize = Integer.parseInt(sizeNode.getText());
        }
        font = new Font(fontFamily, fontStyle, fontSize);
    }
    return font;
}

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

License:Open Source License

/**
 * @param gradientNode//ww  w  . jav a  2s.  co m
 *          root node that hold gradient information
 * @return a gradientPaint implementation of Paint
 */
public static Paint getGradientPaint(final Node gradientNode, final int width, final int height) {

    if (gradientNode == null) {
        return null;
    }
    float x1 = 0;
    float y1 = 0;
    float x2 = width;
    float y2 = height;

    if (gradientNode.selectSingleNode(JFreeChartEngine.X1_NODE_NAME) != null) {
        x1 = Float.parseFloat(gradientNode.selectSingleNode(JFreeChartEngine.X1_NODE_NAME).getText());
    }
    if (gradientNode.selectSingleNode(JFreeChartEngine.Y1_NODE_NAME) != null) {
        y1 = Float.parseFloat(gradientNode.selectSingleNode(JFreeChartEngine.Y1_NODE_NAME).getText());
    }
    if (gradientNode.selectSingleNode(JFreeChartEngine.X2_NODE_NAME) != null) {
        x2 = Float.parseFloat(gradientNode.selectSingleNode(JFreeChartEngine.X2_NODE_NAME).getText());
    }
    if (gradientNode.selectSingleNode(JFreeChartEngine.Y2_NODE_NAME) != null) {
        y2 = Float.parseFloat(gradientNode.selectSingleNode(JFreeChartEngine.Y2_NODE_NAME).getText());
    }
    Color color1 = JFreeChartEngine
            .getColor(gradientNode.selectSingleNode(JFreeChartEngine.COLOR1_NODE_NAME).getText());
    Color color2 = JFreeChartEngine
            .getColor(gradientNode.selectSingleNode(JFreeChartEngine.COLOR2_NODE_NAME).getText());
    boolean cyclic = false;
    if (gradientNode.selectSingleNode(JFreeChartEngine.CYCLIC_NODE_NAME) != null) {
        cyclic = Boolean.valueOf(gradientNode.selectSingleNode(JFreeChartEngine.CYCLIC_NODE_NAME).getText())
                .booleanValue();
    }

    Paint paint = new GradientPaint(x1, y1, color1, x2, y2, color2, cyclic);
    return paint;
}

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

License:Open Source License

/**
 * @param textureNode//from  ww w .  j  a  va 2s .  com
 *          root node that holds texture information
 * @return
 */
public static Paint getTexturePaint(final Node textureNode, final int width, final int height,
        final IPentahoSession session) {

    if (textureNode == null) {
        return null;
    }
    double x1 = 0.0;
    double y1 = 0.0;
    double x2 = width;
    double y2 = height;
    BufferedImage texture = (BufferedImage) JFreeChartEngine
            .getImage(textureNode.selectSingleNode(JFreeChartEngine.TEXTURE_IMAGE_NODE_NAME), session);
    if (textureNode.selectSingleNode(JFreeChartEngine.X1_NODE_NAME) != null) {
        x1 = Double.parseDouble(textureNode.selectSingleNode(JFreeChartEngine.X1_NODE_NAME).getText());
    }
    if (textureNode.selectSingleNode(JFreeChartEngine.Y1_NODE_NAME) != null) {
        y1 = Double.parseDouble(textureNode.selectSingleNode(JFreeChartEngine.Y1_NODE_NAME).getText());
    }
    if (textureNode.selectSingleNode(JFreeChartEngine.X2_NODE_NAME) != null) {
        x2 = Double.parseDouble(textureNode.selectSingleNode(JFreeChartEngine.X2_NODE_NAME).getText());
    }
    if (textureNode.selectSingleNode(JFreeChartEngine.Y2_NODE_NAME) != null) {
        y2 = Double.parseDouble(textureNode.selectSingleNode(JFreeChartEngine.Y2_NODE_NAME).getText());
    }
    Rectangle2D anchor = new Rectangle2D.Double(x1, y1, x2, y2);

    Paint paint = new TexturePaint(texture, anchor);
    return paint;
}

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

License:Open Source License

@Override
public Dataset createChart(final Document doc) {
    if (actionPath != null) { // if we have a solution then get the values
        values = getActionData();/*from w  ww .  j  av a2 s.  c o m*/
    }

    if (values == null) {
        // we could not get any data
        return null;
    }

    // get the chart node from the document
    Node chartAttributes = doc.selectSingleNode("//" + AbstractChartComponent.CHART_NODE_NAME); //$NON-NLS-1$
    // create the definition
    PieDatasetChartDefinition chartDefinition = new PieDatasetChartDefinition((IPentahoResultSet) values, byRow,
            chartAttributes, getSession());

    setTitle(chartDefinition.getTitle());

    // get the URL template
    Node urlTemplateNode = chartAttributes.selectSingleNode(AbstractChartComponent.URLTEMPLATE_NODE_NAME);
    if (urlTemplateNode != null) {
        setUrlTemplate(urlTemplateNode.getText());
    }

    // get the additional parameter
    Node paramName2Node = chartAttributes.selectSingleNode(AbstractChartComponent.PARAM2_NODE_NAME);
    if (paramName2Node != null) {
        paramName2 = paramName2Node.getText();
    }

    if (width == -1) {
        setWidth(chartDefinition.getWidth());
    }
    if (height == -1) {
        setHeight(chartDefinition.getHeight());
    }

    return chartDefinition;
}

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

License:Open Source License

private void setChartAttributes(final Node chartAttributes) {
    if (chartAttributes == null) {
        return;//from  www .j a va2 s.c  o m
    }
    // set the chart background
    setChartBackground(chartAttributes.selectSingleNode(ChartDefinition.CHART_BACKGROUND_NODE_NAME));

    // set the plot background
    setPlotBackground(chartAttributes.selectSingleNode(ChartDefinition.PLOT_BACKGROUND_NODE_NAME));

    // do we want a legend
    setLegendIncluded(chartAttributes.selectSingleNode(ChartDefinition.INCLUDE_LEGEND_NODE_NAME));

    // get the chart title
    setTitle(chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME));

    Node backgroundAlphaNode = chartAttributes.selectSingleNode(ChartDefinition.BACKGROUND_ALPHA_NODE_NAME);
    Node foregroundAlphaNode = chartAttributes.selectSingleNode(ChartDefinition.FOREGROUND_ALPHA_NODE_NAME);

    if (backgroundAlphaNode != null) {
        setBackgroundAlpha(chartAttributes.selectSingleNode(ChartDefinition.BACKGROUND_ALPHA_NODE_NAME));
    }
    if (foregroundAlphaNode != null) {
        setForegroundAlpha(chartAttributes.selectSingleNode(ChartDefinition.FOREGROUND_ALPHA_NODE_NAME));
    }
    // get the chart subtitles

    // A list of <subtitle> nodes should not be allowed to exist as a child of the main XML element (for XML schema
    // to
    // be well constructed and validate the XML .
    // We have deprecated <subtitle> as a child of the main node , and now require a <subtitles> parent node
    // under which <subtitle> can exist.

    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 = subTitlesNode.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME);
        }
    } else {
        // log a deprecation warning for this property...
        PieDatasetChartDefinition.getLogger()
                .warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", //$NON-NLS-1$
                        ChartDefinition.SUBTITLE_NODE_NAME, ChartDefinition.SUBTITLES_NODE_NAME));
        PieDatasetChartDefinition.getLogger().warn(Messages.getInstance()
                .getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", ChartDefinition.SUBTITLE_NODE_NAME)); //$NON-NLS-1$  
    }

    if (subtitles != null) {
        addSubTitles(subtitles);
    }

    // get the chart's exploded sections

    List slicesNodes = null;
    Node slicesNode = chartAttributes.selectSingleNode(PieDatasetChartDefinition.EXPLODE_SLICE_NODE_NAME);
    if (slicesNode != null) {
        slicesNodes = slicesNode.selectNodes(PieDatasetChartDefinition.SLICE_NODE_NAME);
    }

    if (slicesNodes != null) {
        addExplodedSlices(slicesNodes);
    }

    // get the paint sequence
    setPaintSequence(chartAttributes.selectSingleNode(ChartDefinition.PALETTE_NODE_NAME));

    // get the 3D value
    setThreeD(chartAttributes.selectSingleNode(ChartDefinition.THREED_NODE_NAME));

    // set the width
    setWidth(chartAttributes.selectSingleNode(ChartDefinition.WIDTH_NODE_NAME));

    // set the height
    setHeight(chartAttributes.selectSingleNode(ChartDefinition.HEIGHT_NODE_NAME));

    // set the border on or off
    setBorderVisible(chartAttributes.selectSingleNode(ChartDefinition.CHART_BORDER_VISIBLE_NODE_NAME));

    // set the border Paint
    setBorderPaint(JFreeChartEngine
            .getPaint(chartAttributes.selectSingleNode(ChartDefinition.CHART_BORDER_PAINT_NODE_NAME)));

    // set the title location
    setTitlePosition(chartAttributes.selectSingleNode(ChartDefinition.TITLE_POSITION_NODE_NAME));

    // set the title font
    setTitleFont(chartAttributes.selectSingleNode(ChartDefinition.TITLE_FONT_NODE_NAME));

    // set the interior gap
    setInteriorGap(chartAttributes.selectSingleNode(PieDatasetChartDefinition.INTERIOR_GAP_NODE_NAME));

    // set the start angle
    setStartAngle(chartAttributes.selectSingleNode(PieDatasetChartDefinition.START_ANGLE_NODE_NAME));

    // set if we want labels
    setDisplayLabels(chartAttributes.selectSingleNode(ChartDefinition.DISPLAY_LABELS_NODE_NAME));

    // set the label font
    setLabelFont(chartAttributes.selectSingleNode(PieDatasetChartDefinition.LABEL_FONT_NODE_NAME));

    // set the label paint
    setLabelPaint(JFreeChartEngine
            .getPaint(chartAttributes.selectSingleNode(PieDatasetChartDefinition.LABEL_PAINT_NODE_NAME)));

    // set the label background paint
    setLabelBackgroundPaint(JFreeChartEngine.getPaint(
            chartAttributes.selectSingleNode(PieDatasetChartDefinition.LABEL_BACKGROUND_PAINT_NODE_NAME)));

    // set the label gap
    setLabelGap(chartAttributes.selectSingleNode(PieDatasetChartDefinition.LABEL_GAP_NODE_NAME));

    // set legend font
    setLegendFont(chartAttributes.selectSingleNode(ChartDefinition.LEGEND_FONT_NODE_NAME));

    // set legend border visible
    setLegendBorderVisible(chartAttributes.selectSingleNode(ChartDefinition.DISPLAY_LEGEND_BORDER_NODE_NAME));

    setLegendPosition(chartAttributes.selectSingleNode(ChartDefinition.LEGEND_POSITION_NODE_NAME));
}

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

License:Open Source License

@Override
public Dataset createChart(final Document doc) {
    if (actionPath != null) { // if we have a solution then get the values
        values = getActionData();//  w ww  . ja v a  2  s . c om
    }

    if (values == null) {
        // we could not get any data
        return null;
    }
    // get the chart node from the document
    Node chartAttributes = doc.selectSingleNode("//" + AbstractChartComponent.CHART_NODE_NAME); //$NON-NLS-1$
    // create the definition
    TimeSeriesCollectionChartDefinition chartDefinition = new TimeSeriesCollectionChartDefinition(
            (IPentahoResultSet) values, byRow, chartAttributes, getSession());

    // set the misc values from chartDefinition
    setChartType(chartDefinition.getChartType());
    setTitle(chartDefinition.getTitle());

    // get the URL template
    Node urlTemplateNode = chartAttributes.selectSingleNode(AbstractChartComponent.URLTEMPLATE_NODE_NAME);
    if (urlTemplateNode != null) {
        setUrlTemplate(urlTemplateNode.getText());
    }

    // get the additional parameter
    Node paramName2Node = chartAttributes.selectSingleNode(AbstractChartComponent.PARAM2_NODE_NAME);
    if (paramName2Node != null) {
        seriesName = paramName2Node.getText();
    }

    if ((chartDefinition.getWidth() != -1) && (width == -1)) {
        setWidth(chartDefinition.getWidth());
    }
    if ((chartDefinition.getHeight() != -1) && (height == -1)) {
        setHeight(chartDefinition.getHeight());
    }

    return chartDefinition;
}

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

License:Open Source License

private void setChartAttributes(final Node chartAttributes) {
    if (chartAttributes == null) {
        return;//from   w w w.java 2 s .c o  m
    }
    // get the chart type from the chart node -- this overrides the current
    // chart type
    setChartType(chartAttributes.selectSingleNode(ChartDefinition.TYPE_NODE_NAME));

    // set the chart background
    setChartBackground(chartAttributes.selectSingleNode(ChartDefinition.CHART_BACKGROUND_NODE_NAME));

    // set the plot background
    setPlotBackground(chartAttributes.selectSingleNode(ChartDefinition.PLOT_BACKGROUND_NODE_NAME));

    // set the orientation
    setOrientation(chartAttributes.selectSingleNode(XYChartDefinition.ORIENTATION_NODE_NAME));

    // do we want a legend
    setLegendIncluded(chartAttributes.selectSingleNode(ChartDefinition.INCLUDE_LEGEND_NODE_NAME));

    // get the chart title
    setTitle(chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME));

    // A list of <subtitle> nodes should not be allowed to exist as a child of the main XML element (for XML schema
    // to
    // be well constructed and validate the XML .
    // We have deprecated <subtitle> as a child of the main node , and now require a <subtitles> parent node
    // under which <subtitle> can exist.

    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 = subTitlesNode.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) {
        addSubTitles(subtitles);
    }

    // get the paint sequence
    setPaintSequence(chartAttributes.selectSingleNode(ChartDefinition.PALETTE_NODE_NAME));
    Node backgroundAlphaNode = chartAttributes.selectSingleNode(ChartDefinition.BACKGROUND_ALPHA_NODE_NAME);
    Node foregroundAlphaNode = chartAttributes.selectSingleNode(ChartDefinition.FOREGROUND_ALPHA_NODE_NAME);

    if (backgroundAlphaNode != null) {
        setBackgroundAlpha(chartAttributes.selectSingleNode(ChartDefinition.BACKGROUND_ALPHA_NODE_NAME));
    }
    if (foregroundAlphaNode != null) {
        setForegroundAlpha(chartAttributes.selectSingleNode(ChartDefinition.FOREGROUND_ALPHA_NODE_NAME));
    }
    // get the stacked value
    setStacked(chartAttributes.selectSingleNode(ChartDefinition.STACKED_NODE_NAME));

    // get the 3D value
    setThreeD(chartAttributes.selectSingleNode(ChartDefinition.THREED_NODE_NAME));

    // set the width
    setWidth(chartAttributes.selectSingleNode(ChartDefinition.WIDTH_NODE_NAME));

    // set the height
    setHeight(chartAttributes.selectSingleNode(ChartDefinition.HEIGHT_NODE_NAME));

    // set the dot width
    setDotWidth(chartAttributes.selectSingleNode(ChartDefinition.DOT_WIDTH_NODE_NAME));

    // set the dot height
    setDotHeight(chartAttributes.selectSingleNode(ChartDefinition.DOT_HEIGHT_NODE_NAME));

    // set vertical tick labels flag
    setDomainVerticalTickLabels(
            chartAttributes.selectSingleNode(XYChartDefinition.DOMAIN_VERTICAL_TICK_LABELS_NODE_NAME));

    // set the border on or off
    setBorderVisible(chartAttributes.selectSingleNode(ChartDefinition.CHART_BORDER_VISIBLE_NODE_NAME));

    // set the border Paint
    setBorderPaint(JFreeChartEngine
            .getPaint(chartAttributes.selectSingleNode(XYChartDefinition.CHART_BORDER_PAINT_NODE_NAME)));

    // set the title location
    setTitlePosition(chartAttributes.selectSingleNode(ChartDefinition.TITLE_POSITION_NODE_NAME));

    // set the legend location
    setLegendPosition(chartAttributes.selectSingleNode(ChartDefinition.LEGEND_POSITION_NODE_NAME));

    // set the title font
    setTitleFont(chartAttributes.selectSingleNode(ChartDefinition.TITLE_FONT_NODE_NAME));

    // set the domain title
    setDomainTitle(chartAttributes.selectSingleNode(XYChartDefinition.DOMAIN_TITLE_NODE_NAME));

    // set the domain font
    setDomainTitleFont(chartAttributes.selectSingleNode(XYChartDefinition.DOMAIN_TITLE_FONT_NODE_NAME));

    // set the range title
    setRangeTitle(chartAttributes.selectSingleNode(XYChartDefinition.RANGE_TITLE_NODE_NAME));

    // the the range font
    setRangeTitleFont(chartAttributes.selectSingleNode(XYChartDefinition.RANGE_TITLE_FONT_NODE_NAME));

    // set the range minimum
    setRangeMinimum(chartAttributes.selectSingleNode(XYChartDefinition.RANGE_MINIMUM_NODE_NAME));

    // set the range minimum
    setRangeMaximum(chartAttributes.selectSingleNode(XYChartDefinition.RANGE_MAXIMUM_NODE_NAME));

    // set the date minimum
    setDateMinimum(
            chartAttributes.selectSingleNode(TimeSeriesCollectionChartDefinition.DATE_MINIMUM_NODE_NAME));

    // set the date minimum
    setDateMaximum(
            chartAttributes.selectSingleNode(TimeSeriesCollectionChartDefinition.DATE_MAXIMUM_NODE_NAME));

    // set the Period type
    setDomainPeriodType(chartAttributes.selectSingleNode(XYChartDefinition.DOMAIN_PERIOD_TYPE_NODE_NAME));

    // set the line style
    setLineStyle(chartAttributes.selectSingleNode(ChartDefinition.LINE_STYLE_NODE_NAME));

    // set the line width
    setLineWidth(chartAttributes.selectSingleNode(ChartDefinition.LINE_WIDTH_NODE_NAME));

    // set the marker visibility
    setMarkersVisible(chartAttributes.selectSingleNode(ChartDefinition.MARKER_VISIBLE_NODE_NAME));

    // set legend font
    setLegendFont(chartAttributes.selectSingleNode(ChartDefinition.LEGEND_FONT_NODE_NAME));

    // set legend border visible
    setLegendBorderVisible(chartAttributes.selectSingleNode(ChartDefinition.DISPLAY_LEGEND_BORDER_NODE_NAME));

    setTooltipContent(chartAttributes.selectSingleNode(XYChartDefinition.TOOLTIP_CONTENT_NODE_NAME));

    setTooltipYFormat(chartAttributes.selectSingleNode(XYChartDefinition.TOOLTIP_Y_FORMAT_NODE_NAME));

    setTooltipXFormat(chartAttributes.selectSingleNode(XYChartDefinition.TOOLTIP_X_FORMAT_NODE_NAME));
}

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

License:Open Source License

private void setChartAttributes(final Node chartAttributes) {
    if (chartAttributes == null) {
        return;/*  www  .  j a v a2s . co m*/
    }
    // get the chart type from the chart node -- this overrides the current
    // chart type
    setChartType(chartAttributes.selectSingleNode(ChartDefinition.TYPE_NODE_NAME));

    // set the chart background
    setChartBackground(chartAttributes.selectSingleNode(ChartDefinition.CHART_BACKGROUND_NODE_NAME));

    // set the plot background
    setPlotBackground(chartAttributes.selectSingleNode(ChartDefinition.PLOT_BACKGROUND_NODE_NAME));

    // set the orientation
    setOrientation(chartAttributes.selectSingleNode(XYChartDefinition.ORIENTATION_NODE_NAME));

    // do we want a legend
    setLegendIncluded(chartAttributes.selectSingleNode(ChartDefinition.INCLUDE_LEGEND_NODE_NAME));

    // get the chart title
    setTitle(chartAttributes.selectSingleNode(ChartDefinition.TITLE_NODE_NAME));

    Node backgroundAlphaNode = chartAttributes.selectSingleNode(ChartDefinition.BACKGROUND_ALPHA_NODE_NAME);
    Node foregroundAlphaNode = chartAttributes.selectSingleNode(ChartDefinition.FOREGROUND_ALPHA_NODE_NAME);

    if (backgroundAlphaNode != null) {
        setBackgroundAlpha(chartAttributes.selectSingleNode(ChartDefinition.BACKGROUND_ALPHA_NODE_NAME));
    }
    if (foregroundAlphaNode != null) {
        setForegroundAlpha(chartAttributes.selectSingleNode(ChartDefinition.FOREGROUND_ALPHA_NODE_NAME));
    }
    // get the chart subtitles

    // A list of <subtitle> nodes should not be allowed to exist as a child of the main XML element (for XML schema
    // to
    // be well constructed and validate the XML .
    // We have deprecated <subtitle> as a child of the main node , and now require a <subtitles> parent node
    // under which <subtitle> can exist.

    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 = subTitlesNode.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME);
        }
    } else {
        // log a deprecation warning for this property...
        TimeTableXYDatasetChartDefinition.getLogger()
                .warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", //$NON-NLS-1$
                        ChartDefinition.SUBTITLE_NODE_NAME, ChartDefinition.SUBTITLES_NODE_NAME));
        TimeTableXYDatasetChartDefinition.getLogger().warn(Messages.getInstance()
                .getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", ChartDefinition.SUBTITLE_NODE_NAME)); //$NON-NLS-1$  
    }

    if (subtitles != null) {
        addSubTitles(subtitles);
    }

    // get the paint sequence
    setPaintSequence(chartAttributes.selectSingleNode(ChartDefinition.PALETTE_NODE_NAME));

    // get the stacked value
    setStacked(chartAttributes.selectSingleNode(ChartDefinition.STACKED_NODE_NAME));

    // get the 3D value
    setThreeD(chartAttributes.selectSingleNode(ChartDefinition.THREED_NODE_NAME));

    // set the width
    setWidth(chartAttributes.selectSingleNode(ChartDefinition.WIDTH_NODE_NAME));

    // set the height
    setHeight(chartAttributes.selectSingleNode(ChartDefinition.HEIGHT_NODE_NAME));

    // set the dot width
    setDotWidth(chartAttributes.selectSingleNode(ChartDefinition.DOT_WIDTH_NODE_NAME));

    // set the dot height
    setDotHeight(chartAttributes.selectSingleNode(ChartDefinition.DOT_HEIGHT_NODE_NAME));

    // set vertical tick labels flag
    setDomainVerticalTickLabels(
            chartAttributes.selectSingleNode(XYChartDefinition.DOMAIN_VERTICAL_TICK_LABELS_NODE_NAME));

    // set the border on or off
    setBorderVisible(chartAttributes.selectSingleNode(ChartDefinition.CHART_BORDER_VISIBLE_NODE_NAME));

    // set the border Paint
    setBorderPaint(JFreeChartEngine
            .getPaint(chartAttributes.selectSingleNode(XYChartDefinition.CHART_BORDER_PAINT_NODE_NAME)));

    // set the title location
    setTitlePosition(chartAttributes.selectSingleNode(ChartDefinition.TITLE_POSITION_NODE_NAME));

    // set the title font
    setTitleFont(chartAttributes.selectSingleNode(ChartDefinition.TITLE_FONT_NODE_NAME));

    // set the domain title
    setDomainTitle(chartAttributes.selectSingleNode(XYChartDefinition.DOMAIN_TITLE_NODE_NAME));

    // set the domain font
    setDomainTitleFont(chartAttributes.selectSingleNode(XYChartDefinition.DOMAIN_TITLE_FONT_NODE_NAME));

    // set the range title
    setRangeTitle(chartAttributes.selectSingleNode(XYChartDefinition.RANGE_TITLE_NODE_NAME));

    // the the range font
    setRangeTitleFont(chartAttributes.selectSingleNode(XYChartDefinition.RANGE_TITLE_FONT_NODE_NAME));

    // set the range minimum
    setRangeMinimum(chartAttributes.selectSingleNode(XYChartDefinition.RANGE_MINIMUM_NODE_NAME));

    // set the Period type
    setDomainPeriodType(chartAttributes.selectSingleNode(XYChartDefinition.DOMAIN_PERIOD_TYPE_NODE_NAME));

    // set the line style
    setLineStyle(chartAttributes.selectSingleNode(ChartDefinition.LINE_STYLE_NODE_NAME));

    // set the line width
    setLineWidth(chartAttributes.selectSingleNode(ChartDefinition.LINE_WIDTH_NODE_NAME));

    // set the marker visibility
    setMarkersVisible(chartAttributes.selectSingleNode(ChartDefinition.MARKER_VISIBLE_NODE_NAME));

    // set legend font
    setLegendFont(chartAttributes.selectSingleNode(ChartDefinition.LEGEND_FONT_NODE_NAME));

    // set legend border visible
    setLegendBorderVisible(chartAttributes.selectSingleNode(ChartDefinition.DISPLAY_LEGEND_BORDER_NODE_NAME));

    // set the legend position
    setLegendPosition(chartAttributes.selectSingleNode(ChartDefinition.LEGEND_POSITION_NODE_NAME));

    setTooltipContent(chartAttributes.selectSingleNode(XYChartDefinition.TOOLTIP_CONTENT_NODE_NAME));

    setTooltipYFormat(chartAttributes.selectSingleNode(XYChartDefinition.TOOLTIP_Y_FORMAT_NODE_NAME));

    setTooltipXFormat(chartAttributes.selectSingleNode(XYChartDefinition.TOOLTIP_X_FORMAT_NODE_NAME));

}