List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:org.pentaho.cdf.NavigateComponent.java
License:Open Source License
@SuppressWarnings("unchecked") private JSONArray processTree(final Node tree, final String parentPath, boolean includeAllFiles) { final String xPathDir = "./file[@isDirectory='true']"; //$NON-NLS-1$ JSONArray array = null;/* w w w. ja v a2 s .co m*/ try { final List nodes = tree.selectNodes(xPathDir); //$NON-NLS-1$ if (!nodes.isEmpty()) { array = new JSONArray(); } final String[] parentPathArray = parentPath.split("/"); final String solutionName = parentPathArray.length > 2 ? parentPathArray[2] : ""; final String solutionPath = parentPathArray.length > 3 ? parentPath.substring(parentPath.indexOf(solutionName) + solutionName.length() + 1, parentPath.length()) + "/" : ""; for (final Object node1 : nodes) { final Node node = (Node) node1; final JSONObject json = new JSONObject(); JSONArray children = null; String name = node.valueOf("@name"); if (parentPathArray.length > 0) { final String localizedName = node.valueOf("@localized-name"); final String description = node.valueOf("@description"); final boolean visible = node.valueOf("@visible").equals("true"); final boolean isDirectory = node.valueOf("@isDirectory").equals("true"); final String path = solutionName.length() == 0 ? "" : solutionPath + name; final String solution = solutionName.length() == 0 ? name : solutionName; json.put("id", parentPath + "/" + name); json.put("name", name); json.put("solution", solution); json.put("path", path); json.put("type", TYPE_DIR); json.put("visible", visible); json.put("title", visible ? localizedName : "Hidden"); json.put("description", description); if (visible && isDirectory) { children = processTree(node, parentPath + "/" + name, includeAllFiles); json.put("files", new JSONArray()); // Process directory wcdf/xcdf files List<Node> fileNodes; if (includeAllFiles) { fileNodes = node.selectNodes("./file[@isDirectory='false']"); } else { fileNodes = node.selectNodes( "./file[@isDirectory='false'][ends-with(string(@name),'.xcdf') or ends-with(string(@name),'.wcdf')]"); } for (final Node fileNode : fileNodes) { processFileNode(json, fileNode, "files"); } } } else { // root dir json.put("id", tree.valueOf("@path")); json.put("name", solutionName); json.put("path", solutionPath); json.put("visible", true); json.put("title", "Solution"); children = processTree(tree, tree.valueOf("@path"), includeAllFiles); } // System.out.println(" Processing getting children "); if (children != null) { json.put("folders", children); } array.put(json); } } catch (Exception e) { System.out.println("Error: " + e.getClass().getName() + " - " + e.getMessage()); logger.warn("Error: " + e.getClass().getName() + " - " + e.getMessage()); } return array; }
From source file:org.pentaho.cdf.NavigateComponent.java
License:Open Source License
private void processFileNode(JSONObject json, Node fileNode, String placeholder) throws JSONException { /* Get the hashTable that contains the pairs: supported-file-type -> associated url to use */ final Hashtable<String, String> readAbility = PluginCatalogEngine.getInstance().getPlugins(); String link = ""; String _solution = json.getString("solution"); String _path = json.getString("path"); String relativeUrl = contextPath; String name = fileNode.valueOf("@name"); final String type = name.substring(name.lastIndexOf(".") + 1, name.length()); if (relativeUrl.endsWith("/")) { relativeUrl = relativeUrl.substring(0, relativeUrl.length() - 1); }// www . j a v a 2 s . c o m final String path = type.equals(TYPE_DIR) ? (_path.length() > 0 ? _path + "/" + name : name) : _path; /* create the link */ final String lowType = type.toLowerCase(); if (readAbility.containsKey(lowType)) { String s = "/" + readAbility.get(lowType); /* Replace the generic variable names for the variable values */ s = s.replace("{solution}", _solution); s = s.replace("{path}", path); s = s.replace("{name}", name); s = s.replaceAll("&", "&"); link = link + s; JSONObject file = new JSONObject(); file.put("file", name); file.put("solution", json.get("solution")); file.put("path", json.get("path")); file.put("type", type); file.put("visible", fileNode.valueOf("@visible").equals("true")); file.put("title", fileNode.valueOf("@localized-name")); file.put("description", fileNode.valueOf("@description")); file.put("link", link); json.append(placeholder, file); return; } else { // If we don't know this, don't return it return; } }
From source file:org.pentaho.cdf.NavigateComponent.java
License:Open Source License
private String getContentListJSON(final String _solution, final String _path) { String jsonString = null;//w ww .j a v a2 s .c o m JSONArray array = null; try { final JSONObject json = new JSONObject(); final Document navDoc = getRepositoryDocument(this.userSession); final Node tree = navDoc.getRootElement(); final String xPathDir = "./file[@name='" + _solution + "']"; //$NON-NLS-1$ List nodes = tree.selectNodes(xPathDir); //$NON-NLS-1$ if (!nodes.isEmpty() && nodes.size() == 1) { // Add Folder final Node node = getDirectoryNode((Node) nodes.get(0), _path); json.put("name", node.valueOf("@name")); json.put("id", _solution + "/" + _path); json.put("solution", _solution); json.put("path", _path); json.put("type", TYPE_DIR); json.put("visible", false); json.put("title", "Hidden"); array = new JSONArray(); json.put("content", array); nodes = node.selectNodes("./file"); // Add Folder Content for (final Object fileNode : nodes) { processFileNode(json, (Node) fileNode, "content"); } } jsonString = json.toString(2); } catch (Exception e) { System.out.println("Error: " + e.getClass().getName() + " - " + e.getMessage()); logger.warn("Error: " + e.getClass().getName() + " - " + e.getMessage()); } // debug("Finished processing tree"); return jsonString; }
From source file:org.pentaho.di.baserver.utils.inspector.WadlParser.java
License:Open Source License
public Collection<Endpoint> getEndpoints(Document doc) { Node resources = doc.selectSingleNode("/application/child::*[local-name() = 'resources' ]"); if (resources != null) { return parseResources(resources, sanitizePath(resources.valueOf("@base"))); }/*ww w . java2s . c om*/ return Collections.emptySet(); }
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;/*from w w w .j a v a2s . c om*/ } 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));//from w w w. j a v a 2 s . c om 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.di.baserver.utils.inspector.WadlParser.java
License:Open Source License
protected QueryParam parseQueryParam(Node queryParamNode) { QueryParam queryParam = new QueryParam(); queryParam.setName(queryParamNode.valueOf("@name")); queryParam.setType(queryParamNode.valueOf("@type")); return queryParam; }
From source file:org.pentaho.di.trans.steps.getxmldata.GetXMLData.java
License:Apache License
private Object[] processPutRow(Node node) throws KettleException { // Create new row... Object[] outputRowData = buildEmptyRow(); // Create new row or clone if (meta.isInFields()) { System.arraycopy(data.readrow, 0, outputRowData, 0, data.nrReadRow); }//from www .j a v a2 s . c om try { data.nodenr++; // Read fields... for (int i = 0; i < data.nrInputFields; i++) { // Get field GetXMLDataField xmlDataField = meta.getInputFields()[i]; // Get the Path to look for String XPathValue = xmlDataField.getResolvedXPath(); if (meta.isuseToken()) { // See if user use Token inside path field // The syntax is : @_Fieldname- // PDI will search for Fieldname value and replace it // Fieldname must be defined before the current node XPathValue = substituteToken(XPathValue, outputRowData); if (isDetailed()) { logDetailed(XPathValue); } } // Get node value String nodevalue; // Handle namespaces if (meta.isNamespaceAware()) { XPath xpathField = node.createXPath(addNSPrefix(XPathValue, data.PathValue)); xpathField.setNamespaceURIs(data.NAMESPACE); if (xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF) { nodevalue = xpathField.valueOf(node); } else { // nodevalue=xpathField.selectSingleNode(node).asXML(); Node n = xpathField.selectSingleNode(node); if (n != null) { nodevalue = n.asXML(); } else { nodevalue = ""; } } } else { if (xmlDataField.getResultType() == GetXMLDataField.RESULT_TYPE_VALUE_OF) { nodevalue = node.valueOf(XPathValue); } else { // nodevalue=node.selectSingleNode(XPathValue).asXML(); Node n = node.selectSingleNode(XPathValue); if (n != null) { nodevalue = n.asXML(); } else { nodevalue = ""; } } } // Do trimming switch (xmlDataField.getTrimType()) { case GetXMLDataField.TYPE_TRIM_LEFT: nodevalue = Const.ltrim(nodevalue); break; case GetXMLDataField.TYPE_TRIM_RIGHT: nodevalue = Const.rtrim(nodevalue); break; case GetXMLDataField.TYPE_TRIM_BOTH: nodevalue = Const.trim(nodevalue); break; default: break; } // Do conversions // ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(data.totalpreviousfields + i); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(data.totalpreviousfields + i); outputRowData[data.totalpreviousfields + i] = targetValueMeta.convertData(sourceValueMeta, nodevalue); // Do we need to repeat this field if it is null? if (meta.getInputFields()[i].isRepeated()) { if (data.previousRow != null && Utils.isEmpty(nodevalue)) { outputRowData[data.totalpreviousfields + i] = data.previousRow[data.totalpreviousfields + i]; } } } // End of loop over fields... int rowIndex = data.totalpreviousfields + data.nrInputFields; // See if we need to add the filename to the row... if (meta.includeFilename() && !Utils.isEmpty(meta.getFilenameField())) { outputRowData[rowIndex++] = data.filename; } // See if we need to add the row number to the row... if (meta.includeRowNumber() && !Utils.isEmpty(meta.getRowNumberField())) { outputRowData[rowIndex++] = data.rownr; } // Possibly add short filename... if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) { outputRowData[rowIndex++] = data.shortFilename; } // Add Extension if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) { outputRowData[rowIndex++] = data.extension; } // add path if (meta.getPathField() != null && meta.getPathField().length() > 0) { outputRowData[rowIndex++] = data.path; } // Add Size if (meta.getSizeField() != null && meta.getSizeField().length() > 0) { outputRowData[rowIndex++] = data.size; } // add Hidden if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) { outputRowData[rowIndex++] = Boolean.valueOf(data.path); } // Add modification date if (meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0) { outputRowData[rowIndex++] = data.lastModificationDateTime; } // Add Uri if (meta.getUriField() != null && meta.getUriField().length() > 0) { outputRowData[rowIndex++] = data.uriName; } // Add RootUri if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) { outputRowData[rowIndex] = data.rootUriName; } RowMetaInterface irow = getInputRowMeta(); if (irow == null) { data.previousRow = outputRowData; } else { // clone to previously allocated array to make sure next step doesn't // change it in between... System.arraycopy(outputRowData, 0, this.prevRow, 0, outputRowData.length); // Pick up everything else that needs a real deep clone data.previousRow = irow.cloneRow(outputRowData, this.prevRow); } } catch (Exception e) { if (getStepMeta().isDoingErrorHandling()) { // Simply add this row to the error row putError(data.outputRowMeta, outputRowData, 1, e.toString(), null, "GetXMLData001"); data.errorInRowButContinue = true; return null; } else { logError(e.toString()); throw new KettleException(e.toString()); } } return outputRowData; }
From source file:org.pentaho.platform.plugin.action.openflashchart.factory.AbstractChartFactory.java
License:Open Source License
/** * Setup colors for the series and also background *///from w w w.ja v a 2s. 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.quickbundle.mda.gc.ConfigTableDialog.java
License:Open Source License
private void createCustomColumnArea(Composite container, int columns) { GridData gd = null;/*from w w w .j a v a 2 s. co m*/ //1 Config1MainRuleWizardPage.createLine(container, columns); //? final Button isBuildHead = new Button(container, SWT.CHECK); gd = new GridData(); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.END; gd.grabExcessHorizontalSpace = true; isBuildHead.setLayoutData(gd); isBuildHead.setSelection(true); isBuildHead.setToolTipText(""); isBuildHead.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { for (Iterator itMColumn = mColumn.keySet().iterator(); itMColumn.hasNext();) { String index = (String) itMColumn.next(); Button tmpIsBuild = (Button) ((Object[]) mColumn.get(index))[1]; tmpIsBuild.setSelection(isBuildHead.getSelection()); } } }); Label isBuildHead_list = new Label(container, SWT.NONE); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.END; gd.grabExcessHorizontalSpace = true; isBuildHead_list.setLayoutData(gd); isBuildHead_list.setText(""); isBuildHead_list.setToolTipText("?"); //???? Label label_columnName = new Label(container, SWT.NONE); label_columnName.setText("??"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_columnName.setLayoutData(gd); //????(???) Label label_columnNameDisplay = new Label(container, SWT.NONE); label_columnNameDisplay.setText("??"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_columnNameDisplay.setLayoutData(gd); //??java Label label_dataType = new Label(container, SWT.NONE); label_dataType.setText("java"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_dataType.setLayoutData(gd); //???? Label label_displayType = new Label(container, SWT.NONE); label_displayType.setText("?"); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_displayType.setLayoutData(gd); //???? Label label_displayTypeKeyword = new Label(container, SWT.NONE); label_displayTypeKeyword.setText(""); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; label_displayTypeKeyword.setLayoutData(gd); Document docTable = gcRule.getTableDoc(currentTable); java.util.List lColumn = docTable.selectNodes("/meta/tables/table[1]/column"); int indexColumn = 100; for (Iterator itLColumn = lColumn.iterator(); itLColumn.hasNext();) { Object[] columnInfo = new Object[8]; Node node = (Node) itLColumn.next(); columnInfo[0] = node.valueOf("@columnName"); //? Button isBuild = new Button(container, SWT.CHECK); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.END; gd.grabExcessHorizontalSpace = true; isBuild.setLayoutData(gd); if ("true".equals(node.valueOf("@isBuild"))) { isBuild.setSelection(true); } else { isBuild.setSelection(false); } columnInfo[1] = isBuild; //?_list Button isBuild_list = new Button(container, SWT.CHECK); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalSpan = 1; gd.horizontalAlignment = GridData.END; gd.grabExcessHorizontalSpace = true; isBuild_list.setLayoutData(gd); if ("true".equals(node.valueOf("@isBuild_list"))) { isBuild_list.setSelection(true); } else { isBuild_list.setSelection(false); } columnInfo[7] = isBuild_list; //?? Text columnName = new Text(container, SWT.BORDER | SWT.READ_ONLY); columnName.setText(node.valueOf("@columnName")); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; columnName.setLayoutData(gd); columnInfo[2] = columnName; //??(???) Text columnNameDisplay = new Text(container, SWT.BORDER); columnNameDisplay.setText(node.valueOf("@columnNameDisplay")); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; columnNameDisplay.setLayoutData(gd); columnInfo[3] = columnNameDisplay; // columnNameDisplay = new Text(container, SWT.BORDER); // | SWT.READ_ONLY columnNameDisplay.setText(node.valueOf("@dataType")); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; columnNameDisplay.setLayoutData(gd); columnInfo[4] = columnNameDisplay; //? Combo humanDisplayType = new Combo(container, SWT.BORDER | SWT.READ_ONLY); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.horizontalAlignment = GridData.FILL; humanDisplayType.setLayoutData(gd); String[] xmlDisplayType = null; { Node[] tempNode = (Node[]) gcRule.getMainRule() .selectNodes("/rules/dataType/humanDisplayTypes/humanDisplayType/text()") .toArray(new Node[0]); xmlDisplayType = new String[tempNode.length]; for (int j = 0; j < tempNode.length; j++) { xmlDisplayType[j] = tempNode[j].getText(); } } humanDisplayType.setItems(xmlDisplayType); humanDisplayType.setText(node.valueOf("@humanDisplayType")); columnInfo[5] = humanDisplayType; //? Text humanDisplayTypeKeyword = new Text(container, SWT.BORDER); humanDisplayTypeKeyword.setText(node.valueOf("@humanDisplayTypeKeyword")); gd = new GridData(GridData.VERTICAL_ALIGN_FILL); gd.widthHint = 150; gd.horizontalAlignment = GridData.BEGINNING; gd.grabExcessHorizontalSpace = true; humanDisplayTypeKeyword.setLayoutData(gd); columnInfo[6] = humanDisplayTypeKeyword; mColumn.put(String.valueOf(indexColumn), columnInfo); indexColumn++; } }