1 package net.firstpartners.nounit.ui.common; 2 3 30 31 32 import java.io.File ; 33 import java.io.FileNotFoundException ; 34 import java.io.FileOutputStream ; 35 import java.io.IOException ; 36 37 import net.firstpartners.nounit.reader.bytecode.ByteCodeProjectSnippetFactory; 38 import net.firstpartners.nounit.snippet.Snippets; 39 import net.firstpartners.nounit.utility.NoUnitException; 40 41 import org.jdom.output.XMLOutputter; 42 43 44 public class XMLProcessor implements IProcessor { 45 46 49 public XMLProcessor() { 50 super(); 51 52 } 53 54 61 public CommandPackage transform(CommandPackage inCommandPackage) 62 throws NoUnitException { 63 try { 64 65 AbstractValueChecker checkArgs = new LightWeightValueChecker(); 66 checkArgs.checkValues(inCommandPackage); 67 68 ByteCodeProjectSnippetFactory myFactory = 70 new ByteCodeProjectSnippetFactory( 71 inCommandPackage.getString(CommandPackage.START_DIR)); 72 73 Snippets projectInfo = myFactory.getSnippets(); 74 75 this.handleOutput(inCommandPackage, projectInfo); 76 77 inCommandPackage.addValue( 79 CommandPackage.USER_MESSAGE, 80 "XML File generation was Successful"); 81 82 return inCommandPackage; 83 84 } catch (java.io.IOException ioe) { 85 throw new NoUnitException(ioe, "IO Error"); 86 } catch (Exception thr) { 87 throw new NoUnitException(thr, "Throwable caught in transform."); 88 } 89 } 90 97 private void handleOutput(CommandPackage inCommandPackage, Snippets projectInfo) throws FileNotFoundException , IOException { 98 String outDir = inCommandPackage.getString(CommandPackage.OUTPUT_DIR); 100 String fileName = inCommandPackage.getString(CommandPackage.XML_OUTPUT_NAME); 101 102 File destination = null; 103 104 if(fileName != null && !fileName.equals("")){ 105 destination = new File (outDir, fileName); 106 107 }else{ 108 destination = new File (outDir, SystemValues.XML_OUTPUT_NAME); 109 } 110 111 if (destination.exists()) { 113 destination.delete(); 114 } 115 116 FileOutputStream output = new FileOutputStream (destination); 118 119 XMLOutputter fmt = new XMLOutputter(" ", true); 121 fmt.output(projectInfo.getFirstItem().getNodes(), output); 122 } 123 } 124 | Popular Tags |