1 29 package net.sourceforge.groboutils.pmti.v1.autodoc.v1.server; 30 31 import java.io.File ; 32 import java.io.IOException ; 33 import java.io.Writer ; 34 import java.io.FileWriter ; 35 36 import net.sourceforge.groboutils.autodoc.v1.testserver.AbstractWriterServer; 37 import net.sourceforge.groboutils.autodoc.v1.testserver.TestData; 38 import net.sourceforge.groboutils.autodoc.v1.testserver.TestInfo; 39 40 import org.apache.log4j.Logger; 41 42 43 52 public abstract class AbstractNewFileServer extends AbstractWriterServer 53 { 54 private static Logger LOG = Logger.getLogger( AbstractNewFileServer.class ); 55 56 private String prefix; 57 private String postfix; 58 private boolean useTimestamp = true; 59 60 67 public AbstractNewFileServer( String prefix, String postfix ) 68 { 69 this( prefix, postfix, true ); 70 } 71 72 79 public AbstractNewFileServer( String prefix, String postfix, 80 boolean useTimestamp ) 81 { 82 if (prefix == null || postfix == null) 83 { 84 throw new IllegalArgumentException ("no null arguments"); 85 } 86 this.prefix = prefix; 87 this.postfix = postfix; 88 this.useTimestamp = useTimestamp; 89 } 90 91 92 96 protected Writer openOutput( TestData td ) 97 throws IOException 98 { 99 File f = new File ( createFileName( td ) ); 100 LOG.debug("Opening file "+f.getAbsolutePath()+" for output."); 101 FileWriter fw = new FileWriter ( f ); 102 return fw; 103 } 104 105 106 109 protected String createFileName( TestData td ) 110 { 111 TestInfo ti = td.getTestInfo(); 112 String suite = "suite"; 113 String method = "method"; 114 if (ti != null) 115 { 116 if (ti.getSuite() != null) 117 { 118 suite = ti.getSuite(); 119 } 120 if (ti.getMethod() != null) 121 { 122 method = ti.getMethod(); 123 } 124 } 125 StringBuffer sb = new StringBuffer ( this.prefix ); 126 sb.append( suite ). 127 append( '-' ). 128 append( method ); 129 if (this.useTimestamp) 130 { 131 sb.append( '-' ). 132 append( System.currentTimeMillis() ); 133 } 134 sb.append( this.postfix ); 135 String name = sb.toString(); 136 return name; 137 } 138 } 139 140 | Popular Tags |