All pastes #165515 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-09-09 22:54 UTC
rendered paste body
import java.io.*;
import java.util.*;
import java.util.ArrayList;
// JDOM
import org.jdom.*;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.SAXOutputter;

public class XMLhandling
{
	SAXBuilder builder = new SAXBuilder();
	
	// reference on IOclass object
	private IOclass currentIO;
	// constructur of XMLhandling
	public XMLhandling (IOclass oneIO) throws Exception
	{
		try
		{
		this.setIOCLASS(oneIO);
		}
		catch (Exception e)
		{
			System.out.println("XMLHANDLING: "+e.getMessage());
			throw e;
		}
	}
	// set Io class
	public void setIOCLASS(IOclass oneIO) throws Exception
	{
		this.currentIO=oneIO;
		try
		{
		this.getData();
		}
		catch(Exception e)
		{
			System.out.println("setIOCLASS: "+e.getMessage());
			throw e;
		}
	}

	

	private void getData() throws Exception
	{
		try
		{
			SAXBuilder builder = new SAXBuilder();
			Document XMLdoc = builder.build("targets.xml");

			// arraylists for attributes
			ArrayList<String> list_fieldname    = new ArrayList<String>();
			ArrayList<String> list_fieldvalue   = new ArrayList<String>();
			ArrayList<String> list_fielddescrip = new ArrayList<String>();

			Element targets = XMLdoc.getRootElement();
			Element form = targets.getChild("formfields");
			List forminfos = form.getChildren();
					
			Iterator formIterator = forminfos.iterator();
			while (formIterator.hasNext())
			{
				Element actelement = (Element)formIterator.next(); // next Element of formfield
				List actAttributes = actelement.getAttributes();
				
				list_fieldname.add(actelement.getAttributeValue("fieldname"));
				list_fieldvalue.add(actelement.getAttributeValue("fieldvalue"));
				list_fielddescrip.add(actelement.getAttributeValue("fielddescrip"));

			}


			public ArrayList[] getIndivFormdata(int n)
			{
				ArrayList<String> indiv_formdata = new ArrayList<String>();
				indiv_formdata.add(list_fieldname.get(n));
				indiv_formdata.add(list_fieldname.get(n));
				indiv_formdata.add(list_fieldname.get(n));
				return indiv_formdata;
			}

			System.out.println(getIndivFormdata(2));
			
			System.out.println(list_fieldname.get(2));
			System.out.println(list_fieldvalue.size());
			System.out.println(list_fielddescrip.size());

//			currentIO.setFormdata(2, list_fieldname.get(2))
/*			currentIO.setTargetnumber(targets.getAttribute("number").getValue());
			currentIO.setTargetip(targets.getChild("ip").getText());
			currentIO.setTargetpath(targets.getChild("path").getText());
			currentIO.setTargetmethod(targets.getChild("formfields").getAttribute("method").getValue());
			currentIO.setFormf_gender1(targets.getChild("formfields").getChild("gender1").getAttribute("name").getValue());
			currentIO.setFormf_gender1(targets.getChild("formfields").getChild("gender1").getAttribute("value").getValue());
			currentIO.setFormf_gender2(targets.getChild("formfields").getChild("gender2").getAttribute("name").getValue());
			currentIO.setFormf_gender2(targets.getChild("formfields").getChild("gender2").getAttribute("value").getValue());
			currentIO.setFormf_prename(targets.getChild("formfields").getChild("prename").getAttribute("name").getValue());*/
		}
		catch (JDOMException e)
		{
			System.out.println("JDOM Exception: "+e.getMessage());
			throw new Exception(e);
		}
		catch (IOException e)
		{
			System.out.println("IO Excep:"+e.getMessage());
			throw new Exception(e);
		}    
		catch (Exception e)
		{
			System.out.println((e.getClass()).toString());
		}

	}

}