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.cdf.NavigateComponent.java
License:Open Source License
private Node getDirectoryNode(Node node, final String _path) { final String[] pathArray = _path.split("/"); if (pathArray.length > 0) { final String path = pathArray[0]; final String xPathDir = "./file[@name='" + path + "']"; //$NON-NLS-1$ final List nodes = node.selectNodes(xPathDir); //$NON-NLS-1$ if (!nodes.isEmpty() && nodes.size() == 1) { node = (Node) nodes.get(0); if (!_path.equals(path)) { node = getDirectoryNode(node, _path.substring(_path.indexOf(path) + path.length() + 1, _path.length())); }// w ww .ja v a 2s. com } else { return node; } } return node; }
From source file:org.pentaho.commons.connection.memory.MemoryResultSet.java
License:Open Source License
public static MemoryResultSet createFromActionSequenceInputsNode(Node rootNode) { List colHeaders = rootNode.selectNodes("columns/*"); //$NON-NLS-1$ Object[][] columnHeaders = new String[1][colHeaders.size()]; String[] columnTypes = new String[colHeaders.size()]; for (int i = 0; i < colHeaders.size(); i++) { Node theNode = (Node) colHeaders.get(i); columnHeaders[0][i] = theNode.getName(); columnTypes[i] = getNodeText("@type", theNode); //$NON-NLS-1$ }//ww w . j ava2s. com MemoryMetaData metaData = new MemoryMetaData(columnHeaders, null); metaData.setColumnTypes(columnTypes); MemoryResultSet result = new MemoryResultSet(metaData); List rowNodes = rootNode.selectNodes("default-value/row"); //$NON-NLS-1$ for (int r = 0; r < rowNodes.size(); r++) { Node theNode = (Node) rowNodes.get(r); Object[] theRow = new Object[columnHeaders[0].length]; for (int c = 0; c < columnHeaders[0].length; c++) { theRow[c] = getNodeText(columnHeaders[0][c].toString(), theNode); } result.addRow(theRow); } return result; }
From source file:org.pentaho.di.baserver.utils.inspector.WadlParser.java
License:Open Source License
protected Collection<Endpoint> parseResources(Node resourceNode, final String parentPath) { String path = resourceNode.valueOf("@path"); if (path.isEmpty()) { path = parentPath;/* w w w .ja va 2 s. c o m*/ } else { path = parentPath + "/" + sanitizePath(path); } TreeSet<Endpoint> endpoints = new TreeSet<Endpoint>(); for (Object methodNode : resourceNode.selectNodes("*[local-name() = 'method']")) { endpoints.add(parseMethod((Node) methodNode, path)); } for (Object innerResourceNode : resourceNode.selectNodes("*[local-name() = 'resource']")) { endpoints.addAll(parseResources((Node) innerResourceNode, path)); } return endpoints; }
From source file:org.pentaho.di.baserver.utils.inspector.WadlParser.java
License:Open Source License
protected Endpoint parseMethod(Node methodNode, final String path) { Endpoint endpoint = new Endpoint(); endpoint.setId(methodNode.valueOf("@id")); endpoint.setHttpMethod(HttpMethod.valueOf(methodNode.valueOf("@name"))); endpoint.setPath(shortPath(path));// w w w. j a va 2s.c o m Node requestNode = methodNode.selectSingleNode("*[local-name() = 'request']"); if (requestNode != null) { for (Object queryParamNode : requestNode.selectNodes("*[local-name() = 'param']")) { endpoint.getQueryParams().add(parseQueryParam((Node) queryParamNode)); } } Node nodeDoc = methodNode.selectSingleNode("*[local-name() = 'doc']"); if (nodeDoc != null) { endpoint.setDeprecated(isDeprecated(nodeDoc.getText())); endpoint.setDocumentation(extractComment(nodeDoc.getText())); endpoint.setSupported(isSupported(nodeDoc.getText())); } return endpoint; }
From source file:org.pentaho.platform.engine.services.actionsequence.ActionDefinition.java
License:Open Source License
public ActionDefinition(final Node actionRootNode, final ILogger logger) { this.actionRootNode = actionRootNode; errorCode = ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; // this.sequenceData = sequenceData; // get the input parameter definitions actionInputDefinitions = new ListOrderedMap(); actionInputMapping = new ListOrderedMap(); errorCode = SequenceDefinition.parseParameters(actionRootNode, logger, "action-inputs/*", //$NON-NLS-1$ actionInputDefinitions, actionInputMapping, true); // get the ouput definitions actionOutputDefinitions = new ListOrderedMap(); actionOutputMapping = new ListOrderedMap(); errorCode = SequenceDefinition.parseParameters(actionRootNode, logger, "action-outputs/*", //$NON-NLS-1$ actionOutputDefinitions, actionOutputMapping, false); // get the resource definitions actionResourceMapping = new ListOrderedMap(); if (actionRootNode.selectNodes("action-resources/*").size() > 0) { //$NON-NLS-1$ hasActionResources = true;/*from w ww.j a va 2 s .c o m*/ errorCode = SequenceDefinition.parseActionResourceDefinitions(actionRootNode, logger, "action-resources/*", actionResourceMapping); //$NON-NLS-1$ } componentName = XmlDom4JHelper.getNodeText("component-name", actionRootNode); //$NON-NLS-1$ String loggingLevelString = XmlDom4JHelper.getNodeText("logging-level", actionRootNode); //$NON-NLS-1$ loggingLevel = Logger.getLogLevel(loggingLevelString); // get the component payload componentNode = actionRootNode.selectSingleNode("component-definition"); //$NON-NLS-1$ if (componentNode == null) { componentNode = ((Element) actionRootNode).addElement("component-definition"); //$NON-NLS-1$ } // TODO populate preExecuteAuditList and postExecuteAuditList }
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
private static IActionSequence getNextLoopGroup(final ISequenceDefinition seqDef, final Node actionsNode, final String solutionPath, final ILogger logger, final int loggingLevel) { String loopParameterName = XmlDom4JHelper.getNodeText("@loop-on", actionsNode); //$NON-NLS-1$ boolean loopUsingPeek = "true".equalsIgnoreCase(XmlDom4JHelper.getNodeText("@peek-only", actionsNode)); //$NON-NLS-1$ //$NON-NLS-2$ Node actionDefinitionNode;/*from w w w . j a v a 2 s. c om*/ ActionDefinition actionDefinition; List actionDefinitionList = new ArrayList(); List nodeList = actionsNode.selectNodes("*"); //$NON-NLS-1$ Iterator actionDefinitionNodes = nodeList.iterator(); while (actionDefinitionNodes.hasNext()) { actionDefinitionNode = (Node) actionDefinitionNodes.next(); if (actionDefinitionNode.getName().equals("actions")) { //$NON-NLS-1$ actionDefinitionList.add(SequenceDefinition.getNextLoopGroup(seqDef, actionDefinitionNode, solutionPath, logger, loggingLevel)); } else if (actionDefinitionNode.getName().equals("action-definition")) { //$NON-NLS-1$ actionDefinition = new ActionDefinition(actionDefinitionNode, logger); actionDefinition.setLoggingLevel(loggingLevel); actionDefinitionList.add(actionDefinition); } } // action sequences with 0 actions are valid, see: JIRA PLATFORM-837 IConditionalExecution conditionalExecution = SequenceDefinition.parseConditionalExecution(actionsNode, logger, "condition"); //$NON-NLS-1$ ActionSequence sequence = new ActionSequence(loopParameterName, seqDef, actionDefinitionList, loopUsingPeek); sequence.setConditionalExecution(conditionalExecution); return sequence; }
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
static int parseParameters(final Node actionRootNode, final ILogger logger, final String nodePath, final Map parameterMap, final Map mapTo, final boolean inputVar) { try {/*from w w w. j a v a 2 s .c om*/ List parameters = actionRootNode.selectNodes(nodePath); // TODO create objects to represent the types // TODO need source variable list Iterator parametersIterator = parameters.iterator(); Node parameterNode; String parameterName; String parameterType; ActionParameter parameter; List variableNodes; List variables; Node variableNode; Iterator variablesIterator; String variableSource; String variableName; int variableIdx; Object defaultValue = null; while (parametersIterator.hasNext()) { parameterNode = (Node) parametersIterator.next(); parameterName = parameterNode.getName(); parameterType = XmlDom4JHelper.getNodeText("@type", parameterNode); //$NON-NLS-1$ if (mapTo != null) { mapTo.put(parameterName, XmlDom4JHelper.getNodeText("@mapping", parameterNode, parameterName)); //$NON-NLS-1$ } defaultValue = SequenceDefinition.getDefaultValue(parameterNode); // get the list of sources for this parameter variableNodes = parameterNode.selectNodes((inputVar) ? "sources/*" : "destinations/*"); //$NON-NLS-1$ //$NON-NLS-2$ variablesIterator = variableNodes.iterator(); variableIdx = 1; variables = new ArrayList(); while (variablesIterator.hasNext()) { variableNode = (Node) variablesIterator.next(); // try to resolve the parameter value for this try { variableSource = variableNode.getName(); variableName = variableNode.getText(); ActionParameterSource variable = new ActionParameterSource(variableSource, variableName); if (SequenceDefinition.debug) { logger.debug(Messages.getInstance().getString( "SequenceDefinition.DEBUG_ADDING_SOURCE_FOR_PARAMETER", variableSource, //$NON-NLS-1$ parameterName)); } variables.add(variable); } catch (Exception e) { logger.error(Messages.getInstance().getErrorString( "SequenceDefinition.ERROR_0004_VARIABLE_SOURCE_NOT_VALID", //$NON-NLS-1$ Integer.toString(variableIdx), parameterName), e); } variableIdx++; } if (defaultValue != null) { if (SequenceDefinition.debug) { logger.debug( Messages.getInstance().getString("SequenceDefinition.DEBUG_USING_DEFAULT_VALUE", //$NON-NLS-1$ defaultValue.toString(), parameterName)); } } boolean isOutputParameter = Boolean .parseBoolean(XmlDom4JHelper.getNodeText("@is-output-parameter", parameterNode, "true")); //$NON-NLS-1$ //$NON-NLS-2$ parameter = new ActionParameter(parameterName, parameterType, null, variables, defaultValue); parameter.setOutputParameter(isOutputParameter); parameterMap.put(parameterName, parameter); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error(Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"), //$NON-NLS-1$ e); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
private int parseResourceDefinitions(final Node actionRootNode, final ILogger logger) { resourceDefinitions = new ListOrderedMap(); try {/*from w ww . j a va 2s .c om*/ List resources = actionRootNode.selectNodes("resources/*"); //$NON-NLS-1$ // TODO create objects to represent the types // TODO need source variable list Iterator resourcesIterator = resources.iterator(); Node resourceNode; String resourceName; String resourceTypeName; String resourceMimeType; int resourceType; ActionSequenceResource resource; Node typeNode, mimeNode; while (resourcesIterator.hasNext()) { resourceNode = (Node) resourcesIterator.next(); typeNode = resourceNode.selectSingleNode("./*"); //$NON-NLS-1$ if (typeNode != null) { resourceName = resourceNode.getName(); resourceTypeName = typeNode.getName(); resourceType = ActionSequenceResource.getResourceType(resourceTypeName); String resourceLocation = XmlDom4JHelper.getNodeText("location", typeNode); //$NON-NLS-1$ if ((resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resourceType == IActionSequenceResource.FILE_RESOURCE)) { if (resourceLocation == null) { logger.error(Messages.getInstance().getErrorString( "SequenceDefinition.ERROR_0008_RESOURCE_NO_LOCATION", resourceName)); //$NON-NLS-1$ continue; } } else if (resourceType == IActionSequenceResource.STRING) { resourceLocation = XmlDom4JHelper.getNodeText("string", resourceNode); //$NON-NLS-1$ } else if (resourceType == IActionSequenceResource.XML) { //resourceLocation = XmlHelper.getNodeText("xml", resourceNode); //$NON-NLS-1$ Node xmlNode = typeNode.selectSingleNode("./location/*"); //$NON-NLS-1$ // Danger, we have now lost the character encoding of the XML in this node // see BISERVER-895 resourceLocation = (xmlNode == null) ? "" : xmlNode.asXML(); //$NON-NLS-1$ } mimeNode = typeNode.selectSingleNode("mime-type"); //$NON-NLS-1$ if (mimeNode != null) { resourceMimeType = mimeNode.getText(); if ((resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) || (resourceType == IActionSequenceResource.FILE_RESOURCE)) { resourceLocation = FilenameUtils.separatorsToUnix(resourceLocation); if (!resourceLocation.startsWith("/")) { //$NON-NLS-1$ String parentDir = FilenameUtils.getFullPathNoEndSeparator(xactionPath); if (parentDir.length() == 0) { parentDir = RepositoryFile.SEPARATOR; } resourceLocation = FilenameUtils .separatorsToUnix(FilenameUtils.concat(parentDir, resourceLocation)); } } resource = new ActionSequenceResource(resourceName, resourceType, resourceMimeType, resourceLocation); resourceDefinitions.put(resourceName, resource); } else { logger.error(Messages.getInstance().getErrorString( "SequenceDefinition.ERROR_0007_RESOURCE_NO_MIME_TYPE", resourceName)); //$NON-NLS-1$ } } // input = new ActionParameter( resourceName, resourceType, null // ); // resourceDefinitions.put( inputName, input ); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error(Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"), //$NON-NLS-1$ e); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
/** * sbarkdull: method appears to never be used anywhere * /*from ww w. j a v a 2 s . c o m*/ * @param actionRootNode * @param logger * @param nodePath * @param mapTo * @return */ static int parseActionResourceDefinitions(final Node actionRootNode, final ILogger logger, final String nodePath, final Map mapTo) { try { List resources = actionRootNode.selectNodes(nodePath); // TODO create objects to represent the types // TODO need source variable list Iterator resourcesIterator = resources.iterator(); Node resourceNode; String resourceName; while (resourcesIterator.hasNext()) { resourceNode = (Node) resourcesIterator.next(); resourceName = resourceNode.getName(); if (mapTo != null) { mapTo.put(resourceName, XmlDom4JHelper.getNodeText("@mapping", resourceNode, resourceName)); //$NON-NLS-1$ } } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error(Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"), //$NON-NLS-1$ e); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }
From source file:org.pentaho.platform.engine.services.actionsequence.SequenceDefinition.java
License:Open Source License
private static Object getDefaultValue(final Node parameterNode) { Node rootNode = parameterNode.selectSingleNode("default-value"); //$NON-NLS-1$ if (rootNode == null) { return (null); }// w w w . jav a2 s.c o m String dataType = XmlDom4JHelper.getNodeText("@type", rootNode); //$NON-NLS-1$ if (dataType == null) { dataType = XmlDom4JHelper.getNodeText("@type", parameterNode); //$NON-NLS-1$ } if ("string-list".equals(dataType)) { //$NON-NLS-1$ List nodes = rootNode.selectNodes("list-item"); //$NON-NLS-1$ if (nodes == null) { return (null); } ArrayList rtnList = new ArrayList(); for (Iterator it = nodes.iterator(); it.hasNext();) { rtnList.add(((Node) it.next()).getText()); } return (rtnList); } else if ("property-map-list".equals(dataType)) { //$NON-NLS-1$ List nodes = rootNode.selectNodes("property-map"); //$NON-NLS-1$ if (nodes == null) { return (null); } ArrayList rtnList = new ArrayList(); for (Iterator it = nodes.iterator(); it.hasNext();) { Node mapNode = (Node) it.next(); rtnList.add(SequenceDefinition.getMapFromNode(mapNode)); } return (rtnList); } else if ("property-map".equals(dataType)) { //$NON-NLS-1$ return (SequenceDefinition.getMapFromNode(rootNode.selectSingleNode("property-map"))); //$NON-NLS-1$ } else if ("long".equals(dataType)) { //$NON-NLS-1$ try { return (new Long(rootNode.getText())); } catch (Exception e) { //ignore } return (null); } else if ("result-set".equals(dataType)) { //$NON-NLS-1$ return (MemoryResultSet.createFromActionSequenceInputsNode(parameterNode)); } else { // Assume String return (rootNode.getText()); } }