How to manage exceptions and work with transformer in Java

powerpaul

New Member
I have the following Java Program:\[code\]import javax.xml.transform.*;import javax.xml.transform.stream.*;import org.xml.sax.*;import java.io.IOException;public class TestJavaXslt{ public static void main(String[] args) throws TransformerException, TransformerConfigurationException, SAXException, IOException { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource("Mint.xsl")); Transformer transformer1 = tFactory.newTransformer(new StreamSource("TemplatesTest.xsl")); transformer.transform(new StreamSource("mint001.xml"), new StreamResult("Test.xml")); transformer1.transform(new StreamSource("Test.xml"), new StreamResult("Result.xml")); } }\[/code\]The idea is as follows:
  • I use xslt to transform xml file and I make two transformation with the file Mint.xsl apply on the file mint001.xml and the file TemplatesTest.xsl.
  • The result of the first transformation is stored in the file Test.xml and then reused with the second xsl file named TemplatesTest.xsl to produce the last result of my transformation stored in the file Result.xml.
  • I put all these file in the same folder and I want now to modify my code, so that if you save the both xsl file and the file mint001.xml under another name as mine, the program will function well without error.
  • What I did is adapted especially to my example and i want to make it run general in any file with the extension .xsl and .xml.
I got also problem to manage all the exception, because I dont know for the moment how to do it. I wanted for example, that if someone want to run my program just with one XSL file in the folder, an exception will be throw by the program informing the user that he need two xsl file to run the program or he need at least one xml file in the folder to start the program.And finaly, I want to make the program as an embeded program in a jar file.Could some one help me?
 
Back
Top