package enc;

import de.tu_dresden.diplom.richter_mirko_mat2628335.Configuration;

import java.io.InputStream;
import java.io.IOException;
import java.io.File;


/**
 * Testclass to start some operations on the DOMCipher-class.
 */
public class Start {

   public static void main(String[] args){
      try {
         Configuration conf = new Configuration(Configuration.APPLICATION_BASE);
         StringBuffer command = new StringBuffer("java -classpath");
         command.append(" ").append(conf.getModuleDOMCipherHome()).append("/classes");
         command.append(";").append(conf.getLibHome()).append(File.separator).append("xss4j.jar");
         command.append(";").append(conf.getLibHome()).append(File.separator).append("xalan.jar");
         command.append(";").append(conf.getLibHome()).append(File.separator).append("xerces").append(File.separator).append("xmlParserAPIs.jar");
         command.append(";").append(conf.getLibHome()).append(File.separator).append("xerces").append(File.separator).append("xercesImpl.jar");
         command.append(" enc.DOMCipher -e \"*\"");
         command.append(" ").append(conf.getExtAppHome()).append(File.separator).append("ibm_xml_security_suite\\xss4j\\data\\enc\\keyinfo1.xml");
         command.append(" ").append(conf.getExtAppHome()).append(File.separator).append("ibm_xml_security_suite\\xss4j\\data\\enc\\bookorder.xml");
         command.append(" \"//*[name()='cardinfo']\"");
         command.append(" ").append(conf.getExtAppHome()).append(File.separator).append("ibm_xml_security_suite\\xss4j\\data\\enc\\template1.xml");
         Process proc = Runtime.getRuntime().exec(command.toString());
         System.out.println("0");
         proc.waitFor();
         System.out.println("1");
         InputStream in = proc.getInputStream();
         byte[] b = new byte[20];
         int res = 0;
         StringBuffer msg = new StringBuffer();
         System.out.println("2");
         while(res != -1){
            res = in.read(b);
            for(int i = 0; i < res; i++){
               msg.append((char)b[i]);
            }
            System.out.println("res: " + res);
            System.out.println("b: " + b);
         }
         System.out.println(msg);
      } catch (IOException e) {
         e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      } catch (InterruptedException e) {
         e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
      }
//      DOMCipher.main2(new String[]{"-e",
//                                  "*",
//                                  "E:\\home\\mirko\\diplom\\ext_app\\ibm_xml_security_suite\\xss4j\\data\\enc\\keyinfo1.xml",
//                                  "E:\\home\\mirko\\diplom\\ext_app\\ibm_xml_security_suite\\xss4j\\data\\enc\\bookorder.xml",
//                                  "//*[name()='cardinfo']",
//                                  "E:\\home\\mirko\\diplom\\ext_app\\ibm_xml_security_suite\\xss4j\\data\\enc\\template1.xml"
//      });
   }

}
