//urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", "");
@Override
    protected BufferedDataTable[] execute(final BufferedDataTable[] inData,
            final ExecutionContext exec) throws Exception {
    	DataColumnSpec[] allColSpecs = new DataColumnSpec[1];
        allColSpecs[0] = 
                new DataColumnSpecCreator("url", StringCell.TYPE).createSpec();
        DataTableSpec outputSpec = new DataTableSpec(allColSpecs);
     //   System.out.println("calling execute"+resultUrl.getStringValue());
        // the execution context will provide us with storage capacity, in this
        // case a data container to which we will add rows sequentially
        // Note, this container can also handle arbitrary big data tables, it
        // will buffer to disc if necessary.
        BufferedDataContainer container = exec.createDataContainer(outputSpec);
        DataCell[] cells = new DataCell[1];
	String urlTemplate = resultUrl.getStringValue();
	Iterator<DataRow> varIt = inData[0].iterator();
	DataTableSpec dts = inData[0].getDataTableSpec();
	String[] colNames = dts.getColumnNames();
	if(varIt.hasNext()){
	//while(varIt.hasNext()){
		DataRow current = varIt.next();
		Iterator<DataCell> cellIt = current.iterator();
		int colCount = 0;
		while(cellIt.hasNext()){
			DataCell currentCell= cellIt.next();
			String curVar =  colNames[colCount];
			String curVal = currentCell.toString();
			//System.out.println("curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
				if(urlTemplate.indexOf(curVar)==-1){
					System.out.println("1curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
					urlTemplate = urlTemplate+"&"+curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8");
					System.out.println("2curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
				}else{
					System.out.println("3curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
					String configValue = "";
					if(urlTemplate.indexOf("&"+curVar)!=-1){
						configValue = urlTemplate.substring(urlTemplate.indexOf("&"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar)));
					}else if(urlTemplate.indexOf("?"+curVar)!=-1){
						configValue = urlTemplate.substring(urlTemplate.indexOf("?"+curVar)+curVar.length()+2,urlTemplate.indexOf("]",urlTemplate.indexOf(curVar)));
					}
					System.out.println("4curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
					if(configValue.endsWith("&")){
						configValue = configValue.substring(0,configValue.length()-1); //get rid of the &
					}
					if(colCount==0){
						urlTemplate +="&";
					}
					System.out.println("5curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
					if(!configValue.equals("")){
						System.out.println("6curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
						System.out.println("config var: "+curVar+" with configValue:"+ configValue+ ", is overwritten with value: "+currentCell.toString()  );
						urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&");
						urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"));
					}else{
						//System.out.println("now we are here");
						System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
						if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){
							//urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1);
							urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8");
						}else{
							urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8");
						}
						//urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&");
						//urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"));
						//System.out.println("urlTemplate before:"+doubleStr+",  and after:"+urlTemplate);
					}
				}
			colCount++;
		}
	}
	System.out.println("yy:"+urlTemplate);
	//urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", "");
	urlTemplate =urlTemplate.replaceAll("\\[", "");
	urlTemplate =urlTemplate.replaceAll("\\]", "");
	urlTemplate =urlTemplate.replaceAll("%28", "(");
	urlTemplate =urlTemplate.replaceAll("%29", ")");
	//urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue?
	//urlTemplate =urlTemplate.replaceAll("%5D", "]");
	System.out.println("yy:"+urlTemplate);
	if(urlTemplate.endsWith("&")){
		urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1);
	}
	//urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1);
	//System.out.println("urlTemplate became "+urlTemplate);
	cells[0] = new StringCell(urlTemplate);
	  DataRow row = new DefaultRow("aboutCell", cells);
        container.addRowToTable(row);
        container.close();
        BufferedDataTable out = container.getTable();
    // TODO: Return a BufferedDataTable for each output port 
    return new BufferedDataTable[]{out};
    }
}
System.out.println("yy:"+urlTemplate);
//urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", "");
urlTemplate =urlTemplate.replaceAll("\\[", "");
urlTemplate =urlTemplate.replaceAll("\\]", "");
}
//urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&");
//urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"));
//System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate);
}
}
colCount++;
}
}
System.out.println("yy:"+urlTemplate);
//urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", "");
urlTemplate =urlTemplate.replaceAll("\\[", "");
urlTemplate =urlTemplate.replaceAll("\\]", "");
urlTemplate =urlTemplate.replaceAll("%28", "(");
urlTemplate =urlTemplate.replaceAll("%29", ")");
//urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue?
//urlTemplate =urlTemplate.replaceAll("%5D", "]");
System.out.println("yy:"+urlTemplate);
if(urlTemplate.endsWith("&")){
urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1);
}
urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&");
urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"));
}else{
//System.out.println("now we are here");
System.out.println("7curvar:"+curVar+", curval:"+curVal+", urlTemplate:"+urlTemplate);
if(urlTemplate.endsWith("&")||urlTemplate.endsWith("?")){
//urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1);
urlTemplate = urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8");
}else{
urlTemplate = "&"+urlTemplate+curVar+"="+URLEncoder.encode(curVal,"UTF-8");
}
//urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"&]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8")+"&");
//urlTemplate = urlTemplate.replaceAll(Pattern.quote("["+curVar+"="+configValue+"]"), curVar+"="+URLEncoder.encode(currentCell.toString(),"UTF-8"));
//System.out.println("urlTemplate before:"+doubleStr+", and after:"+urlTemplate);
}
}
colCount++;
}
}
System.out.println("yy:"+urlTemplate);
//urlTemplate =urlTemplate.replaceAll("\\[.*?\\]", "");
urlTemplate =urlTemplate.replaceAll("\\[", "");
urlTemplate =urlTemplate.replaceAll("\\]", "");
urlTemplate =urlTemplate.replaceAll("%28", "(");
urlTemplate =urlTemplate.replaceAll("%29", ")");
//urlTemplate =urlTemplate.replaceAll("%5B", "["); //strange that this is needed....API issue?
//urlTemplate =urlTemplate.replaceAll("%5D", "]");
System.out.println("yy:"+urlTemplate);
if(urlTemplate.endsWith("&")){
urlTemplate = urlTemplate.substring(0,urlTemplate.length()-1);
}
//urlTemplate = urlTemplate.substring(0, urlTemplate.length()-1);
//System.out.println("urlTemplate became "+urlTemplate);
cells[0] = new StringCell(urlTemplate);
DataRow row = new DefaultRow("aboutCell", cells);
container.addRowToTable(row);
container.close();
BufferedDataTable out = container.getTable();
// TODO: Return a BufferedDataTable for each output port
return new BufferedDataTable[]{out};
}