List of usage examples for org.dom4j Node selectNodes
List<Node> selectNodes(String xpathExpression);
selectNodes
evaluates an XPath expression and returns the result as a List
of Node
instances or String
instances depending on the XPath expression.
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
private static Map getMapFromNode(final Node mapNode) { Map rtnMap = new ListOrderedMap(); if (mapNode != null) { List nodes = mapNode.selectNodes("entry"); //$NON-NLS-1$ if (nodes != null) { for (Iterator it = nodes.iterator(); it.hasNext();) { Node entryNode = (Node) it.next(); rtnMap.put(XmlDom4JHelper.getNodeText("@key", entryNode), entryNode.getText()); //$NON-NLS-1$ }// w w w. j av a 2 s . c om } } return (rtnMap); }
From source file:org.pentaho.platform.engine.services.ActionSequenceJCRHelper.java
License:Open Source License
public void localizeDoc(final Node document, final RepositoryFile file) { String fileName = file.getName(); int dotIndex = fileName.indexOf('.'); String baseName = fileName.substring(0, dotIndex); // TODO read in nodes from the locale file and use them to override the // ones in the main document try {// w w w .j a v a2s . c o m List nodes = document.selectNodes("descendant::*"); //$NON-NLS-1$ Iterator nodeIterator = nodes.iterator(); while (nodeIterator.hasNext()) { Node node = (Node) nodeIterator.next(); String name = node.getText(); if (name.startsWith("%") && !node.getPath().endsWith("/text()")) { //$NON-NLS-1$ //$NON-NLS-2$ try { String localeText = getLocaleString(name, baseName, file, true); if (localeText != null) { node.setText(localeText); } } catch (Exception e) { logger.warn(Messages.getInstance().getString( "ActionSequenceJCRHelper.WARN_MISSING_RESOURCE_PROPERTY", name.substring(1), //$NON-NLS-1$ baseName, getLocale().toString())); } } } } catch (Exception e) { logger.error(Messages.getInstance().getErrorString( "ActionSequenceJCRHelper.ERROR_0007_COULD_NOT_READ_PROPERTIES", file.getPath()), e); //$NON-NLS-1$ } }
From source file:org.pentaho.platform.plugin.action.builtin.SecureFilterComponent.java
License:Open Source License
@Override public boolean validateAction() { Node compDef = getComponentDefinition(); List selNodes = compDef.selectNodes("selections/*"); //$NON-NLS-1$ String inputName = null;/* w w w.ja v a 2 s.c om*/ boolean isOk = true; for (Iterator it = selNodes.iterator(); it.hasNext();) { Node node = (Node) it.next(); try { inputName = node.getName(); // Get the Data Node IActionParameter inputParam = getInputParameter(inputName); String filterType = XmlDom4JHelper.getNodeText("@filter", node, null); //$NON-NLS-1$ // BISERVER-149 Changed isOptional param to default to false in order to // enable prompting when no default value AND no selection list is given... // This is also the default that Design Studio presumes. String optionalParm = XmlDom4JHelper.getNodeText("@optional", node, "false"); //$NON-NLS-1$ //$NON-NLS-2$ boolean isOptional = "true".equals(optionalParm); //$NON-NLS-1$ if ("none".equalsIgnoreCase(filterType)) { //$NON-NLS-1$ IActionParameter selectParam = getInputParameter(inputName); String title = XmlDom4JHelper.getNodeText("title", node, inputName); //$NON-NLS-1$ String valueCol = ""; //$NON-NLS-1$ String dispCol = ""; //$NON-NLS-1$ String displayStyle = XmlDom4JHelper.getNodeText("@style", node, null); //$NON-NLS-1$ boolean promptOne = "true" //$NON-NLS-1$ .equalsIgnoreCase(XmlDom4JHelper.getNodeText("@prompt-if-one-value", node, "false")); //$NON-NLS-1$ //$NON-NLS-2$ if ("hidden".equals(displayStyle)) { //$NON-NLS-1$ hiddenList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional)); } else { selList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional)); } } else { Node filterNode = node.selectSingleNode("filter"); //$NON-NLS-1$ IActionParameter selectParam = getInputParameter(filterNode.getText().trim()); String valueCol = XmlDom4JHelper.getNodeText("@value-col-name", filterNode, null); //$NON-NLS-1$ String dispCol = XmlDom4JHelper.getNodeText("@display-col-name", filterNode, null); //$NON-NLS-1$ String title = XmlDom4JHelper.getNodeText("title", node, null); //$NON-NLS-1$ String displayStyle = XmlDom4JHelper.getNodeText("@style", node, null); //$NON-NLS-1$ boolean promptOne = "true" //$NON-NLS-1$ .equalsIgnoreCase(XmlDom4JHelper.getNodeText("@prompt-if-one-value", node, "false")); //$NON-NLS-1$ //$NON-NLS-2$ selList.add(new SelEntry(inputParam, selectParam, valueCol, dispCol, title, displayStyle, promptOne, isOptional)); } } catch (Exception e) { // Catch the exception to let us test all // the params isOk = false; error(Messages.getInstance().getErrorString("SecureFilterComponent.ERROR_0001_PARAM_MISSING", //$NON-NLS-1$ inputName)); } } return (isOk); }
From source file:org.pentaho.platform.plugin.action.jfreechart.ChartComponent.java
License:Open Source License
@Override protected boolean executeAction() { int height = -1; int width = -1; String title = ""; //$NON-NLS-1$ Node chartDocument = null;//from ww w . ja v a2 s . co 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; }
From source file:org.pentaho.platform.plugin.action.jfreereport.components.JFreeReportConfigParameterComponent.java
License:Open Source License
private boolean initReportConfigParameters() { boolean result = true; if (isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT)) { Object maybeReport = getInputValue(AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT); if (maybeReport instanceof MasterReport) { MasterReport report = (MasterReport) maybeReport; // We should have our report object at this point. if (isDefinedInput(JFreeReportConfigParameterComponent.REPORT_CONFIG_INPUT_PARAM)) { // It's coming in as an input parameter Object reportConfigParams = this .getInputValue(JFreeReportConfigParameterComponent.REPORT_CONFIG_INPUT_PARAM); if (reportConfigParams instanceof IPentahoResultSet) { setReportConfigParameters(report, (IPentahoResultSet) reportConfigParams); } else if (reportConfigParams instanceof Map) { setReportConfigParameters(report, (Map) reportConfigParams); } else { error(Messages.getInstance() .getErrorString("JFreeReport.ERROR_0026_UNKNOWN_REPORT_CONFIGURATION_PARAMETERS")); //$NON-NLS-1$ result = false;//w ww .j a va 2 s .c om } } else { Node compDef = getComponentDefinition(); List configNodes = compDef .selectNodes(JFreeReportConfigParameterComponent.REPORT_CONFIG_COMPDEFN + "/*"); //$NON-NLS-1$ if ((configNodes != null) && (configNodes.size() > 0)) { setReportConfigParameters(report, configNodes); } } } } return result; }
From source file:org.pentaho.platform.plugin.action.jfreereport.JFreeReportGeneratorComponent.java
License:Open Source License
@Override protected boolean executeAction() { /*/*w w w. j a v a 2 s . c om*/ * The on-the-fly JFreeReport generator will expect the following: ============================================= * * INPUT: Path (String) to Existing JFreeReport to use as "template" OutputStream to write generated report * IPentahoResultSet List of Columns to "Group" List of column widths * * OUTPUT: JFreeReport XML to provided Path or OutputStream * * ASSUMPTIONS: List of column widths - last provided item is to be repeated for all remaining columns Perform * ItemSumFunction on all numeric columns per group and grand total Perform ItemSumFunction on calculated column per * group and grand total Groups and Items will be removed from template (we will retain font/color data) * ============================================= * * public OnTheFlyJFreeReportGenerator(String path, IPentahoResultSet set, List groupLabels, List widths, * OutputStream stream) ------ public void process() */ JFreeReportGenAction genAction = null; if (!(getActionDefinition() instanceof JFreeReportGenAction)) { error(Messages.getInstance().getErrorString( "JFreeReportGeneratorComponent.ERROR_0001_UNKNOWN_ACTION_TYPE", //$NON-NLS-1$ getActionDefinition().getElement().asXML())); return false; } else { genAction = (JFreeReportGenAction) getActionDefinition(); resultSet = (IPentahoResultSet) genAction.getResultSet().getValue(); Node componentNode = null; String settingsFromActionSequence = null; try { settingsFromActionSequence = genAction.getComponentSettings().getStringValue(); } catch (Exception ex) { //ignore } if (settingsFromActionSequence != null) { try { Document settingsDoc = XmlDom4JHelper.getDocFromString(settingsFromActionSequence, new PentahoEntityResolver()); componentNode = settingsDoc.getRootElement(); } catch (Exception e) { error("Could not get settings from action sequence document", e); //$NON-NLS-1$ return false; } } else { componentNode = getComponentDefinition(); } try { compPath = genAction.getTemplatePath().getStringValue(); path = PentahoSystem.getApplicationContext().getSolutionPath(compPath); orientation = genAction.getOrientation().getStringValue(); nullString = genAction.getNullString().getStringValue(); horizontalOffset = genAction.getHorizontalOffset().getIntValue(horizontalOffset); reportName = genAction.getReportName().getStringValue(); createSubTotals = genAction.getCreateSubTotals().getBooleanValue(false); createGrandTotals = genAction.getCreateGrandTotals().getBooleanValue(false); createRowBanding = genAction.getCreateRowBanding().getBooleanValue(false); createTotalColumn = genAction.getCreateTotalColumn().getBooleanValue(false); totalColumnName = genAction.getTotalColumnName().getStringValue(); totalColumnWidth = genAction.getTotalColumnWidth().getIntValue(totalColumnWidth); totalColumnFormat = genAction.getTotalColumnFormat().getStringValue(); rowBandingColor = genAction.getRowBandingColor().getStringValue(); spacerWidth = genAction.getSpacerWidth().getIntValue(spacerWidth); columnHeaderBackgroundColor = genAction.getColumnHeaderBackgroundColor().getStringValue(); columnHeaderForegroundColor = genAction.getColumnHeaderForegroundColor().getStringValue(); columnHeaderFontFace = genAction.getColumnHeaderFontFace().getStringValue(); columnHeaderFontSize = genAction.getColumnHeaderFontSize().getStringValue(); columnHeaderGap = genAction.getColumnHeaderGap().getIntValue(columnHeaderGap); } catch (Exception e) { e.printStackTrace(); } // Get the group display labels List groupLabelNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.GROUP_LABELS_PROP + "/" //$NON-NLS-1$ + JFreeReportGeneratorComponent.GROUP_LABEL_PROP); if (groupLabelNodes != null) { groupLabels = new String[groupLabelNodes.size()]; for (int i = 0; i < groupLabels.length; i++) { groupLabels[i] = ((Node) groupLabelNodes.get(i)).getText(); } } // Get the grouped columns indices List groupedColumnsIndicesNodes = componentNode .selectNodes(JFreeReportGeneratorComponent.GROUPED_COLUMNS_PROP + "/" //$NON-NLS-1$ + JFreeReportGeneratorComponent.GROUPED_COLUMN_INDICES_PROP); if (groupedColumnsIndicesNodes != null) { groupIndices = new int[groupedColumnsIndicesNodes.size()]; for (int i = 0; i < groupIndices.length; i++) { groupIndices[i] = Integer.parseInt(((Node) groupedColumnsIndicesNodes.get(i)).getText()) - 1; // I am zero based, this is not } } // get display names List displayNameNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.COLUMN_NAMES_PROP + "/" //$NON-NLS-1$ + JFreeReportGeneratorComponent.COLUMN_NAME_PROP); if (displayNameNodes != null) { displayNames = new String[displayNameNodes.size()]; for (int i = 0; i < displayNames.length; i++) { displayNames[i] = ((Node) displayNameNodes.get(i)).getText(); } } // get column alignments List columnAlignmentNodes = componentNode .selectNodes(JFreeReportGeneratorComponent.COLUMN_ALIGNMENTS_PROP + "/" //$NON-NLS-1$ + JFreeReportGeneratorComponent.COLUMN_ALIGNMENT_PROP); if (columnAlignmentNodes != null) { columnAlignments = new String[columnAlignmentNodes.size()]; for (int i = 0; i < columnAlignments.length; i++) { columnAlignments[i] = ((Node) columnAlignmentNodes.get(i)).getText(); } } // Get the column widths List widthNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.COLUMN_WIDTHS_PROP + "/" //$NON-NLS-1$ + JFreeReportGeneratorComponent.WIDTH_PROP); if (widthNodes != null) { widths = new int[widthNodes.size()]; for (int i = 0; i < widths.length; i++) { widths[i] = Integer.valueOf(((Node) widthNodes.get(i)).getText()).intValue(); } } // Get the column item hides List itemHideNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.ITEM_HIDES_PROP + "/" //$NON-NLS-1$ + JFreeReportGeneratorComponent.ITEM_HIDE_PROP); if (itemHideNodes != null) { itemHides = new boolean[itemHideNodes.size()]; for (int i = 0; i < itemHides.length; i++) { itemHides[i] = Boolean.valueOf(((Node) itemHideNodes.get(i)).getText()).booleanValue(); } } // Get the column formats List formatNodes = componentNode.selectNodes(JFreeReportGeneratorComponent.COLUMN_FORMATS_PROP + "/" //$NON-NLS-1$ + JFreeReportGeneratorComponent.FORMAT_PROP); if (formatNodes != null) { formats = new String[formatNodes.size()]; for (int i = 0; i < formats.length; i++) { formats[i] = ((Node) formatNodes.get(i)).getText(); } } } String reportDefinition = process(); if (reportDefinition != null) { if (genAction.getOutputReportDefinition() != null) { genAction.getOutputReportDefinition().setValue(reportDefinition); } else { // This is to support the old way where // we did not check if report-definition existed in the output section setOutputValue(JFreeReportGenAction.REPORT_DEFINITION, reportDefinition); } } return true; }
From source file:org.pentaho.platform.plugin.action.openflashchart.factory.AbstractChartFactory.java
License:Open Source License
/** * Setup colors for the series and also background *//* w w w . j a v a 2 s.c o m*/ protected void setupColors() { Node temp = chartNode.selectSingleNode(COLOR_PALETTE_NODE_LOC); if (temp != null) { Object[] colorNodes = temp.selectNodes(COLOR_NODE_LOC).toArray(); for (int j = 0; j < colorNodes.length; j++) { colors.add(getValue((Node) colorNodes[j])); } } else { for (int i = 0; i < COLORS_DEFAULT.length; i++) { colors.add(COLORS_DEFAULT[i]); } } // Use either chart-background or plot-background (chart takes precendence) temp = chartNode.selectSingleNode(PLOT_BACKGROUND_NODE_LOC); if (getValue(temp) != null) { String type = temp.valueOf(PLOT_BACKGROUND_COLOR_XPATH); if (type != null && COLOR_TYPE.equals(type)) { chart.setBackgroundColour(getValue(temp)); chart.setInnerBackgroundColour(getValue(temp)); } } temp = chartNode.selectSingleNode(CHART_BACKGROUND_NODE_LOC); if (getValue(temp) != null) { String type = temp.valueOf(CHART_BACKGROUND_COLOR_XPATH); if (type != null && COLOR_TYPE.equals(type)) { chart.setBackgroundColour(getValue(temp)); } } }
From source file:org.pentaho.platform.plugin.adhoc.AdhocWebServiceInteractXml.java
License:Open Source License
public static Document convertXml(final Document reportXml) { // get the list of headers List<String> headerList = new ArrayList<String>(); List<?> nodes = reportXml.selectNodes("/report/groupheader/@name"); //$NON-NLS-1$ // find all the unique group header names Iterator<?> it = nodes.iterator(); Attribute attr;/*from ww w . j ava2 s. c o m*/ String name; while (it.hasNext()) { // we only need to go until we get the first duplicate attr = (Attribute) it.next(); name = attr.getText(); if (!"dummy".equals(name)) { //$NON-NLS-1$ if (!headerList.contains(name)) { headerList.add(name); System.out.println(name); } else { break; } } } String headerNames[] = new String[headerList.size()]; String headerValues[] = new String[headerList.size()]; Element headerNodes[] = new Element[headerList.size()]; String columnHeaders[] = new String[0]; Element columnHeaderNodes[] = new Element[0]; headerList.toArray(headerNames); for (int idx = 0; idx < headerValues.length; idx++) { headerValues[idx] = ""; //$NON-NLS-1$ } Document reportDoc = DocumentHelper.createDocument(); Element reportNode = DocumentHelper.createElement("report"); //$NON-NLS-1$ reportDoc.setRootElement(reportNode); // process the top-level nodes nodes = reportXml.selectNodes("/report/*"); //$NON-NLS-1$ Node node; // go thru all the nodes it = nodes.iterator(); while (it.hasNext()) { node = (Node) it.next(); name = node.getName(); if ("groupheader".equals(name)) { //$NON-NLS-1$ // process the group headers // get the group header name String headerName = node.selectSingleNode("@name").getText(); //$NON-NLS-1$ if (!"dummy".equals(headerName)) { //$NON-NLS-1$ // find the header index String headerValue = node.selectSingleNode("element[1]").getText();//$NON-NLS-1$ int headerIdx = -1; for (int idx = 0; idx < headerNames.length; idx++) { if (headerNames[idx].equals(headerName)) { headerIdx = idx; break; } } if (!headerValues[headerIdx].equals(headerValue)) { // this is a new header value headerValues[headerIdx] = headerValue; // find the parent node Element parentNode; if (headerIdx == 0) { parentNode = reportNode; } else { parentNode = headerNodes[headerIdx - 1]; } // create a group header node for this Element headerNode = DocumentHelper.createElement("groupheader");//$NON-NLS-1$ parentNode.add(headerNode); headerNodes[headerIdx] = headerNode; // create the name attribute attr = DocumentHelper.createAttribute(headerNode, "name", headerName);//$NON-NLS-1$ headerNode.add(attr); // create the value node Element elementNode = DocumentHelper.createElement("element");//$NON-NLS-1$ headerNode.add(elementNode); attr = DocumentHelper.createAttribute(elementNode, "name", headerName);//$NON-NLS-1$ elementNode.add(attr); elementNode.setText(headerValue); } } // see if there are any column headers List<?> elements = node.selectNodes("element");//$NON-NLS-1$ if (elements.size() == 0) { elements = node.selectNodes("band/element");//$NON-NLS-1$ } if (elements.size() > 1) { // there are column headers here, get them and store them for the next set of rows columnHeaders = new String[elements.size() - 1]; columnHeaderNodes = new Element[elements.size() - 1]; for (int idx = 1; idx < elements.size(); idx++) { columnHeaders[idx - 1] = ((Element) elements.get(idx)).getText(); } } } else if ("items".equals(name)) {//$NON-NLS-1$ // process items (rows) // get the parent node, this should always be the last one on the list Element parentNode; if (headerNodes.length == 0) { parentNode = reportNode; } else { parentNode = headerNodes[headerNodes.length - 1]; } // create the items node Element itemsNode = DocumentHelper.createElement("items");//$NON-NLS-1$ parentNode.add(itemsNode); // create the headers node Element headersNode = DocumentHelper.createElement("headers");//$NON-NLS-1$ itemsNode.add(headersNode); // create the rows node Element itemBandsNode = DocumentHelper.createElement("itembands");//$NON-NLS-1$ itemsNode.add(itemBandsNode); for (int idx = 0; idx < columnHeaders.length; idx++) { Element headerNode = DocumentHelper.createElement("header");//$NON-NLS-1$ headerNode.setText(columnHeaders[idx]); headersNode.add(headerNode); columnHeaderNodes[idx] = headerNode; } // now copy the item bands over List<?> itembands = node.selectNodes("itemband");//$NON-NLS-1$ Iterator<?> bands = itembands.iterator(); boolean first = true; while (bands.hasNext()) { Element itemband = (Element) bands.next(); Element itemBandNode = DocumentHelper.createElement("itemband");//$NON-NLS-1$ itemBandsNode.add(itemBandNode); List<?> elementList = itemband.selectNodes("element");//$NON-NLS-1$ Iterator<?> elements = elementList.iterator(); int idx = 0; while (elements.hasNext()) { Element element = (Element) elements.next(); Element elementNode = DocumentHelper.createElement("element");//$NON-NLS-1$ itemBandNode.add(elementNode); elementNode.setText(element.getText()); name = element.selectSingleNode("@name").getText();//$NON-NLS-1$ if (name.endsWith("Element")) {//$NON-NLS-1$ name = name.substring(0, name.length() - "Element".length());//$NON-NLS-1$ } attr = DocumentHelper.createAttribute(elementNode, "name", name);//$NON-NLS-1$ elementNode.add(attr); if (first) { // copy the item name over to the column header attr = DocumentHelper.createAttribute(columnHeaderNodes[idx], "name", name);//$NON-NLS-1$ columnHeaderNodes[idx].add(attr); } idx++; } first = false; } } } return reportDoc; }
From source file:org.pentaho.platform.plugin.services.pluginmgr.SystemPathXmlPluginProvider.java
License:Open Source License
protected void processExternalResources(PlatformPlugin plugin, Document doc) { Node parentNode = doc.selectSingleNode("//external-resources"); //$NON-NLS-1$ if (parentNode == null) { return;/*w w w .ja v a 2 s. co m*/ } for (Object obj : parentNode.selectNodes("file")) { Element node = (Element) obj; if (node != null) { String context = node.attributeValue("context"); //$NON-NLS-1$ String resource = node.getStringValue(); plugin.addExternalResource(context, resource); } } }
From source file:org.pentaho.platform.repository.solution.SolutionRepositoryBase.java
License:Open Source License
public void localizeDoc(final Node document, final ISolutionFile file) { String fileName = file.getFileName(); int dotIndex = fileName.indexOf('.'); String baseName = fileName.substring(0, dotIndex); // TODO read in nodes from the locale file and use them to override the // ones in the main document try {/*from w w w. jav a 2 s. c o m*/ List nodes = document.selectNodes("descendant::*"); //$NON-NLS-1$ Iterator nodeIterator = nodes.iterator(); while (nodeIterator.hasNext()) { Node node = (Node) nodeIterator.next(); String name = node.getText(); if (name.startsWith("%") && !node.getPath().endsWith("/text()")) { //$NON-NLS-1$ //$NON-NLS-2$ try { String localeText = getLocaleString(name, baseName, file, true); if (localeText != null) { node.setText(localeText); } } catch (Exception e) { warn(Messages.getString("SolutionRepository.WARN_MISSING_RESOURCE_PROPERTY", //$NON-NLS-1$ name.substring(1), baseName, getLocale().toString())); } } } } catch (Exception e) { error(Messages.getErrorString("SolutionRepository.ERROR_0007_COULD_NOT_READ_PROPERTIES", //$NON-NLS-1$ file.getFullPath()), e); } }