// Path: src/main/java/com/syndicapp/scraper/FSSUserAgent.java
// public class FSSUserAgent {
//     public static HttpClient httpclient = HttpClientBuilder.create().build();
//     public static Logger log = Logger.getLogger(FSSUserAgent.class);
//     public static BasicHttpContext context = new BasicHttpContext();
// 
//     public FSSUserAgent() {
//     }
// 
// 
// }
// 
// Path: src/main/java/com/syndicapp/scraper/exception/UnexpectedPageContentsException.java
// public class UnexpectedPageContentsException extends Exception
// {
// 
//     public UnexpectedPageContentsException(String s)
//     {
//         super(s);
//     }
// 
//     private static final long serialVersionUID = 0xf57ed4fa93f8378aL;
// }


import com.syndicapp.scraper.FSSUserAgent;
import com.syndicapp.scraper.exception.UnexpectedPageContentsException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;

    {
    }

    public static HashMap click(String page, HashMap inputParams)
        throws Exception
    {
        HashMap outputParams = new HashMap();
        String transactionToken = null;
        Pattern p = Pattern.compile("transactionToken\" value=\"(\\d+)\"/>\\s*<input type=\"hidden\" name=\"iBankFormSubmission\" value=\"true\" />\\s*<div>\\s*<input type=\"image\" class=\"aibRowRight\" name=\"_target6");
        for(Matcher m = p.matcher(page); m.find();)
            transactionToken = m.group(1);

        HttpPost httppost = new HttpPost("https://aibinternetbanking.aib.ie/inet/roi/fundstransferroi.htm");
        List nvps = new ArrayList();
        p = Pattern.compile("<input type=\"hidden\" name=\"accountRefList\" value=\"\"/>");
        for(Matcher m = p.matcher(page); m.find(); nvps.add(new BasicNameValuePair("accountRefList", "")));
        nvps.add(new BasicNameValuePair("transactionToken", transactionToken));
        nvps.add(new BasicNameValuePair("iBankFormSubmission", "true"));
        nvps.add(new BasicNameValuePair("receiverAccountIndex", (String)inputParams.get("toAccountId")));
        nvps.add(new BasicNameValuePair("receiverReference", (String)inputParams.get("receiverReference")));
        nvps.add(new BasicNameValuePair("paymentAmount.euro", (String)inputParams.get("amounteuro")));
        nvps.add(new BasicNameValuePair("paymentAmount.cent", (String)inputParams.get("amountcent")));
        nvps.add(new BasicNameValuePair("_target6.x", "21"));
        nvps.add(new BasicNameValuePair("_target6.y", "15"));
        log.debug((new StringBuilder()).append("Clicking 'Transfer to Another ROI Account Step 3' with ").append(nvps.toString()).toString());
        httppost.setEntity(new UrlEncodedFormEntity(nvps, "ISO-8859-1"));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        page = EntityUtils.toString(entity);
        if(!page.contains("You have requested to make the following transfer:"))

// Path: src/main/java/com/syndicapp/scraper/FSSUserAgent.java
// public class FSSUserAgent {
//     public static HttpClient httpclient = HttpClientBuilder.create().build();
//     public static Logger log = Logger.getLogger(FSSUserAgent.class);
//     public static BasicHttpContext context = new BasicHttpContext();
// 
//     public FSSUserAgent() {
//     }
// 
// 
// }
// 
// Path: src/main/java/com/syndicapp/scraper/exception/UnexpectedPageContentsException.java
// public class UnexpectedPageContentsException extends Exception
// {
// 
//     public UnexpectedPageContentsException(String s)
//     {
//         super(s);
//     }
// 
//     private static final long serialVersionUID = 0xf57ed4fa93f8378aL;
// }


// Path: src/main/java/com/syndicapp/scraper/aib/TransferToAnotherROIAccountStep3.java
import com.syndicapp.scraper.FSSUserAgent;
import com.syndicapp.scraper.exception.UnexpectedPageContentsException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;

    {
    }

    public static HashMap click(String page, HashMap inputParams)
        throws Exception
    {
        HashMap outputParams = new HashMap();
        String transactionToken = null;
        Pattern p = Pattern.compile("transactionToken\" value=\"(\\d+)\"/>\\s*<input type=\"hidden\" name=\"iBankFormSubmission\" value=\"true\" />\\s*<div>\\s*<input type=\"image\" class=\"aibRowRight\" name=\"_target6");
        for(Matcher m = p.matcher(page); m.find();)
            transactionToken = m.group(1);

        HttpPost httppost = new HttpPost("https://aibinternetbanking.aib.ie/inet/roi/fundstransferroi.htm");
        List nvps = new ArrayList();
        p = Pattern.compile("<input type=\"hidden\" name=\"accountRefList\" value=\"\"/>");
        for(Matcher m = p.matcher(page); m.find(); nvps.add(new BasicNameValuePair("accountRefList", "")));
        nvps.add(new BasicNameValuePair("transactionToken", transactionToken));
        nvps.add(new BasicNameValuePair("iBankFormSubmission", "true"));
        nvps.add(new BasicNameValuePair("receiverAccountIndex", (String)inputParams.get("toAccountId")));
        nvps.add(new BasicNameValuePair("receiverReference", (String)inputParams.get("receiverReference")));
        nvps.add(new BasicNameValuePair("paymentAmount.euro", (String)inputParams.get("amounteuro")));
        nvps.add(new BasicNameValuePair("paymentAmount.cent", (String)inputParams.get("amountcent")));
        nvps.add(new BasicNameValuePair("_target6.x", "21"));
        nvps.add(new BasicNameValuePair("_target6.y", "15"));
        log.debug((new StringBuilder()).append("Clicking 'Transfer to Another ROI Account Step 3' with ").append(nvps.toString()).toString());
        httppost.setEntity(new UrlEncodedFormEntity(nvps, "ISO-8859-1"));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        page = EntityUtils.toString(entity);
        if(!page.contains("You have requested to make the following transfer:"))

            throw new UnexpectedPageContentsException("Didn't get to the Transfer to Another ROI Account Step 3 Page!");
