package org.maskat.demo.databinding.rd_bt1.vo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;

import javax.servlet.http.HttpServletRequest;


import org.maskat.demo.AbstractValueObj;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.sun.org.apache.xerces.internal.parsers.DOMParser;

public class ValueObj extends AbstractValueObj {

  public String check;

  public ValueObj(HttpServletRequest req) {
    super(req);

    try {
      BufferedReader reader = new BufferedReader(req.getReader());
      String line = null;
      String xml = "";
      while ((line = reader.readLine()) != null) {
        xml += line;
      }
      System.out.println(xml);
      DOMParser parser = new DOMParser();
      parser.parse(new InputSource(new StringReader(xml)));

      NodeList paramNodeList = parser.getDocument().getChildNodes().item(0).getChildNodes();
      for (int i = 0; i < paramNodeList.getLength(); i++) {
        Node node = paramNodeList.item(i);
        if ("check".equals(node.getNodeName())) {
          try {
            check = node.getChildNodes().item(0).getNodeValue();
          } catch (Exception e) {
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
      return;
    } catch (SAXException e) {
      e.printStackTrace();
    }

  }

  public String tempGetXML() {
      System.out.println(check);
    String newCheck = "";
    if ("rd_rd1".equals(check)){ newCheck = "rd_rd6"; }
    else if ("rd_rd2".equals(check)){ newCheck = "rd_rd7"; }
    else if ("rd_rd3".equals(check)){ newCheck = "rd_rd8"; }
    else if ("rd_rd4".equals(check)){ newCheck = "rd_rd5"; }
  
    return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><maskat><check>" + newCheck + "</check></maskat>";
  }

}
