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.uifoundation.chart.XYZSeriesCollectionChartDefinition.java
License:Open Source License
private void setChartAttributes(final Node chartAttributes) { if (chartAttributes == null) { return;/*from www.j ava2 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(XYZSeriesCollectionChartDefinition.ORIENTATION_NODE_NAME)); // do we want a legend setLegendIncluded(chartAttributes.selectSingleNode(ChartDefinition.INCLUDE_LEGEND_NODE_NAME)); setLegendPosition(chartAttributes.selectSingleNode(ChartDefinition.LEGEND_POSITION_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... XYZSeriesCollectionChartDefinition.getLogger() .warn(Messages.getInstance().getString("CHART.WARN_DEPRECATED_CHILD", //$NON-NLS-1$ ChartDefinition.SUBTITLE_NODE_NAME, ChartDefinition.SUBTITLES_NODE_NAME)); XYZSeriesCollectionChartDefinition.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(XYZSeriesCollectionChartDefinition.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(XYZSeriesCollectionChartDefinition.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(XYZSeriesCollectionChartDefinition.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(XYZSeriesCollectionChartDefinition.DOMAIN_TITLE_NODE_NAME)); // set the domain title font setDomainTitleFont( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.DOMAIN_TITLE_FONT_NODE_NAME)); // set the domain tick font setDomainTickFont( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.DOMAIN_TICK_FONT_NODE_NAME)); // the the domain tick label number format setDomainTickFormat( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.DOMAIN_TICK_FORMAT_NODE_NAME)); // set we want domain to include zero setRangeIncludesZero( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_INCLUDES_ZERO_NODE_NAME)); // set the range title setRangeTitle(chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_TITLE_NODE_NAME)); // the the range font setRangeTitleFont( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_TITLE_FONT_NODE_NAME)); // the the range font setRangeTickFont( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_TICK_FONT_NODE_NAME)); // the the range tick label number format setRangeTickFormat( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_TICK_FORMAT_NODE_NAME)); // set the domain minimum setDomainMinimum( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.DOMAIN_MINIMUM_NODE_NAME)); // set the domain minimum setDomainMaximum( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.DOMAIN_MAXIMUM_NODE_NAME)); // set the range minimum setRangeMinimum( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_MINIMUM_NODE_NAME)); // set the range minimum setRangeMaximum( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_MAXIMUM_NODE_NAME)); // set we want domain to include zero setDomainIncludesZero(chartAttributes .selectSingleNode(XYZSeriesCollectionChartDefinition.DOMAIN_INCLUDES_ZERO_NODE_NAME)); // set we want domain to force zero setDomainStickyZero( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.DOMAIN_STICKY_ZERO_NODE_NAME)); // set we want domain to include zero setRangeIncludesZero( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_INCLUDES_ZERO_NODE_NAME)); // set we want domain to force zero setRangeStickyZero( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.RANGE_STICKY_ZERO_NODE_NAME)); // set the maximum bubble size setMaxBubbleSize( chartAttributes.selectSingleNode(XYZSeriesCollectionChartDefinition.MAX_BUBBLE_SIZE_NODE_NAME)); // set the bubble label content setBubbleLabelContent(chartAttributes .selectSingleNode(XYZSeriesCollectionChartDefinition.BUBBLE_LABEL_CONTENT_NODE_NAME)); // set the bubble label's x value format setXFormat(chartAttributes .selectSingleNode(XYZSeriesCollectionChartDefinition.BUBBLE_LABEL_X_FORMAT_NODE_NAME)); // set the bubble label's y value format setYFormat(chartAttributes .selectSingleNode(XYZSeriesCollectionChartDefinition.BUBBLE_LABEL_Y_FORMAT_NODE_NAME)); // set the bubble label's z value format setZFormat(chartAttributes .selectSingleNode(XYZSeriesCollectionChartDefinition.BUBBLE_LABEL_Z_FORMAT_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)); }
From source file:org.rolap4j.parsers.Dom4jBasedCatalogParser.java
License:Apache License
/** * @param cubeNode//www . j av a2s .co m * @param schema * @return * @throws ParsingException */ private Collection<Measure> getMeasures(Node cubeNode, Schema schema) throws ParsingException { List<Measure> measures = new ArrayList<>(); List<Node> measureNodes = cubeNode.selectNodes("Measure"); String worker; for (Node measureNode : measureNodes) { worker = measureNode.valueOf("@name"); if (StringUtil.isEmpty(worker)) { throw new ParsingException("The name of the measure attribute must be specified"); } Measure measure = new Measure(); measure.setName(worker); measures.add(measure); } return measures; }
From source file:org.rolap4j.parsers.Dom4jBasedCatalogParser.java
License:Apache License
/** * @param cubeNode/* w w w . ja va2 s. c om*/ * @param schema * @return * @throws ParsingException */ private Collection<Dimension> getDimensions(Node cubeNode, final Schema schema) throws ParsingException { List<Dimension> dimensions = new ArrayList<>(); List<Node> dimensionNodes = cubeNode.selectNodes("DimensionUsage"); String worker; for (Node dimensionNode : dimensionNodes) { worker = dimensionNode.valueOf("@name"); if (StringUtil.isEmpty(worker)) { throw new ParsingException("The name of the dimensionUsage attribute must be specified"); } if (!schema.containsDimension(worker)) { StringBuilder names = new StringBuilder(); for (Iterator<String> iter = schema.getDimensions().keySet().iterator(); iter.hasNext();) { names.append(iter.next()).append(", "); } if (names.length() > 0) { names.setLength(names.length() - 1); } throw new ParsingException("Unexpected dimension found : " + worker + " when one of the following dimensions is expected : " + names); } dimensions.add(schema.getDimension(worker)); } return dimensions; }
From source file:org.rolap4j.parsers.Dom4jBasedCatalogParser.java
License:Apache License
/** * Load the current dimension hierachies * * @param dimensionNode/* w ww .j a va2 s . c o m*/ * @param dimensionName * @return list of hierarchies that correspond to the dimension * @throws ParsingException an error occurred when parsing the file */ private List<Hierarchy> loadHierarchies(final Node dimensionNode, final String dimensionName) throws ParsingException { log.debug("Loading all {} hierarchies", dimensionName); List<Node> hierarchiesNodes = dimensionNode.selectNodes("Hierarchy"); List<Hierarchy> hierarchies = new ArrayList<>(); Set<String> notAvailableHierarchyNames = new HashSet<>(); String worker; int sprinter = 1; boolean defaultHierarchyDefined = false; for (Node hierarchyNode : hierarchiesNodes) { worker = hierarchyNode.valueOf("@hasAll"); checkHasAllValidity(worker, dimensionName, sprinter); Hierarchy hierarchy = new Hierarchy(); hierarchy.setHasAll("true".equalsIgnoreCase(worker)); // get the required name ... worker = hierarchyNode.valueOf("@name"); if (StringUtil.isEmpty(worker) && !defaultHierarchyDefined) { throw new ParsingException("An hierarchy name is missing. The hierarchy index is : " + sprinter); } defaultHierarchyDefined = true; // set the name if available ... checkHiearchyAvailability(worker, notAvailableHierarchyNames); hierarchy.setName(worker); // set the hierarchy primary key attribute ... worker = hierarchyNode.valueOf("@primaryKey"); if (StringUtil.isEmpty(worker)) { throw new ParsingException("The following attribute must be specified for the " + dimensionName + " dimension : primaryKey"); } hierarchy.setPrimaryKey(worker); hierarchy.addLevels(loadLevels(hierarchyNode, hierarchy.getName(), dimensionName)); hierarchies.add(hierarchy); log.debug("\tHierarchy {} added to {} hierarchies", hierarchy.getName(), dimensionName); } return hierarchies; }
From source file:org.rolap4j.parsers.Dom4jBasedCatalogParser.java
License:Apache License
/** * Load all levels from an hierarchy node * * @param hierarchyNode The hierarchy node * @param hierarchyName The name of the concerned hierarchy * @param dimensionName The name of the concerned dimension * @return All the levels of the specified hierarchy * @throws ParsingException/*from w w w .j a v a 2s . co m*/ * @see Level */ private List<Level> loadLevels(final Node hierarchyNode, final String hierarchyName, final String dimensionName) throws ParsingException { log.debug("Loading all {} levels ...", hierarchyName); List<Level> levels = new ArrayList<>(); final List<Node> levelNodes = hierarchyNode.selectNodes("Level"); String worker; int sprinter = 1; for (Node levelNode : levelNodes) { worker = levelNode.valueOf("@name"); if (StringUtil.isEmpty(worker)) { StringBuilder exceptionMessage = new StringBuilder(); exceptionMessage.append("The name attribute is missing for the #").append(sprinter) .append(" level of the ").append(hierarchyName).append(" hierarchy of the ") .append(dimensionName).append(" dimension "); throw new ParsingException(exceptionMessage.toString()); } Level level = new Level(); level.setName(worker); worker = levelNode.valueOf("@column"); if (StringUtil.isEmpty(worker)) { throw new ParsingException("A column attribute is required for the " + level.getName()); } level.setColumn(worker); worker = levelNode.valueOf("@uniqueMembers"); checkUniqueMembersValidity(worker, level.getName()); level.setUniqueMembers("true".equalsIgnoreCase(worker)); level.addProperties(loadProperties(levelNode, level.getName(), dimensionName)); log.debug("\tLevel {} added to {} hierarchy", level.getName(), hierarchyName); sprinter++; } return levels; }
From source file:org.rolap4j.parsers.Dom4jBasedCatalogParser.java
License:Apache License
/** * @param levelNode/* w w w . j a v a 2 s .c o m*/ * @param levelName * @param dimensionName * @return * @throws ParsingException */ private Set<Property> loadProperties(final Node levelNode, final String levelName, final String dimensionName) throws ParsingException { log.debug("Loading all {} level properties ...", levelName); Set<Property> properties = new HashSet<>(); List<Node> propertyNodes = levelNode.selectNodes("Property"); String worker; Set<String> notAvailablePropertyNames = new HashSet<>(); for (Node propertyNode : propertyNodes) { worker = propertyNode.valueOf("@name"); if (StringUtil.isEmpty(worker)) { throw new ParsingException( "The name attribute is missing for one or some properties of " + levelName + " level"); } checkPropertyAvailability(worker, notAvailablePropertyNames); final Property property = new Property(); property.setName(worker); worker = propertyNode.valueOf("@column"); if (StringUtil.isEmpty(worker)) { throw new ParsingException("A column attribute is required for " + property.getName() + " property of " + levelName + " level"); } property.setColumn(worker); property.setType(PropertyUtil.getPropertyType(propertyNode.valueOf("@type"))); properties.add(property); } return properties; }
From source file:org.rundeck.api.parser.BulkDeleteParser.java
License:Apache License
@Override public RundeckJobDeleteBulk parse(Node subnode) { final ArrayList<RundeckJobDelete> deletes = new ArrayList<RundeckJobDelete>(); final List results = subnode.selectNodes("(succeeded|failed)/deleteJobResult"); final DeleteParser parser = new DeleteParser(); if (null != results && results.size() > 0) { for (final Object o : results) { deletes.add(parser.parseXmlNode((Node) o)); }/*from w ww . j a v a 2s.c o m*/ } final String requestcount = StringUtils.trimToNull(subnode.valueOf("@requestCount")); final String allsuccessString = StringUtils.trimToNull(subnode.valueOf("@allsuccessful")); int count = 0; boolean allsuccess = false; if (null != requestcount) { try { count = Integer.parseInt(requestcount); } catch (NumberFormatException e) { } } if (null != allsuccessString) { allsuccess = Boolean.parseBoolean(allsuccessString); } return new RundeckJobDeleteBulk(deletes, count, allsuccess); }
From source file:org.rundeck.api.parser.HistoryParser.java
License:Apache License
@Override public RundeckHistory parse(Node eventsNode) { RundeckHistory history = new RundeckHistory(); history.setCount(Integer.valueOf(eventsNode.valueOf("@count"))); history.setTotal(Integer.valueOf(eventsNode.valueOf("@total"))); history.setMax(Integer.valueOf(eventsNode.valueOf("@max"))); history.setOffset(Integer.valueOf(eventsNode.valueOf("@offset"))); @SuppressWarnings("unchecked") List<Node> eventNodes = eventsNode.selectNodes("event"); EventParser eventParser = new EventParser(); for (Node eventNode : eventNodes) { RundeckEvent event = eventParser.parseXmlNode(eventNode); history.addEvent(event);/*from w w w . j a v a2 s . co m*/ } return history; }
From source file:org.rundeck.api.parser.JobsImportResultParser.java
License:Apache License
@Override public RundeckJobsImportResult parse(Node resultNode) { RundeckJobsImportResult result = new RundeckJobsImportResult(); @SuppressWarnings("unchecked") List<Node> succeededJobsNodes = resultNode.selectNodes("succeeded/job"); if (succeededJobsNodes != null) { for (Node succeededJobNode : succeededJobsNodes) { RundeckJob job = new JobParser().parseXmlNode(succeededJobNode); result.addSucceededJob(job); }//w w w . j a v a 2 s. co m } @SuppressWarnings("unchecked") List<Node> skippedJobsNodes = resultNode.selectNodes("skipped/job"); if (skippedJobsNodes != null) { for (Node skippedJobNode : skippedJobsNodes) { RundeckJob job = new JobParser().parseXmlNode(skippedJobNode); result.addSkippedJob(job); } } @SuppressWarnings("unchecked") List<Node> failedJobsNodes = resultNode.selectNodes("failed/job"); if (failedJobsNodes != null) { for (Node failedJobNode : failedJobsNodes) { RundeckJob job = new JobParser().parseXmlNode(failedJobNode); result.addFailedJob(job, failedJobNode.valueOf("error")); } } return result; }
From source file:org.rundeck.api.parser.ListParser.java
License:Apache License
@Override public List<T> parseXmlNode(Node node) { List<T> elements = new ArrayList<T>(); @SuppressWarnings("unchecked") List<Node> elementNodes = node.selectNodes(BaseXpathParser.unwrapXpath(node, xpath)); for (Node elementNode : elementNodes) { T element = parser.parseXmlNode(elementNode); elements.add(element);/*from w ww . j a va 2 s. c o m*/ } return elements; }