2

I have created a program to convert text to xml by using ReverseXSL API.

 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;

 import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerFactoryConfigurationError;

 import com.reverseXSL.parser.ParserException;
 import com.reverseXSL.transform.Transformer;
 import com.reverseXSL.transform.TransformerException;
 import com.reverseXSL.transform.TransformerFactory;

 public class MyTest4 {


     public MyTest4() {

     }

     public static int transformXSL(String defFile, String inputFile, String XSLFile, String OutputFile) {

         try {
             System.out.println("Dheeraj's method is called");

             // start time

             FileWriter fw = null;
             try {
                 fw = new FileWriter("D://Countime.txt");
             } catch (IOException e1) {
                 // TODO Auto-generated catch block
                 e1.printStackTrace();
             }
             BufferedWriter output = new BufferedWriter(fw);
             DateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
             Date dt = new Date();
             System.out.println("Date is calculated");

             try {
                 output.write("Start Time:" + sd.format(dt).toString());
             } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }


             System.out.println(sd.format(dt));

             FileReader myDEFReader = null, myXSLReader = null;
             TransformerFactory tf = TransformerFactory.newInstance();
             Transformer t = null;
             FileInputStream inStream = null;
             ByteArrayOutputStream outStream = null;

             // Step 1:

             //instantiate a transformer with the specified DEF and XSLT

             if (new File(defFile).canRead()) {
                 try {
                     myDEFReader = new FileReader(defFile);
                     System.out.println("Definition file is read");
                 } catch (FileNotFoundException e) {

                     e.printStackTrace();
                 }

             } else myDEFReader = null;

             if (new File(XSLFile).canRead())
                 try {
                     myXSLReader = new FileReader(XSLFile);
                     System.out.println("XSL file is read");
                 } catch (FileNotFoundException e) {

                     e.printStackTrace();
                 } else myXSLReader = null;

             try {

                 t = tf.newTransformer(myDEFReader, myXSLReader);
             } catch (IOException e) {

                 e.printStackTrace();
             }

             System.out.println("Step 1: DEF AND XSLT Transformation completed");

             // Step 2:
             // Read Input data

             try {
                 inStream = new FileInputStream(inputFile);
             } catch (FileNotFoundException e) {
                 e.printStackTrace();
             }

             outStream = new ByteArrayOutputStream();

             System.out.println("Step 2: Reading Input file:  completed");

             // Step 3:

             // Transform Input

             try {
                 try (BufferedReader br = new BufferedReader(new FileReader("D://2.txt"))) {
                     String line = null;
                     while ((line = br.readLine()) != null) {
                         System.out.println("Content: " + line);
                     }
                 }

                 System.out.println("File: " + inputFile.toString());
                 System.out.println("\n content: \n" + inStream.toString());
                 System.out.println("Calling Transform Function");
                 t.transform(inStream, outStream);
                 System.out.println("Transformation is called");
                 outStream.close();
                 try (OutputStream outputStream = new FileOutputStream(OutputFile)) {
                     outStream.writeTo(outputStream);

                     System.out.println("Outstream is generated; Output file is creating");
                 }
                 System.out.println(outStream.toString());
             } catch (TransformerException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             } catch (ParserException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             } catch (ParserConfigurationException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             } catch (FactoryConfigurationError e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             } catch (TransformerFactoryConfigurationError e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             } catch (javax.xml.transform.TransformerException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }


             System.out.println("output file is created");
             // End time

             Date dt2 = new Date();
             System.out.println(sd.format(dt2));

             System.out.println("End time:" + dt2.toString());
             try {
                 output.append("End Time:" + sd.format(dt2).toString());
                 output.close();
             } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }
         } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
         return 0;
     }

This program is to be executed by an application by calling static method (static int transformXSL).

I am able to execute and produce output with running from Eclipse. However, When I ran program (jar) by using application it stuck somewhere and I couldnt find anything.

Then, I debugged by "Debug as...-> Remote Java Application" in Eclipse from Application and found "InvocationTargetException" at ClassLoaders.callStaticFunction.

InvocationTargetException It doesn't have any stack trace, I cant find where this error coming from and what it is all about.

Dheeraj Kumar
  • 3,917
  • 8
  • 43
  • 80
  • Please do not repost the same questions, edit the original to clarify it instead. – Tunaki Aug 09 '16 at 08:26
  • Heading of question was misspelled which cant be edited. – Dheeraj Kumar Aug 09 '16 at 08:35
  • It can be edited, just like the rest of the post. You can click [edit](http://stackoverflow.com/posts/38765240/edit) and change the title and the body. Refer to the [help]. – Tunaki Aug 09 '16 at 08:37
  • I will delete previous one. Can you remove duplicate tag? – Dheeraj Kumar Aug 09 '16 at 08:39
  • People started to help you on that question. It's unfair to outright delete it. If you want to delete one, delete this one, but be sure to edit the original question with all the info. – Tunaki Aug 09 '16 at 08:41

0 Answers0