List of usage examples for org.apache.commons.httpclient.util ParameterParser parse
public List parse(char[] paramArrayOfChar, char paramChar)
From source file:be.ibridge.kettle.url.UrlInput.java
private Object[] buildRow() throws KettleException { Object[] outputRowData = RowDataUtil.resizeArray(data.readrow, data.convertRowMeta.size()); // Read fields... for (int i = 0; i < data.nrInputFields; i++) { // Get field UrlInputField field = meta.getInputFields()[i]; // get url array for field ParameterParser p = new ParameterParser(); List l = p.parse(data.urlToParse.getQuery(), '&'); String nodevalue = ""; Iterator iter = l.iterator(); while (iter.hasNext()) { NameValuePair param = (NameValuePair) iter.next(); if (param.getName().equalsIgnoreCase(field.getValue())) { nodevalue = param.getValue(); }//ww w .j a v a2s . c o m } // Do trimming switch (field.getTrimType()) { case UrlInputField.TYPE_TRIM_LEFT: nodevalue = Const.ltrim(nodevalue); break; case UrlInputField.TYPE_TRIM_RIGHT: nodevalue = Const.rtrim(nodevalue); break; case UrlInputField.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 && Const.isEmpty(nodevalue)) { outputRowData[data.totalpreviousfields + i] = data.previousRow[data.totalpreviousfields + i]; } } } // End of loop over fields... int rowIndex = data.totalpreviousfields + data.nrInputFields; if (meta.getAuthorityField() != null && meta.getAuthorityField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getAuthority(); } if (meta.getDefaultPortField() != null && meta.getDefaultPortField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getDefaultPort(); } if (meta.getFileField() != null && meta.getFileField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getFile(); } if (meta.getHostField() != null && meta.getHostField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getHost(); } if (meta.getPathField() != null && meta.getPathField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getPath(); } if (meta.getPortField() != null && meta.getPortField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getPort(); } if (meta.getProtocolField() != null && meta.getProtocolField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getProtocol(); } if (meta.getQueryField() != null && meta.getQueryField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getQuery(); } if (meta.getRefField() != null && meta.getRefField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getRef(); } if (meta.getUserInfoField() != null && meta.getUserInfoField().length() > 0) { outputRowData[rowIndex++] = data.urlToParse.getUserInfo(); } if (meta.getUriNameField() != null && meta.getUriNameField().length() > 0) { try { outputRowData[rowIndex++] = data.urlToParse.toURI().toString(); } catch (URISyntaxException ex) { throw new KettleException(ex); } } data.recordnr++; RowMetaInterface irow = getInputRowMeta(); data.previousRow = irow == null ? outputRowData : (Object[]) irow.cloneRow(outputRowData); // copy it to make // surely the next step doesn't change it in between... return outputRowData; }
From source file:ddf.catalog.source.opensearch.TestOpenSearchSource.java
private List<NameValuePair> extractQueryParams(FirstArgumentCapture answer) throws MalformedURLException, URISyntaxException { URL url = new URI(answer.getInputArg()).toURL(); ParameterParser paramParser = new ParameterParser(); List<NameValuePair> pairs = paramParser.parse(url.getQuery(), '&'); return pairs; }