001: package net.firstpartners.nounit.ui.common;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Andrew Glover
024: * @since Jul 4, 2003
025: *
026: *
027: * Class only outputs and XML file and defers xslt to outside transformers
028: *
029: */
030:
031: import java.io.File;
032: import java.io.FileNotFoundException;
033: import java.io.FileOutputStream;
034: import java.io.IOException;
035:
036: import net.firstpartners.nounit.reader.bytecode.ByteCodeProjectSnippetFactory;
037: import net.firstpartners.nounit.snippet.Snippets;
038: import net.firstpartners.nounit.utility.NoUnitException;
039:
040: import org.jdom.output.XMLOutputter;
041:
042: public class XMLProcessor implements IProcessor {
043:
044: /**
045: *
046: */
047: public XMLProcessor() {
048: super ();
049:
050: }
051:
052: /**
053: * Method only does the XML output and "Skips" any xsl/xslt, leaving
054: * that up to users.
055: *
056: * (non-Javadoc)
057: * @see net.firstpartners.nounit.ui.common.IProcessor#transform(net.firstpartners.nounit.ui.common.CommandPackage)
058: */
059: public CommandPackage transform(CommandPackage inCommandPackage)
060: throws NoUnitException {
061: try {
062:
063: AbstractValueChecker checkArgs = new LightWeightValueChecker();
064: checkArgs.checkValues(inCommandPackage);
065:
066: //Walk the Package(s) to get the XML
067: ByteCodeProjectSnippetFactory myFactory = new ByteCodeProjectSnippetFactory(
068: inCommandPackage
069: .getString(CommandPackage.START_DIR));
070:
071: Snippets projectInfo = myFactory.getSnippets();
072:
073: this .handleOutput(inCommandPackage, projectInfo);
074:
075: //Set the output message
076: inCommandPackage.addValue(CommandPackage.USER_MESSAGE,
077: "XML File generation was Successful");
078:
079: return inCommandPackage;
080:
081: } catch (java.io.IOException ioe) {
082: throw new NoUnitException(ioe, "IO Error");
083: } catch (Exception thr) {
084: throw new NoUnitException(thr,
085: "Throwable caught in transform.");
086: }
087: }
088:
089: /**
090: *
091: * @param inCommandPackage
092: * @param projectInfo
093: * @throws FileNotFoundException
094: * @throws IOException
095: */
096: private void handleOutput(CommandPackage inCommandPackage,
097: Snippets projectInfo) throws FileNotFoundException,
098: IOException {
099: // Combine File and Directory
100: String outDir = inCommandPackage
101: .getString(CommandPackage.OUTPUT_DIR);
102: String fileName = inCommandPackage
103: .getString(CommandPackage.XML_OUTPUT_NAME);
104:
105: File destination = null;
106:
107: if (fileName != null && !fileName.equals("")) {
108: destination = new File(outDir, fileName);
109:
110: } else {
111: destination = new File(outDir, SystemValues.XML_OUTPUT_NAME);
112: }
113:
114: //Delete file if it's already there
115: if (destination.exists()) {
116: destination.delete();
117: }
118:
119: //Get Handle to file
120: FileOutputStream output = new FileOutputStream(destination);
121:
122: //Output Xml to this stream
123: XMLOutputter fmt = new XMLOutputter(" ", true);
124: fmt.output(projectInfo.getFirstItem().getNodes(), output);
125: }
126: }
|