KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > ui > common > XMLProcessor


1 package net.firstpartners.nounit.ui.common;
2
3 /**
4  * Title: NoUnit - Identify Classes that are not being unit Tested
5  *
6  * Copyright (C) 2001 Paul Browne , FirstPartners.net
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @author Andrew Glover
24  * @since Jul 4, 2003
25  *
26  *
27  * Class only outputs and XML file and defers xslt to outside transformers
28  *
29  */

30
31
32 import java.io.File JavaDoc;
33 import java.io.FileNotFoundException JavaDoc;
34 import java.io.FileOutputStream JavaDoc;
35 import java.io.IOException JavaDoc;
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     /**
47      *
48      */

49     public XMLProcessor() {
50         super();
51
52     }
53
54     /**
55      * Method only does the XML output and "Skips" any xsl/xslt, leaving
56      * that up to users.
57      *
58      * (non-Javadoc)
59      * @see net.firstpartners.nounit.ui.common.IProcessor#transform(net.firstpartners.nounit.ui.common.CommandPackage)
60      */

61     public CommandPackage transform(CommandPackage inCommandPackage)
62         throws NoUnitException {
63         try {
64
65             AbstractValueChecker checkArgs = new LightWeightValueChecker();
66             checkArgs.checkValues(inCommandPackage);
67
68             //Walk the Package(s) to get the XML
69
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             //Set the output message
78
inCommandPackage.addValue(
79                 CommandPackage.USER_MESSAGE,
80                 "XML File generation was Successful");
81
82             return inCommandPackage;
83
84         } catch (java.io.IOException JavaDoc ioe) {
85             throw new NoUnitException(ioe, "IO Error");
86         } catch (Exception JavaDoc thr) {
87             throw new NoUnitException(thr, "Throwable caught in transform.");
88         }
89     }
90     /**
91      *
92      * @param inCommandPackage
93      * @param projectInfo
94      * @throws FileNotFoundException
95      * @throws IOException
96      */

97     private void handleOutput(CommandPackage inCommandPackage, Snippets projectInfo) throws FileNotFoundException JavaDoc, IOException JavaDoc {
98         // Combine File and Directory
99
String JavaDoc outDir = inCommandPackage.getString(CommandPackage.OUTPUT_DIR);
100         String JavaDoc fileName = inCommandPackage.getString(CommandPackage.XML_OUTPUT_NAME);
101         
102         File JavaDoc destination = null;
103         
104         if(fileName != null && !fileName.equals("")){
105             destination = new File JavaDoc(outDir, fileName);
106             
107         }else{
108             destination = new File JavaDoc(outDir, SystemValues.XML_OUTPUT_NAME);
109         }
110
111         //Delete file if it's already there
112
if (destination.exists()) {
113             destination.delete();
114         }
115
116         //Get Handle to file
117
FileOutputStream JavaDoc output = new FileOutputStream JavaDoc(destination);
118
119         //Output Xml to this stream
120
XMLOutputter fmt = new XMLOutputter(" ", true);
121         fmt.output(projectInfo.getFirstItem().getNodes(), output);
122     }
123 }
124
Popular Tags