List of usage examples for org.dom4j Node selectSingleNode
Node selectSingleNode(String xpathExpression);
selectSingleNode
evaluates an XPath expression and returns the result as a single Node
instance.
From source file:org.pentaho.platform.repository.subscription.SubscriptionRepository.java
License:Open Source License
public Element importSchedules(final Document doc) { Element resultElement = DocumentHelper.createElement("importSchedulesResults"); //$NON-NLS-1$ if (doc == null) { Element ele = resultElement.addElement("message") //$NON-NLS-1$ .addText(Messages.getString("PRO_SUBSCRIPTREP.DOCUMENT_IS_NULL")); //$NON-NLS-1$ ele.addAttribute("result", "ERROR"); //$NON-NLS-1$ //$NON-NLS-2$ return (resultElement); }//from w w w.jav a 2 s .c om List scheduleNodes = doc.selectNodes("//schedules/*"); //$NON-NLS-1$ if (scheduleNodes.size() == 0) { Element ele = resultElement.addElement("message") //$NON-NLS-1$ .addText(Messages.getString("PRO_SUBSCRIPTREP.NO_SCHEDULES_DEFINED")); //$NON-NLS-1$ ele.addAttribute("result", "WARNING"); //$NON-NLS-1$ //$NON-NLS-2$ return (resultElement); } synchronized (SubscriptionRepository.SyncLock) { Node scheduleNode = null; String schedName, schedDesc, schedRef, cronString, schedGroup; ISchedule aSchedule; // List schedList; try { SubscriptionRepository.logger .info(Messages.getString("PRO_SUBSCRIPTREP.USER_IMPORT_PROCESSING_SCHEDULES", //$NON-NLS-1$ Integer.toString(scheduleNodes.size()))); for (int i = 0; i < scheduleNodes.size(); i++) { scheduleNode = (Node) scheduleNodes.get(i); schedRef = scheduleNode.selectSingleNode("@ref").getText(); //$NON-NLS-1$ schedName = scheduleNode.selectSingleNode("@name").getText(); //$NON-NLS-1$ schedDesc = scheduleNode.selectSingleNode("@description").getText(); //$NON-NLS-1$ schedGroup = scheduleNode.selectSingleNode("@group").getText(); //$NON-NLS-1$ cronString = scheduleNode.getText(); try { aSchedule = getScheduleByScheduleReference(schedRef); if (aSchedule != null) { aSchedule.setCronString(cronString); aSchedule.setDescription(schedDesc); aSchedule.setGroup(schedGroup); aSchedule.setTitle(schedName); resultElement.addElement("modified").addText(schedRef); //$NON-NLS-1$ SubscriptionRepository.logger.info(Messages .getString("PRO_SUBSCRIPTREP.MODIFIED_SUBSCRIPTION_SCHEDULE", schedRef)); //$NON-NLS-1$ } else { aSchedule = addCronSchedule(schedName, schedRef, schedDesc, cronString, schedGroup, null, null); resultElement.addElement("added").addText(schedRef); //$NON-NLS-1$ SubscriptionRepository.logger.info( Messages.getString("PRO_SUBSCRIPTREP.ADDED_SUBSCRIPTION_SCHEDULE", schedRef)); //$NON-NLS-1$ } SubscriptionRepository.subscriptionScheduler.getCronSummary(cronString); // Throws an exception if invalid } catch (Exception e) { resultElement.addElement("message") //$NON-NLS-1$ .addText(Messages.getString("PRO_SUBSCRIPTREP.ERROR_OCCURRED_WITH_SCHEDULE", //$NON-NLS-1$ schedRef, e.getLocalizedMessage())); SubscriptionRepository.logger .warn(Messages.getString("PRO_SUBSCRIPTREP.EXCEPTION_WITH_SCHEDULE", schedRef), e); //$NON-NLS-1$ } } } catch (Exception e) { Element ele = resultElement.addElement("message").addText( //$NON-NLS-1$ Messages.getString("PRO_SUBSCRIPTREP.ERROR_PROCESSING_IMPORTS") + e.getLocalizedMessage()); //$NON-NLS-1$ ele.addAttribute("result", "ERROR"); //$NON-NLS-1$ //$NON-NLS-2$ SubscriptionRepository.logger .error(Messages.getString("PRO_SUBSCRIPTREP.EXCEPTION_PROCESSING_IMPORTS"), e); //$NON-NLS-1$ return (resultElement); } } return (resultElement); }
From source file:org.pentaho.platform.repository.subscription.SubscriptionRepository.java
License:Open Source License
public Element importContent(final Document doc) { Element resultElement = DocumentHelper.createElement("importContentResults"); //$NON-NLS-1$ if (doc == null) { Element ele = resultElement.addElement("message") //$NON-NLS-1$ .addText(Messages.getString("PRO_SUBSCRIPTREP.DOCUMENT_IS_NULL")); //$NON-NLS-1$ ele.addAttribute("result", "ERROR"); //$NON-NLS-1$//$NON-NLS-2$ return (resultElement); }//from w ww . j a v a 2 s . c o m List contentNodes = doc.selectNodes("//subscription-content/*"); //$NON-NLS-1$ if (contentNodes.size() == 0) { Element ele = resultElement.addElement("message") //$NON-NLS-1$ .addText(Messages.getString("PRO_SUBSCRIPTREP.NO_SCHEDULES_DEFINED")); //$NON-NLS-1$ ele.addAttribute("result", "WARNING"); //$NON-NLS-1$//$NON-NLS-2$ return (resultElement); } synchronized (SubscriptionRepository.SyncLock) { Node contentNode = null; Node tempNode = null; String actionRef, contentType, allowAllSchedules; ISubscribeContent subscribeContent = null; List schedList = getSchedules(); Map scheduleMap = new HashMap(); Map groupMap = new HashMap(); for (int j = 0; j < schedList.size(); ++j) { Schedule aSchedule = (Schedule) schedList.get(j); scheduleMap.put(aSchedule.getScheduleReference(), aSchedule); List groupList = (List) groupMap.get(aSchedule.getGroup()); if (groupList == null) { groupList = new ArrayList(); groupMap.put(aSchedule.getGroup(), groupList); } groupList.add(aSchedule); } try { SubscriptionRepository.logger.info(Messages.getString( "PRO_SUBSCRIPTREP.USER_PROCESSING_CONTENT_NODES", Integer.toString(contentNodes.size()))); //$NON-NLS-1$ for (int i = 0; i < contentNodes.size(); i++) { contentNode = (Node) contentNodes.get(i); actionRef = contentNode.selectSingleNode("@action").getText(); //$NON-NLS-1$ contentType = contentNode.selectSingleNode("@type").getText(); //$NON-NLS-1$ tempNode = contentNode.selectSingleNode("@allowAllSchedules"); //$NON-NLS-1$ if (tempNode != null) { allowAllSchedules = tempNode.getText(); } else { allowAllSchedules = "false"; //$NON-NLS-1$ } try { subscribeContent = getContentByActionReference(actionRef); if (subscribeContent != null) { subscribeContent.setType(contentType); resultElement.addElement("modified").addText(actionRef); //$NON-NLS-1$ SubscriptionRepository.logger.info(Messages .getString("PRO_SUBSCRIPTREP.MODIFIED_SUBSCRIPTION_CONTENT", actionRef)); //$NON-NLS-1$ } else { subscribeContent = addContent(actionRef, contentType); resultElement.addElement("added").addText(actionRef); //$NON-NLS-1$ SubscriptionRepository.logger.info( Messages.getString("PRO_SUBSCRIPTREP.ADDED_SUBSCRIPTION_CONTENT", actionRef)); //$NON-NLS-1$ } } catch (Exception e) { resultElement.addElement("message").addText(Messages.getString( //$NON-NLS-1$ "PRO_SUBSCRIPTREP.ERROR_WITH_CONTENT", actionRef, e.getLocalizedMessage())); //$NON-NLS-1$ SubscriptionRepository.logger .warn(Messages.getString("PRO_SUBSCRIPTREP.ERROR_WITH_CONTENT_LOG", actionRef), e); //$NON-NLS-1$ } List contentSchedules = new ArrayList(); if ("true".equalsIgnoreCase(allowAllSchedules)) { //$NON-NLS-1$ contentSchedules.addAll(schedList); } else { List suppliedSchedules = contentNode.selectNodes("schedule"); //$NON-NLS-1$ if (suppliedSchedules != null) { for (int j = 0; j < suppliedSchedules.size(); j++) { tempNode = (Node) suppliedSchedules.get(j); String schName = tempNode.getText(); if (schName != null) { Object aSchedule = scheduleMap.get(schName); if (aSchedule != null) { contentSchedules.add(aSchedule); } } } } List suppliedGroups = contentNode.selectNodes("group"); //$NON-NLS-1$ if (suppliedGroups != null) { for (int j = 0; j < suppliedGroups.size(); j++) { tempNode = (Node) suppliedGroups.get(j); String grpName = tempNode.getText(); if (grpName != null) { List groupList = (List) groupMap.get(grpName); if (groupList != null) { contentSchedules.addAll(groupList); } } } } } HibernateUtil.beginTransaction(); // Need to do this or the schedules don't get saved if the content item is new subscribeContent.setSchedules(contentSchedules); HibernateUtil.commitTransaction(); } } catch (Exception e) { Element ele = resultElement.addElement("message").addText( //$NON-NLS-1$ Messages.getString("PRO_SUBSCRIPTREP.ERROR_PROCESSING_IMPORTS") + e.getLocalizedMessage()); //$NON-NLS-1$ ele.addAttribute("result", "ERROR"); //$NON-NLS-1$ //$NON-NLS-2$ SubscriptionRepository.logger .error(Messages.getString("PRO_SUBSCRIPTREP.EXCEPTION_PROCESSING_IMPORTS"), e); //$NON-NLS-1$ return (resultElement); } } return (resultElement); }
From source file:org.pentaho.platform.uifoundation.chart.BarLineChartDefinition.java
License:Open Source License
public BarLineChartDefinition(final IPentahoResultSet data, final boolean byRow, final Node chartAttributes, final IPentahoSession session) { super(data, byRow, chartAttributes, session); // setting standard category chart definition attriutes setChartAttributes(chartAttributes); // Setting bar-line-chart attributes // setCategoryColumn(chartAttributes.selectSingleNode(CATEGORY_NODE_NAME)); setBarSeries(chartAttributes.selectSingleNode(BarLineChartDefinition.BAR_SERIES_NODE_NAME)); setLineSeries(chartAttributes.selectSingleNode(BarLineChartDefinition.LINE_SERIES_NODE_NAME)); setLinesRangeTitle(chartAttributes.selectSingleNode(BarLineChartDefinition.LINES_RANGE_TITLE_NODE_NAME)); setLinesRangeTitleFont(// ww w . jav a 2 s .c om chartAttributes.selectSingleNode(BarLineChartDefinition.LINES_RANGE_TITLE_FONT_NODE_NAME)); setLinesRangeTickFormat( chartAttributes.selectSingleNode(BarLineChartDefinition.LINES_RANGE_TICK_FORMAT_NODE_NAME)); setLinesRangeTickFont( chartAttributes.selectSingleNode(BarLineChartDefinition.LINES_RANGE_TICK_FONT_NODE_NAME)); setLinesRangeMinimum( chartAttributes.selectSingleNode(BarLineChartDefinition.LINES_RANGE_MINIMUM_NODE_NAME)); setLinesRangeMaximum( chartAttributes.selectSingleNode(BarLineChartDefinition.LINES_RANGE_MAXIMUM_NODE_NAME)); }
From source file:org.pentaho.platform.uifoundation.chart.CategoryDatasetChartComponent.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 ww w. j av a 2 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 String chType = chartAttributes.selectSingleNode("chart-type").getText(); //$NON-NLS-1$ CategoryDatasetChartDefinition chartDefinition = null; if (ChartDefinition.BAR_LINE_CHART_STR.equalsIgnoreCase(chType)) { chartDefinition = new BarLineChartDefinition((IPentahoResultSet) values, byRow, chartAttributes, getSession()); } else { chartDefinition = new CategoryDatasetChartDefinition((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.CategoryDatasetChartDefinition.java
License:Open Source License
private void setChartAttributes(final Node chartAttributes) { if (chartAttributes == null) { return;/*from www.j a va 2 s . com*/ } // set the alfa layers 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 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(CategoryDatasetChartDefinition.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)); // 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 subTitleNodes = chartAttributes.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME); if ((subTitleNodes == null) || (subTitleNodes.isEmpty())) { Node subTitlesNode = chartAttributes.selectSingleNode(ChartDefinition.SUBTITLES_NODE_NAME); if (subTitlesNode != null) { subTitleNodes = subTitlesNode.selectNodes(ChartDefinition.SUBTITLE_NODE_NAME); } } else { // log a deprecation warning for this property... CategoryDatasetChartDefinition.getLogger() .warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", //$NON-NLS-1$ ChartDefinition.SUBTITLE_NODE_NAME, ChartDefinition.SUBTITLES_NODE_NAME)); CategoryDatasetChartDefinition.getLogger().warn(Messages.getInstance() .getString("CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", ChartDefinition.SUBTITLE_NODE_NAME)); //$NON-NLS-1$ } if (subTitleNodes != null) { addSubTitles(subTitleNodes); } // get the paint sequence setPaintSequence(chartAttributes.selectSingleNode(ChartDefinition.PALETTE_NODE_NAME)); // get the stacked value setStacked(chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.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 category rotation direction setCategoryLabelRotation( chartAttributes .selectSingleNode(CategoryDatasetChartDefinition.DOMAIN_LABEL_ROTATION_DIRECTION_NODE_NAME), chartAttributes .selectSingleNode(CategoryDatasetChartDefinition.DOMAIN_LABEL_ROTATION_ANGLE_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 legend position 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(CategoryDatasetChartDefinition.DOMAIN_TITLE_NODE_NAME)); // set the domain font setDomainTitleFont( chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.DOMAIN_TITLE_FONT_NODE_NAME)); // set the range minimum setRangeMinimum(chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.RANGE_MINIMUM_NODE_NAME)); // set the range minimum setRangeMaximum(chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.RANGE_MAXIMUM_NODE_NAME)); // set the range tick units setRangeTickUnits( chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.RANGE_TICK_UNITS_NODE_NAME)); // the the range tick label number format setDomainTickFont( chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.DOMAIN_TICK_FONT_NODE_NAME)); // set the range title setRangeTitle(chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.RANGE_TITLE_NODE_NAME)); // the the range font setRangeTitleFont( chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.RANGE_TITLE_FONT_NODE_NAME)); // the the range tick label number format setRangeTickFormat( chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.RANGE_TICK_FORMAT_NODE_NAME)); // the the range ticklabel font setRangeTickFont( chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.RANGE_TICK_FONT_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 the marker visibility setMaxBarWidth(chartAttributes.selectSingleNode(CategoryDatasetChartDefinition.MAX_BAR_WIDTH_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)); // first see if Hitachi Vantara System sets this property String defaultIncludeNullCategories = PentahoSystem .getSystemSetting("Charting/" + INCLUDE_NULL_CATEGORIES_NODE_NAME, "true"); //$NON-NLS-1$ //$NON-NLS-2$ setIncludeNullCategories("true".equals(defaultIncludeNullCategories)); //$NON-NLS-1$ // set whether to include null categories setIncludeNullCategories(chartAttributes.selectSingleNode(INCLUDE_NULL_CATEGORIES_NODE_NAME)); }
From source file:org.pentaho.platform.uifoundation.chart.CategoryDatasetChartDefinition.java
License:Open Source License
public void setChartBackground(final Node chartBackgroundNode) { if (chartBackgroundNode != null) { Node backgroundTypeNode = chartBackgroundNode .selectSingleNode(ChartDefinition.BACKGROUND_TYPE_ATTRIBUTE_NAME); if (backgroundTypeNode != null) { String backgroundTypeStr = backgroundTypeNode.getText(); if (ChartDefinition.COLOR_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setChartBackgroundPaint(JFreeChartEngine.getPaint(chartBackgroundNode)); setChartBackgroundImage((Image) null); } else if (ChartDefinition.IMAGE_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setChartBackgroundImage(chartBackgroundNode); setChartBackgroundPaint(null); } else if (ChartDefinition.TEXTURE_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setChartBackgroundPaint(JFreeChartEngine.getTexturePaint(chartBackgroundNode, getWidth(), getHeight(), getSession())); setChartBackgroundImage((Image) null); } else if (ChartDefinition.GRADIENT_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setChartBackgroundPaint( JFreeChartEngine.getGradientPaint(chartBackgroundNode, getWidth(), getHeight())); setChartBackgroundImage((Image) null); }//from w w w . j a v a 2 s. co m } } }
From source file:org.pentaho.platform.uifoundation.chart.CategoryDatasetChartDefinition.java
License:Open Source License
public void setPlotBackground(final Node plotBackgroundNode) { if (plotBackgroundNode != null) { Node backgroundTypeNode = plotBackgroundNode .selectSingleNode(ChartDefinition.BACKGROUND_TYPE_ATTRIBUTE_NAME); if (backgroundTypeNode != null) { String backgroundTypeStr = backgroundTypeNode.getText(); if (ChartDefinition.COLOR_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setPlotBackgroundPaint(JFreeChartEngine.getPaint(plotBackgroundNode)); setPlotBackgroundImage((Image) null); } else if (ChartDefinition.IMAGE_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setPlotBackgroundImage(plotBackgroundNode); setPlotBackgroundPaint(null); } else if (ChartDefinition.TEXTURE_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setPlotBackgroundPaint(JFreeChartEngine.getTexturePaint(plotBackgroundNode, getWidth(), getHeight(), getSession())); setPlotBackgroundImage((Image) null); } else if (ChartDefinition.GRADIENT_TYPE_NAME.equalsIgnoreCase(backgroundTypeStr)) { setPlotBackgroundPaint(//from w w w . j a va 2 s . c om JFreeChartEngine.getGradientPaint(plotBackgroundNode, getWidth(), getHeight())); setPlotBackgroundImage((Image) null); } } } }
From source file:org.pentaho.platform.uifoundation.chart.ChartHelper.java
License:Open Source License
/** * doChart generates the images and html necessary to render various charts within a web page. * /* w w w. j av a 2s. c om*/ * @param actionPath * full path including the name of the action sequence or resource * @param parameterProvider * the collection of parameters to customize the chart * @param outputStream * the output string buffer for the content * @param userSession * the user session object * @param messages * a collection to store error and logging messages * @param logger * logging object * * @return true if successful */ @Deprecated public static boolean doChart(final String actionPath, final IParameterProvider parameterProvider, final StringBuffer outputStream, final IPentahoSession userSession, final ArrayList messages, ILogger logger) { deprecateWarning(); boolean result = true; String content = null; StringBuffer messageBuffer = new StringBuffer(); if (logger == null) { // No logger? The usersession extends ILogger, use it for logging logger = userSession; } // Retrieve all parameters from parameter provider String outerParams = parameterProvider.getStringParameter("outer-params", null); //$NON-NLS-1$ String innerParam = parameterProvider.getStringParameter("inner-param", null); //$NON-NLS-1$ String urlDrillTemplate = parameterProvider.getStringParameter("drill-url", null); //$NON-NLS-1$ String imageUrl = parameterProvider.getStringParameter("image-url", null); //$NON-NLS-1$ // Very likely null; allow API users to continue to pass the dial value via parameters String dialValue = parameterProvider.getStringParameter("value", null); //$NON-NLS-1$ IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); if (imageUrl == null) { imageUrl = requestContext.getContextPath(); //$NON-NLS-1$ } if (urlDrillTemplate == null) { urlDrillTemplate = ""; //$NON-NLS-1$ } int width = (int) parameterProvider.getLongParameter("image-width", 150); //$NON-NLS-1$ int height = (int) parameterProvider.getLongParameter("image-height", 150); //$NON-NLS-1$ SimpleUrlFactory urlFactory = new SimpleUrlFactory(urlDrillTemplate); // Determine the type of chart we are building; these values can come from the chart xml definition, or // from the parameter provider. Try the parameter provider first, for performance reasons. String chartTypeStr = parameterProvider.getStringParameter(ChartDefinition.TYPE_NODE_NAME, null); String datasetType = ChartDefinition.CATEGORY_DATASET_STR; if ((chartTypeStr == null) || (chartTypeStr.length() == 0)) { try { // attempt to get the chart type and possibly data type from the xml doc ActionSequenceJCRHelper jcrHelper = new ActionSequenceJCRHelper(userSession); Document chartDefinition = jcrHelper.getSolutionDocument(actionPath, RepositoryFilePermission.READ); Node chartAttributes = chartDefinition .selectSingleNode("//" + AbstractChartComponent.CHART_NODE_NAME); //$NON-NLS-1$ chartTypeStr = chartAttributes.selectSingleNode(ChartDefinition.TYPE_NODE_NAME).getText(); Node datasetTypeNode = chartAttributes.selectSingleNode(ChartDefinition.DATASET_TYPE_NODE_NAME); if (datasetTypeNode != null) { datasetType = datasetTypeNode.getText(); } } catch (Exception e) { logger.error(Messages.getInstance() .getErrorString("ChartHelper.ERROR_0001_IO_PROBLEM_GETTING_CHART_TYPE"), e); //$NON-NLS-1$ PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", //$NON-NLS-1$ Messages.getInstance().getString("ChartHelper.ERROR_0001_IO_PROBLEM_GETTING_CHART_TYPE"), //$NON-NLS-1$ messages, messageBuffer); content = messageBuffer.toString(); result = false; } } // Check again - do we have a chart type now? If not, bail out, we have no idea what to try to generate if ((chartTypeStr == null) || (chartTypeStr.length() == 0)) { logger.error(Messages.getInstance().getString("ChartHelper.ERROR_0002_COULD_NOT_DETERMINE_CHART_TYPE")); //$NON-NLS-1$ PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", //$NON-NLS-1$ Messages.getInstance().getString("ChartHelper.ERROR_0002_COULD_NOT_DETERMINE_CHART_TYPE"), //$NON-NLS-1$ messages, messageBuffer); content = messageBuffer.toString(); result = false; } if (!result) { outputStream.append(content); return result; } int chartType = JFreeChartEngine.getChartType(chartTypeStr); AbstractJFreeChartComponent chartComponent = null; try { // Some charts are determined by the dataset that is passed in; check these first... if (datasetType.equalsIgnoreCase(ChartDefinition.TIME_SERIES_COLLECTION_STR)) { chartComponent = new TimeSeriesCollectionChartComponent(chartType, actionPath, width, height, urlFactory, messages); } else if (datasetType.equalsIgnoreCase(ChartDefinition.XY_SERIES_COLLECTION_STR)) { chartComponent = new XYSeriesCollectionChartComponent(chartType, actionPath, width, height, urlFactory, messages); } else if (datasetType.equalsIgnoreCase(ChartDefinition.XYZ_SERIES_COLLECTION_STR)) { chartComponent = new XYZSeriesCollectionChartComponent(chartType, actionPath, width, height, urlFactory, messages); } // Didn't find a dataset, so try to create the component based on chart type. if (chartComponent == null) { switch (chartType) { case JFreeChartEngine.BAR_CHART_TYPE: case JFreeChartEngine.AREA_CHART_TYPE: case JFreeChartEngine.BAR_LINE_CHART_TYPE: case JFreeChartEngine.LINE_CHART_TYPE: case JFreeChartEngine.DIFFERENCE_CHART_TYPE: case JFreeChartEngine.DOT_CHART_TYPE: case JFreeChartEngine.STEP_AREA_CHART_TYPE: case JFreeChartEngine.STEP_CHART_TYPE: case JFreeChartEngine.PIE_GRID_CHART_TYPE: chartComponent = new CategoryDatasetChartComponent(chartType, actionPath, width, height, urlFactory, messages); break; case JFreeChartEngine.PIE_CHART_TYPE: chartComponent = new PieDatasetChartComponent(chartType, actionPath, width, height, urlFactory, messages); break; case JFreeChartEngine.DIAL_CHART_TYPE: chartComponent = new DialChartComponent(chartType, actionPath, width, height, urlFactory, messages); if (dialValue != null) { Number numericDialValue = DataUtilities.toNumber(dialValue, LocaleHelper.getCurrencyFormat(), LocaleHelper.getNumberFormat()); ((DialChartComponent) chartComponent).setValue(numericDialValue.doubleValue()); } break; case JFreeChartEngine.BUBBLE_CHART_TYPE: chartComponent = new XYZSeriesCollectionChartComponent(chartType, actionPath, width, height, urlFactory, messages); break; case JFreeChartEngine.UNDEFINED_CHART_TYPE: default: // Unsupported chart type, bail out logger.error(Messages.getInstance().getString("ChartHelper.ERROR_0003_INVALID_CHART_TYPE", //$NON-NLS-1$ chartTypeStr, Integer.toString(chartType))); PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", //$NON-NLS-1$ Messages.getInstance().getString("ChartHelper.ERROR_0003_INVALID_CHART_TYPE", //$NON-NLS-1$ chartTypeStr, Integer.toString(chartType)), messages, messageBuffer); content = messageBuffer.toString(); result = false; } } if (result && (chartComponent != null)) { try { chartComponent.setLoggingLevel(logger.getLoggingLevel()); chartComponent.validate(userSession, null); chartComponent.setDataAction(actionPath); chartComponent.setUrlTemplate(urlDrillTemplate); String seriesName = parameterProvider.getStringParameter("series-name", null); //$NON-NLS-1$ if (chartComponent instanceof CategoryDatasetChartComponent) { ((CategoryDatasetChartComponent) chartComponent).setSeriesName(seriesName); } // WARNING!!! This is an atypical way to access data for the chart... these parameters and their // usage are undocumented, and only left in here to support older solutions that may be using them. // *************** START QUESTIONABLE CODE ******************************************************** String connectionName = parameterProvider.getStringParameter("connection", null); //$NON-NLS-1$ String query = parameterProvider.getStringParameter("query", null); //$NON-NLS-1$ String dataAction = parameterProvider.getStringParameter("data-process", null); //$NON-NLS-1$ IPentahoConnection connection = null; try { chartComponent.setParamName(innerParam); chartComponent.setParameterProvider(IParameterProvider.SCOPE_REQUEST, parameterProvider); if ((connectionName != null) && (query != null)) { // connection = new SQLConnection(connectionName, logger) // TODO support non-SQL data sources. Much easier now using the factory connection = PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, connectionName, userSession, logger); try { query = TemplateUtil.applyTemplate(query, TemplateUtil.parametersToProperties(parameterProvider), null); IPentahoResultSet results = connection.executeQuery(query); chartComponent.setValues(results); } finally { boolean ignored = true; } chartComponent.setUrlTemplate(urlDrillTemplate); if (outerParams != null) { StringTokenizer tokenizer = new StringTokenizer(outerParams, ";"); //$NON-NLS-1$ while (tokenizer.hasMoreTokens()) { chartComponent.addOuterParamName(tokenizer.nextToken()); } } } else if (dataAction != null) { chartComponent.setDataAction(dataAction); } // ***************** END QUESTIONABLE CODE ******************************************************** content = chartComponent.getContent("text/html"); //$NON-NLS-1$ } finally { if (connection != null) { connection.close(); } } } catch (Throwable e) { logger.error(Messages.getInstance().getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), //$NON-NLS-1$ e); } } // end of if(result) try { if (content == null) { PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", //$NON-NLS-1$ Messages.getInstance().getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), //$NON-NLS-1$ messages, messageBuffer); content = messageBuffer.toString(); result = false; } outputStream.append(content); } catch (Exception e) { logger.error(Messages.getInstance().getErrorString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), e); //$NON-NLS-1$ } } finally { if (chartComponent != null) { chartComponent.dispose(); } } return result; }
From source file:org.pentaho.platform.uifoundation.chart.DialChartComponent.java
License:Open Source License
@Override public Dataset createChart(final Document doc) { // get the chart node from the document Node chartAttributes = doc.selectSingleNode("//" + AbstractChartComponent.CHART_NODE_NAME); //$NON-NLS-1$ // Try to retrieve the data values from the <data> XML block if (actionPath != null) { values = getActionData();/*from w w w .ja va 2s .com*/ } // No <data> node; check for <dialvalue>, <dialmaximum>, <dialminimum> nodes if (values == null) { Node valueNode = chartAttributes.selectSingleNode(DialChartComponent.VALUE_NODE_NAME); Node maxValueNode = chartAttributes.selectSingleNode(DialChartComponent.MAXVALUE_NODE_NAME); Node minValueNode = chartAttributes.selectSingleNode(DialChartComponent.MINVALUE_NODE_NAME); double val = 0; double min = -1; double max = -1; if (valueNode != null) { try { val = Double.parseDouble(valueNode.getText()); } catch (Exception e) { AbstractChartComponent.logger.error(Messages.getInstance().getErrorString( "DIALCHARTCOMPONENT.ERROR_0001_ERROR_PARSING_VALUE", valueNode.getText()), e); //$NON-NLS-1$ val = 0; } if ((minValueNode != null) && (maxValueNode != null)) { try { min = Double.parseDouble(minValueNode.getText()); max = Double.parseDouble(maxValueNode.getText()); } catch (Exception e) { AbstractChartComponent.logger.error(Messages.getInstance().getErrorString( "DIALCHARTCOMPONENT.ERROR_0001_ERROR_PARSING_VALUE", //$NON-NLS-1$ minValueNode.getText(), maxValueNode.getText()), e); min = -1; max = -1; } } // Its OK if there is no min and max - we will derive it later if absent. MemoryResultSet set = new MemoryResultSet(); if ((min == -1) && (max == -1)) { set.addRow(new Object[] { new Double(val) }); } else { set.addRow(new Object[] { new Double(val), new Double(min), new Double(max) }); } values = set; } } // If, at this point, the values object is null, we will continue to execute, and assume // the user is has set the dial value using the API. // create the definition DialWidgetDefinition chartDefinition = new DialWidgetDefinition((IPentahoResultSet) values, byRow, chartAttributes, width, height, getSession()); // This local variable "value" is here for parity with the way the DashboardWidgetComponent functions... // If value gets set, all other data methods executed previously are overridden. if (value != null) { chartDefinition.setValue(value.doubleValue()); chartDefinition.deriveMinMax(value.doubleValue()); } // set the misc values from chartDefinition setChartType(JFreeChartEngine.DIAL_CHART_TYPE); setTitle(chartDefinition.getTitle()); // get the URL template Node urlTemplateNode = chartAttributes.selectSingleNode(AbstractChartComponent.URLTEMPLATE_NODE_NAME); if (urlTemplateNode != null) { setUrlTemplate(urlTemplateNode.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.DialWidgetDefinition.java
License:Open Source License
/** * TODO PROBLEM HERE! If you use this constructor, the XML schema for the chart attributes is different than if * you use the constructor with the arguments public DialWidgetDefinition( Document document, double value, int * width, int height, IPentahoSession session). This constructor expects the chart attribute nodes to be children * of the <chart-attributes> node, whereas the latter constructor expects the attributes to be children of a * <dial> node. This does not help us with our parity situation, and should be deprecated and reconciled. * //ww w .j a va2 s .co m * @param data * @param byRow * @param chartAttributes * @param width * @param height * @param session */ public DialWidgetDefinition(final IPentahoResultSet data, final boolean byRow, final Node chartAttributes, final int width, final int height, final IPentahoSession session) { this(0.0, Double.MIN_VALUE, Double.MAX_VALUE, false); attributes = chartAttributes; if (data != null) { if (byRow) { setDataByRow(data); } else { setDataByColumn(data); } } // 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 alfa layers 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)); } DialWidgetDefinition.createDial(this, chartAttributes, width, height, session); }