Source code for /engineering/autohit-2003/src/autohit/common/test/TestLogFormatting.javaOriginal file TestLogFormatting.java
   1 /**
   2  * AUTOHIT 2003
   3  * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
   4  * 
   5  * This program is free software; you can redistribute it and/or modify 
   6  * it under the terms of the GNU General Public License as published by 
   7  * the Free Software Foundation; either version 2 of the License, or (at
   8  * your option) any later version.
   9  * This program is distributed in the hope that it will be useful, but
  10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12  * more details.
  13  * 
  14  * You should have received a copy of the GNU General Public License along
  15  * with this program; if not, write to the Free Software Foundation, Inc.,
  16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17  *
  18  * Additional license information can be found in the documentation.
  19  * @author Erich P Gatejen
  20  */
  21 package autohit.common.test;
  22 
  23 import autohit.common.AutohitLogDrainDefault;
  24 import autohit.common.channels.Atom;
  25 import autohit.common.Utils;
  26 
  27 import java.io.File;
  28 
  29 /**
  30  * A simple CLI 
  31  *
  32  * @author Erich P. Gatejen
  33  * @version 1.0
  34  * <i>Version History</i>
  35  * <code>EPG - Initial - 25Apr03 
  36  * 
  37  */
  38 public class TestLogFormatting {
  39 
  40 	/**
  41 	 * Globals
  42 	 */
  43 
  44 	/**
  45 	 *  Help
  46 	 */
  47 	public void help() {
  48 		System.out.println("LOG TESTER");
  49 		System.out.println("t inputfile = pretty print with timestamp");
  50 		System.out.println("n inputfile = pretty print without timestamp");
  51 		System.out.println("?           = show this help");
  52 	}
  53 	
  54 	/**
  55 	 *  Object main
  56 	 */
  57 	public void ppWithT(String it) throws Exception {
  58 
  59 		File f = new File (it);
  60 		String thang = Utils.loadFile2String(f);
  61 		
  62 		System.out.println("THANG ------------------- ");
  63 		System.out.println(thang);
  64 		System.out.println("------------------------- ");
  65 		
  66 		Atom a = new Atom(1,1,1,thang);
  67 		a.senderID = "id";
  68 		AutohitLogDrainDefault d = new AutohitLogDrainDefault();
  69 		d.setPrettyFlag(true);
  70 		d.setTimestampFlag(true);
  71 		d.post(a);
  72 	}
  73 
  74 	/**
  75 	 *  Object main
  76 	 */
  77 	public void ppWithNT(String it) throws Exception {
  78 
  79 		File f = new File (it);
  80 		String thang = Utils.loadFile2String(f);
  81 		
  82 		System.out.println("THANG ------------------- ");
  83 		System.out.println(thang);
  84 		System.out.println("------------------------- ");
  85 		
  86 		Atom a = new Atom(1,1,1,thang);
  87 		a.senderID = "id";
  88 		AutohitLogDrainDefault d = new AutohitLogDrainDefault();
  89 		d.setPrettyFlag(true);
  90 		d.setTimestampFlag(false);
  91 		d.post(a);
  92 	}
  93 
  94 	/**
  95 	 * main interface
  96 	 */
  97 	public static void main(String[] args) {
  98 
  99 		// handle arguments
 100 		if (args.length < 1) {
 101 			System.out.println("No command");
 102 			return;
 103 		}
 104 		
 105 		try {
 106 			TestLogFormatting me = new TestLogFormatting();
 107 			char cmd = args[0].charAt(0); 
 108 			switch (cmd) {
 109 	
 110 				case 't' :
 111 				case 'T' : if (args.length < 2) {
 112 								System.out.println("BAD.  No input file given.");
 113 								System.out.println("params= " + args[0]);
 114 							} else {
 115 								me.ppWithT(args[1]); 
 116 							}
 117 							break;
 118 				case 'n' :
 119 				case 'N' : if (args.length < 2) {
 120 								System.out.println("BAD.  No input file given.");
 121 								System.out.println("params= " + args[0]);
 122 							} else {
 123 								me.ppWithNT(args[1]); 
 124 							}
 125 							break;						
 126 				case '?' : 
 127 				default  : me.help(); break;		
 128 			}
 129 
 130 		} catch (Exception e) {
 131 			e.printStackTrace();
 132 		}
 133 	}
 134 
 135 }