1 32 33 package it.businesslogic.ireport.plugin.locale; 34 35 import com.jaspersoft.babylon.JasperBabylonClient; 36 import it.businesslogic.ireport.gui.MainFrame; 37 38 42 public class JasperBabylonRunner implements Runnable { 43 44 public static String IREPORT_APP_ID="1"; 45 private JasperBabylonRunnerListener runnerListener; 46 private int operation = 0; 47 private JasperBabylonClient jbc = new JasperBabylonClient(); 48 49 public static final int OP_LIST_LOCALES = 1; 50 public static final int OP_GET_LOCALE = 2; 51 public static final int OP_PUT_LOCALE = 3; 52 53 private String localeId = null; 54 private java.util.Properties props = null; 55 56 public void listLocales() 57 { 58 operation = OP_LIST_LOCALES; 59 jbc.setAppId( IREPORT_APP_ID ); 60 jbc.setJasperBabylonUrl( MainFrame.getMainInstance().getProperties().getProperty("jasperBabylonURL","http://www.jasperforge.org/jasperbabylon")); 61 Thread t = new Thread (this); 62 t.start(); 63 } 64 65 public void getLocale(String localeId) 66 { 67 operation = OP_GET_LOCALE; 68 jbc.setAppId( IREPORT_APP_ID ); 69 jbc.setJasperBabylonUrl( MainFrame.getMainInstance().getProperties().getProperty("jasperBabylonURL","http://www.jasperforge.org/jasperbabylon")); 70 this.localeId = localeId; 71 Thread t = new Thread (this); 72 t.start(); 73 } 74 75 76 public void putLocale(String localeId, java.util.Properties props) 77 { 78 operation = OP_PUT_LOCALE; 79 jbc.setAppId( IREPORT_APP_ID ); 80 jbc.setJasperBabylonUrl( MainFrame.getMainInstance().getProperties().getProperty("jasperBabylonURL","http://www.jasperforge.org/jasperbabylon")); 81 jbc.setUsername(MainFrame.getMainInstance().getProperties().getProperty("jasperBabylonUsername") ); 82 jbc.setPassword(MainFrame.getMainInstance().getProperties().getProperty("jasperBabylonPassword") ); 83 this.props = props; 84 this.localeId = localeId; 85 Thread t = new Thread (this); 86 t.start(); 87 88 } 89 90 public void run() { 91 try { 92 switch (operation) 93 { 94 case OP_LIST_LOCALES: 95 java.util.List list = jbc.listLocales(); 96 this.getRunnerListener().listLocalesComplete(list); 97 break; 98 99 case OP_GET_LOCALE: 100 java.util.Properties p = jbc.getLocale( this.localeId ); 101 this.getRunnerListener().getLocaleComplete(p); 102 break; 103 104 case OP_PUT_LOCALE: 105 String s = jbc.putLocale(this.localeId, props); 106 this.getRunnerListener().putLocaleComplete(s); 107 break; 108 } 109 110 111 } catch (Exception ex) 112 { 113 this.getRunnerListener().operationError(operation, ex.getMessage()); 114 } 115 } 116 117 public JasperBabylonRunnerListener getRunnerListener() { 118 return runnerListener; 119 } 120 121 public void setRunnerListener(JasperBabylonRunnerListener runnerListener) { 122 this.runnerListener = runnerListener; 123 } 124 } 125 126 | Popular Tags |