2008-06-16 12:31:14 +00:00
package net.i2p.router.web ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Properties ;
import java.util.Set ;
import java.util.TreeSet ;
2008-07-16 13:42:54 +00:00
2008-06-16 12:31:14 +00:00
import net.i2p.router.startup.ClientAppConfig ;
2009-01-29 02:16:18 +00:00
public class ConfigClientsHelper extends HelperBase {
2008-06-16 12:31:14 +00:00
public ConfigClientsHelper ( ) { }
public String getForm1 ( ) {
2009-07-01 16:00:43 +00:00
StringBuilder buf = new StringBuilder ( 1024 ) ;
2009-07-30 23:10:48 +00:00
buf . append ( " <table> \ n " ) ;
2009-10-26 02:21:15 +00:00
buf . append ( " <tr><th align= \" right \" > " + _ ( " Client " ) + " </th><th> " + _ ( " Run at Startup? " ) + " </th><th> " + _ ( " Start Now " ) + " </th><th align= \" left \" > " + _ ( " Class and arguments " ) + " </th></tr> \ n " ) ;
2008-06-16 12:31:14 +00:00
List clients = ClientAppConfig . getClientApps ( _context ) ;
for ( int cur = 0 ; cur < clients . size ( ) ; cur + + ) {
ClientAppConfig ca = ( ClientAppConfig ) clients . get ( cur ) ;
2008-10-19 21:45:04 +00:00
renderForm ( buf , " " + cur , ca . clientName , false , ! ca . disabled , " webConsole " . equals ( ca . clientName ) ,
ca . className + ( ( ca . args ! = null ) ? " " + ca . args : " " ) ) ;
2008-06-16 12:31:14 +00:00
}
buf . append ( " </table> \ n " ) ;
return buf . toString ( ) ;
}
public String getForm2 ( ) {
2009-07-01 16:00:43 +00:00
StringBuilder buf = new StringBuilder ( 1024 ) ;
2009-07-30 23:10:48 +00:00
buf . append ( " <table> \ n " ) ;
2009-10-26 02:21:15 +00:00
buf . append ( " <tr><th align= \" right \" > " + _ ( " WebApp " ) + " </th><th> " + _ ( " Run at Startup? " ) + " </th><th> " + _ ( " Start Now " ) + " </th><th align= \" left \" > " + _ ( " Description " ) + " </th></tr> \ n " ) ;
2008-06-16 12:31:14 +00:00
Properties props = RouterConsoleRunner . webAppProperties ( ) ;
Set keys = new TreeSet ( props . keySet ( ) ) ;
for ( Iterator iter = keys . iterator ( ) ; iter . hasNext ( ) ; ) {
String name = ( String ) iter . next ( ) ;
if ( name . startsWith ( RouterConsoleRunner . PREFIX ) & & name . endsWith ( RouterConsoleRunner . ENABLED ) ) {
2008-06-17 13:48:41 +00:00
String app = name . substring ( RouterConsoleRunner . PREFIX . length ( ) , name . lastIndexOf ( RouterConsoleRunner . ENABLED ) ) ;
2008-06-16 12:31:14 +00:00
String val = props . getProperty ( name ) ;
2008-06-17 13:48:41 +00:00
renderForm ( buf , app , app , ! " addressbook " . equals ( app ) , " true " . equals ( val ) , RouterConsoleRunner . ROUTERCONSOLE . equals ( app ) , app + " .war " ) ;
2008-06-16 12:31:14 +00:00
}
}
buf . append ( " </table> \ n " ) ;
return buf . toString ( ) ;
}
2009-07-01 16:00:43 +00:00
private void renderForm ( StringBuilder buf , String index , String name , boolean urlify , boolean enabled , boolean ro , String desc ) {
2009-08-01 03:28:42 +00:00
buf . append ( " <tr><td class= \" mediumtags \" align= \" right \" width= \" 25% \" > " ) ;
2008-06-16 12:31:14 +00:00
if ( urlify & & enabled ) {
String link = " / " ;
if ( ! RouterConsoleRunner . ROUTERCONSOLE . equals ( name ) )
link + = name + " / " ;
2009-10-26 21:48:46 +00:00
buf . append ( " <a href= \" " ) . append ( link ) . append ( " \" > " ) . append ( _ ( name ) ) . append ( " </a> " ) ;
2008-06-16 12:31:14 +00:00
} else {
2009-10-26 21:48:46 +00:00
buf . append ( _ ( name ) ) ;
2008-06-16 12:31:14 +00:00
}
2009-08-01 03:28:42 +00:00
buf . append ( " </td><td align= \" center \" width= \" 10% \" ><input type= \" checkbox \" class= \" optbox \" name= \" " ) . append ( index ) . append ( " .enabled \" value= \" true \" " ) ;
2008-06-16 12:31:14 +00:00
if ( enabled ) {
buf . append ( " checked= \" true \" " ) ;
if ( ro )
buf . append ( " disabled= \" true \" " ) ;
}
2009-08-01 03:28:42 +00:00
buf . append ( " /></td><td align= \" center \" width= \" 15% \" > " ) ;
2008-06-20 20:20:50 +00:00
if ( ! enabled ) {
2009-10-26 02:21:15 +00:00
buf . append ( " <button type= \" submit \" name= \" action \" value= \" Start " ) . append ( index ) . append ( " \" > " + _ ( " Start " ) + " <span class=hide> " ) . append ( index ) . append ( " </span></button> " ) ;
2008-06-20 20:20:50 +00:00
}
2009-08-01 03:28:42 +00:00
buf . append ( " </td><td align= \" left \" width= \" 50% \" > " ) . append ( desc ) . append ( " </td></tr> \ n " ) ;
2008-06-16 12:31:14 +00:00
}
}