CheckoutBank.java 2.6 KB
/*
 * Copyright Codecrew Ry
 * 
 * All rights reserved.
 * 
 * This license applies to any software containing a notice placed by the 
 * copyright holder. Such software is herein referred to as the Software. 
 * This license covers modification, distribution and use of the Software. 
 * 
 * Any distribution and use in source and binary forms, with or without 
 * modification is not permitted without explicit written permission from the 
 * copyright owner. 
 * 
 * A non-exclusive royalty-free right is granted to the copyright owner of the 
 * Software to use, modify and distribute all modifications to the Software in 
 * future versions of the Software. 
 * 
 */
package fi.codecrew.moya.util;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class CheckoutBank {

	private final String key;
	private final String url;
	private final String icon;
	private final String name;
	private final List<Valuepair> postParams = new ArrayList<Valuepair>();
	private static final Logger logger = LoggerFactory.getLogger(CheckoutBank.class);

	public CheckoutBank(Node bank) {
		if (bank.getNodeType() != 1)
		{
			throw new RuntimeException("Wrong type of node " + bank + " type " + bank.getNodeType());
		}
		key = bank.getNodeName();
		logger.info("Bank type {}", bank);
		NamedNodeMap attrs = bank.getAttributes();
		String iconval = null;
		String nameval = null;
		String urlval = null;
		for (int j = 0; j < attrs.getLength(); ++j)
		{
			Node attr = attrs.item(j);
			if (attr.getNodeName().equals("icon")) {
				iconval = attr.getNodeValue();
			} else if (attr.getNodeName().equals("name")) {
				nameval = attr.getNodeValue();
			} else if (attr.getNodeName().equals("url")) {
				urlval = attr.getNodeValue();
			}
		}
		icon = iconval;
		name = nameval;
		url = urlval;

		NodeList children = bank.getChildNodes();
		for (int i = 0; i < children.getLength(); ++i)
		{
			Node childnode = children.item(i);
			if (childnode.getNodeType() == 1)
			{
				String paramName = childnode.getNodeName();
				String paramValue = childnode.getTextContent();
				getPostParams().add(new Valuepair(paramName, paramValue));
				logger.info("Added param for {} name {} value {}", new Object[] { key, paramName, paramValue });
			}
		}
//		System.out.println();

	}

	public String getKey() {
		return key;
	}

	public String getUrl() {
		return url;
	}

	public String getIcon() {
		return icon;
	}

	public String getName() {
		return name;
	}

	public List<Valuepair> getPostParams() {
		return postParams;
	}

}