1 18 19 package org.apache.beehive.netui.tools.testrecorder.shared.config; 20 21 import org.apache.beehive.netui.tools.testrecorder.shared.util.StringHelper; 22 import org.apache.beehive.netui.tools.testrecorder.shared.Logger; 23 24 import java.io.File ; 25 26 31 public class WebappConfig { 32 33 private static final Logger log = Logger.getInstance( WebappConfig.class ); 34 35 private String name; 36 private String description; 37 private boolean testMode; 38 private ServerConfig server; 39 private String contextRoot; 41 private File testDirectory; 42 private File resultsDirectory; 43 private Config config; 44 45 public WebappConfig( String name, String description, ServerConfig server, boolean testMode, 46 String contextRoot, String testDirectory, Config config ) { 47 this.name = name; 48 this.description = description; 49 this.testMode = testMode; 50 this.server = server; 51 this.contextRoot = contextRoot; 52 this.testDirectory = new File ( testDirectory ); 53 this.resultsDirectory = new File ( config.getBaseDirectory(), name + "-playback" ); 54 this.config = config; 55 } 56 57 public String getName() { 58 return name; 59 } 60 61 public String getDescription() { 62 return description; 63 } 64 65 public ServerConfig getServer() { 66 return server; 67 } 68 69 public boolean isTestMode() { 70 return testMode; 71 } 72 73 public String getContextRoot() { 74 return contextRoot; 75 } 76 77 public String getServletURI() { 78 return getContextRoot() + "/" + getConfig().getServletURI(); 79 } 80 81 public String getTestDirectory() { 82 return testDirectory.getAbsolutePath(); 83 } 84 85 88 public boolean createTestDirectory() { 89 if ( testDirectory.exists() ) { 90 return true; 91 } 92 return testDirectory.mkdirs(); 93 } 94 95 public String getResultsDirectory() { 96 return resultsDirectory.getAbsolutePath(); 97 } 98 99 104 public boolean deleteResults() { 105 return deleteResults( false ); 106 } 107 108 114 public boolean deleteResults( boolean removeDir ) { 115 boolean rtnVal = true; 116 if ( resultsDirectory.exists() ) { 117 File [] files = resultsDirectory.listFiles(); 118 File file = null; 119 for ( int i = 0; i < files.length; i++ ) { 120 file = files[i]; 121 if ( !file.delete() ) { 122 if ( log.isWarnEnabled() ) { 123 log.warn( "unable to delete results file( " + file.getAbsolutePath() + " )" ); 124 } 125 rtnVal = false; 126 } 127 } 128 if ( rtnVal && removeDir ) { 129 if ( !resultsDirectory.delete() ) { 130 if ( log.isWarnEnabled() ) { 131 log.warn( "unable to delete( " + resultsDirectory.getAbsolutePath() + " )" ); 132 } 133 rtnVal = false; 134 } 135 } 136 } 137 return rtnVal; 138 } 139 140 144 public boolean createResultsDirectory() { 145 boolean rtnVal = false; 146 resultsDirectory.mkdirs(); 147 if ( resultsDirectory.exists() ) { 148 rtnVal = true; 149 } 150 return rtnVal; 151 } 152 153 public boolean handleSuffix( String suffix ) { 154 return getConfig().handleSuffix( suffix ); 155 } 156 157 public Config getConfig() { 158 return config; 159 } 160 161 public String toString() { 162 StringBuffer sb = new StringBuffer ( 256 ); 163 sb.append( "[ " ); 164 sb.append( "name( " + getName() + " )" ); 165 sb.append( ", description( " + getDescription() + " )" ); 166 sb.append( ", testMode( " + isTestMode() + " )" ); 167 sb.append( ", server( " + getServer() + " )" ); 168 sb.append( ", contextRoot( " + getContextRoot() + " )" ); 169 sb.append( ", servletURI( " + getServletURI() + " )" ); 170 sb.append( ", testDir( " + getTestDirectory() + " )" ); 171 sb.append( ", resultsDir( " + getResultsDirectory() + " )" ); 172 sb.append( ", suffixList( " + StringHelper.toString( getConfig().getSuffixes().iterator(), "\n", "\n\t" ) + " )" ); 173 sb.append( " ]" ); 174 return sb.toString(); 175 } 176 177 } 178 | Popular Tags |