// Path: src/java/com/idega/block/form/business/XFormPersistenceService.java
// public interface XFormPersistenceService {
// 
// 	public Map<String, String> getVariables(Long identifier);
// 
// }


import java.io.InputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.parsers.DocumentBuilder;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import com.idega.block.form.business.XFormPersistenceService;
import com.idega.business.IBOLookup;
import com.idega.business.IBOLookupException;
import com.idega.idegaweb.IWMainApplication;
import com.idega.slide.business.IWSlideService;
import com.idega.util.CoreConstants;
import com.idega.util.CoreUtil;
import com.idega.util.IOUtil;
import com.idega.util.ListUtil;
import com.idega.util.StringHandler;
import com.idega.util.StringUtil;
import com.idega.util.datastructures.map.MapUtil;
import com.idega.util.xml.XmlUtil;
import com.idega.xformsmanager.business.Submission;
		List<Node> nodes = XmlUtil.getChildNodes(submissionDocument.getDocumentElement(), null, null, "mapping", null);
		if (ListUtil.isEmpty(nodes)) {
			return variables;
		}

		for (Iterator<Node> i = nodes.iterator(); i.hasNext();) {
			Node node = i.next();

			org.w3c.dom.Element element = null;
			if (node instanceof org.w3c.dom.Element) {
				element = (org.w3c.dom.Element) node;
			} else {
				continue;
			}

			String name = element.getAttribute("mapping");
			String value = node.getTextContent();
			if (!StringUtil.isEmpty(name) && !StringUtil.isEmpty(value)) {
				variables.put(name.trim(), value.trim());
			}
		}

		return variables;
	}

	@Transient
	private Map<String, String> getVariablesFromDatabase() throws Exception {
		IWMainApplication iwma = IWMainApplication.getDefaultIWMainApplication();
		@SuppressWarnings("unchecked")
		Map<String, Object> beans = WebApplicationContextUtils.getWebApplicationContext(iwma.getServletContext())
// Path: src/java/com/idega/block/form/business/XFormPersistenceService.java
// public interface XFormPersistenceService {
// 
// 	public Map<String, String> getVariables(Long identifier);
// 
// }


// Path: src/java/com/idega/block/form/data/XFormSubmission.java
import java.io.InputStream;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.parsers.DocumentBuilder;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import com.idega.block.form.business.XFormPersistenceService;
import com.idega.business.IBOLookup;
import com.idega.business.IBOLookupException;
import com.idega.idegaweb.IWMainApplication;
import com.idega.slide.business.IWSlideService;
import com.idega.util.CoreConstants;
import com.idega.util.CoreUtil;
import com.idega.util.IOUtil;
import com.idega.util.ListUtil;
import com.idega.util.StringHandler;
import com.idega.util.StringUtil;
import com.idega.util.datastructures.map.MapUtil;
import com.idega.util.xml.XmlUtil;
import com.idega.xformsmanager.business.Submission;

		List<Node> nodes = XmlUtil.getChildNodes(submissionDocument.getDocumentElement(), null, null, "mapping", null);
		if (ListUtil.isEmpty(nodes)) {
			return variables;
		}

		for (Iterator<Node> i = nodes.iterator(); i.hasNext();) {
			Node node = i.next();

			org.w3c.dom.Element element = null;
			if (node instanceof org.w3c.dom.Element) {
				element = (org.w3c.dom.Element) node;
			} else {
				continue;
			}

			String name = element.getAttribute("mapping");
			String value = node.getTextContent();
			if (!StringUtil.isEmpty(name) && !StringUtil.isEmpty(value)) {
				variables.put(name.trim(), value.trim());
			}
		}

		return variables;
	}

	@Transient
	private Map<String, String> getVariablesFromDatabase() throws Exception {
		IWMainApplication iwma = IWMainApplication.getDefaultIWMainApplication();
		@SuppressWarnings("unchecked")
		Map<String, Object> beans = WebApplicationContextUtils.getWebApplicationContext(iwma.getServletContext())
				.getBeansOfType(XFormPersistenceService.class);