1 9 10 package com.jaspersoft.jasperserver.irplugin; 11 12 import com.jaspersoft.jasperserver.irplugin.gui.CheckUpdateDialog; 13 import com.jaspersoft.jasperserver.irplugin.gui.RepositoryExplorer; 14 import it.businesslogic.ireport.gui.MainFrame; 15 import java.io.File ; 16 import java.io.FileInputStream ; 17 import java.io.FileOutputStream ; 18 import java.util.Properties ; 19 import javax.swing.JOptionPane ; 20 import javax.swing.SwingUtilities ; 21 22 26 public class IRPlugin extends it.businesslogic.ireport.plugin.IReportPlugin { 27 28 public static String configFileName = "jasperserverplugin.xml"; 29 public static final String REQUIRED_VERSION = "1.1.0"; 30 public static final String CURRENT_VERSION = "1.1.0"; 31 public static final String PROPERTY_CHECK_FOR_UPDATE = "PROPERTY_CHECK_FOR_UPDATE"; 32 33 private boolean viewVisible = false; 34 35 private boolean firstTime = true; 36 37 private static IRPlugin mainInstance = null; 38 public static IRPlugin getMainInstance() { 39 return mainInstance; 40 } 41 42 46 private java.util.List jServers = new java.util.ArrayList (); 47 48 51 private java.util.Properties properties = new java.util.Properties (); 52 53 54 private RepositoryExplorer repositoryExplorer = null; 55 boolean firstCall = true; 56 57 58 public IRPlugin() { 59 mainInstance = this; 60 } 61 62 public void call() { 63 64 if (getRepositoryExplorer() == null) 66 { 67 loadConfiguration(); 68 setRepositoryExplorer(new RepositoryExplorer(this)); 69 } 70 71 if (MainFrame.getMainInstance().constTitle.compareTo("iReport 1.2.6 ") < 0) 72 { 73 79 SwingUtilities.invokeLater( new Runnable () 80 { 81 public void run() 82 { 83 JOptionPane.showMessageDialog(null,"JasperReports plugin requires iReport 1.2.6 or above!"); 84 } 85 } 86 ); 87 return; 88 } 89 else 90 { 91 if (!isViewVisible()) 92 { 93 DockingUtil.installUI(getRepositoryExplorer()); 94 } 95 } 96 97 getMainFrame().logOnConsole("Checking? " + (!firstTime || getProperties().getProperty(PROPERTY_CHECK_FOR_UPDATE, "true").equals("true"))); 98 if (!firstTime || getProperties().getProperty(PROPERTY_CHECK_FOR_UPDATE, "true").equals("true")) 99 { 100 SwingUtilities.invokeLater( new Runnable () 101 { 102 103 public void run() 104 { 105 try { 106 UpgradeSearch us = new UpgradeSearch(); 107 Thread t = new Thread (us); 108 t.run(); 109 } catch (Throwable ex) { 110 ex.printStackTrace(); 111 } 112 } 113 }); 114 } 115 firstTime = false; 116 117 } 118 119 120 121 public void configure() { 122 CheckUpdateDialog cup = new CheckUpdateDialog(getMainFrame(), true); 123 cup.setVisible(true); 124 } 125 126 127 130 public void loadConfiguration() 131 { 132 setProperties(new java.util.Properties ()); 133 File configFile = new File ( MainFrame.IREPORT_USER_HOME_DIR, configFileName); 134 try { 135 136 if (configFile.exists()) 137 { 138 getProperties().loadFromXML( new FileInputStream ( configFile ) ); 139 } 140 } catch (Exception ex) 141 { 142 ex.printStackTrace(); 143 } 144 145 Properties props = getProperties(); 146 for (int i=0;props.getProperty("server."+i+".name") != null; ++i) 147 { 148 JServer server = new JServer(); 149 server.setName( props.getProperty("server."+i+".name") ); 150 server.setUrl( props.getProperty("server."+i+".url") ); 151 server.setUsername( props.getProperty("server."+i+".username") ); 152 server.setPassword( props.getProperty("server."+i+".password") ); 153 154 getJServers().add(server); 155 } 156 } 157 158 161 public boolean saveConfiguration() 162 { 163 File dir = new File ( MainFrame.IREPORT_USER_HOME_DIR ); 164 165 for (int i=0; getProperties().getProperty("server."+i+".name") != null; ++i) 169 { 170 getProperties().remove("server."+i+".name"); 171 getProperties().remove("server."+i+".url"); 172 getProperties().remove("server."+i+".username"); 173 getProperties().remove("server."+i+".password"); 174 } 175 176 for (int i=0; i<getJServers().size(); ++i) 177 { 178 JServer server = (JServer)getJServers().get(i); 179 getProperties().setProperty("server."+i+".name", server.getName()); 180 getProperties().setProperty("server."+i+".url", server.getUrl()); 181 getProperties().setProperty("server."+i+".username", server.getUsername()); 182 getProperties().setProperty("server."+i+".password", server.getPassword()); 183 } 184 185 try { 186 if (dir.exists()) { 187 if (!dir.isDirectory() ) { 188 javax.swing.JOptionPane.showMessageDialog( getMainFrame(), dir.getPath() +" is not a directory!\nPlease rename this file and retry to save config!","",JOptionPane.ERROR_MESSAGE); 189 return false; 190 } 191 } 192 else { 193 dir.mkdirs(); 194 } 195 196 File configFile = new File (dir,configFileName); 197 getProperties().storeToXML(new FileOutputStream (configFile),"JasperServer Plugin configuration file\n (c) 2006 by JasperSoft"); 198 199 return true; 200 } catch (Exception ex) { 201 javax.swing.JOptionPane.showMessageDialog( getMainFrame(), "An error is occurred saving Plugin config:\n"+ex.getMessage()+"\nPlease try to save config again!","",JOptionPane.ERROR_MESSAGE); 202 return false; 203 } 204 } 205 206 209 public java.util.Properties getProperties() { 210 return properties; 211 } 212 213 216 public void setProperties(java.util.Properties properties) { 217 this.properties = properties; 218 } 219 220 public java.util.List getJServers() { 221 return jServers; 222 } 223 224 public void setJServers(java.util.List jServers) { 225 this.jServers = jServers; 226 } 227 228 241 public static String createTmpFileName(String filePrefix, String fileExtension) 242 { 243 if (filePrefix == null) filePrefix = ""; 244 else filePrefix += "_"; 245 if (fileExtension != null && !fileExtension.startsWith(".")) 246 { 247 fileExtension = "." + fileExtension; 248 } 249 250 if (fileExtension == null) fileExtension = ".tmp"; 251 252 String tmpDirectory = MainFrame.getMainInstance().IREPORT_USER_HOME_DIR; 253 tmpDirectory += File.separator + "jstmp"; 254 255 File tmpDirectoryFile = new File (tmpDirectory); 256 if (!tmpDirectoryFile.exists()) 257 { 258 tmpDirectoryFile.mkdirs(); 259 } 260 261 return tmpDirectoryFile + File.separator + filePrefix + (new java.util.Date ()).getTime() + fileExtension; 262 263 } 264 265 public RepositoryExplorer getRepositoryExplorer() { 266 return repositoryExplorer; 267 } 268 269 public void setRepositoryExplorer(RepositoryExplorer repositoryExplorer) { 270 this.repositoryExplorer = repositoryExplorer; 271 } 272 273 public boolean isViewVisible() { 274 return viewVisible; 275 } 276 277 public void setViewVisible(boolean viewVisible) { 278 this.viewVisible = viewVisible; 279 } 280 } | Popular Tags |