1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.common.InfoException; 4 import com.calipso.reportgenerator.common.IReportManager; 5 import com.calipso.reportgenerator.common.LanguageTraslator; 6 import com.calipso.reportgenerator.client.ReportManagerService; 7 8 import javax.swing.*; 9 import java.awt.event.WindowAdapter ; 10 import java.awt.event.WindowEvent ; 11 import java.util.Map ; 12 import java.util.HashMap ; 13 14 17 public class ReportViewerApp { 18 19 private String callingProgramId = ""; 20 private String configPath; 21 private String userId; 22 private String reportDefinitionId; 23 private String reportViewId=""; 24 private String distributedHost=""; 25 private boolean visibleActions=true; 26 private Map params; 27 private String microReportFileName = ""; 28 private boolean serverLocation = true; 29 30 public ReportViewerApp(String configPath, String args[]) { 31 this.configPath = configPath; 32 this.userId = getArg("UserId",args); 33 this.reportDefinitionId = getArg("ReportDefinitionId",args); 34 this.reportViewId = getArg("ReportViewId",args); 35 this.callingProgramId = getArg("ProgramId", args); 36 this.microReportFileName = getArg("MicroReportFileName", args); 37 this.distributedHost = getArg("DistributedHost", args); 38 if(getArg("Location", args).equalsIgnoreCase("local")){ 39 serverLocation = false; 40 } 41 if (getArg("VisibleActions",args).equalsIgnoreCase("false")){ 42 this.visibleActions = false; 43 } 44 initSystemParams(); 45 fillReportParams(args); 46 } 47 48 51 private void initSystemParams() { 52 if(configPath.equalsIgnoreCase("") && System.getProperty("ConfigPath")!=null && !System.getProperty("ConfigPath").equalsIgnoreCase("")){ 53 this.configPath = System.getProperty("ConfigPath"); 54 } 55 if(userId.equalsIgnoreCase("") && System.getProperty("UserId")!=null && !System.getProperty("UserId").equalsIgnoreCase("")){ 56 this.userId = System.getProperty("UserId"); 57 } 58 if(reportDefinitionId.equalsIgnoreCase("") && System.getProperty("ReportDefinitionId")!=null && !System.getProperty("ReportDefinitionId").equalsIgnoreCase("")){ 59 this.reportDefinitionId = System.getProperty("ReportDefinitionId"); 60 } 61 if(distributedHost.equalsIgnoreCase("") && System.getProperty("DistributedHost")!=null && !System.getProperty("DistributedHost").equalsIgnoreCase("")){ 62 this.distributedHost = System.getProperty("DistributedHost"); 63 } 64 if(reportViewId.equalsIgnoreCase("") && System.getProperty("ReportViewId")!=null && !System.getProperty("ReportViewId").equalsIgnoreCase("")){ 65 this.reportViewId = System.getProperty("ReportViewId"); 66 } 67 if(callingProgramId.equalsIgnoreCase("") && System.getProperty("CallingProgramId")!=null && !System.getProperty("CallingProgramId").equalsIgnoreCase("")){ 68 this.callingProgramId = System.getProperty("CallingProgramId"); 69 } 70 if(microReportFileName.equalsIgnoreCase("") && System.getProperty("MicroReportFileName")!=null && !System.getProperty("MicroReportFileName").equalsIgnoreCase("")){ 71 this.microReportFileName = System.getProperty("MicroReportFileName"); 72 } 73 if(serverLocation && System.getProperty("Location")!=null && !System.getProperty("Location").equalsIgnoreCase("")){ 74 if(System.getProperty("Location").equalsIgnoreCase("local")){ 75 this.serverLocation = false; 76 } 77 } 78 if(visibleActions && System.getProperty("VisibleActions")!=null && !System.getProperty("VisibleActions").equalsIgnoreCase("")){ 79 if(System.getProperty("VisibleActions").equalsIgnoreCase("false")){ 80 this.visibleActions = false; 81 } 82 } 83 } 84 85 88 private void fillReportParams(String args[]) { 89 String paramName; 90 String paramValue; 91 if (!this.reportDefinitionId.equals("")){ 92 if (args != null ){ 93 int indexParam; 94 int indexValue; 95 for (int i = 0; i < args.length ; i++){ 96 indexParam = args[i].indexOf("Param-"); 97 indexValue = args[i].indexOf("="); 98 if ((indexParam >= 0 )&&(indexValue >=0)){ 99 paramName = args[i].substring(("Param-").length()+indexParam,indexValue); 100 paramValue = args[i].substring(indexValue+1,args[i].length()); 101 getParams().put(paramName,paramValue); 102 } 103 } 104 } 105 } 106 } 107 108 private Map getParams(){ 109 if (params==null){ 110 params = new HashMap (); 111 } 112 return params; 113 } 114 115 private String getArg(String s, String args[]) { 116 String returnValue = ""; 117 if (args != null ){ 118 int index; 119 for (int i = 0; (i < args.length) && returnValue.equals(""); i++){ 120 index = args[i].indexOf(s); 121 if (index >= 0 ){ 122 returnValue = args[i].substring(s.length()+index+1,args[i].length()); 123 } 124 } 125 } 126 return returnValue; 127 } 128 129 public static void main(String args[]) throws InfoException { 130 131 ReportViewerApp reportViewerApp = new ReportViewerApp("", args); 132 reportViewerApp.show(); 133 } 134 135 public void show() throws InfoException { 136 IReportManager service = ReportManagerService.getReportManagerService(configPath ,null, distributedHost); 138 checkLicence(service); 139 boolean validate = false; 140 try{ 141 validate = LoginValidation.validate("", "Login", service, callingProgramId); 142 }catch (Exception e){ 143 e.printStackTrace(); 144 JOptionPane.showMessageDialog(null, e.getMessage(),LanguageTraslator.traslate("231"),JOptionPane.ERROR_MESSAGE); 145 } 146 if(validate){ ReportViewer reportViewer; 148 151 if (microReportFileName.equals("")){ 152 reportViewer = new ReportViewer(LoginValidation.getUserName(), reportDefinitionId,reportViewId,"",service,visibleActions, params); 153 }else{ 154 reportViewer = new ReportViewer(LoginValidation.getUserName(),microReportFileName, serverLocation ,"",service,visibleActions, params); 155 } 156 reportViewer.addWindowListener(new WindowAdapter () { 157 public void windowClosing(WindowEvent e) { 158 System.exit(0); 159 } 160 }); 161 reportViewer.setVisible(true); 162 }else{ 163 JOptionPane.showMessageDialog(null,LanguageTraslator.traslate("364"),LanguageTraslator.traslate("231"),JOptionPane.ERROR_MESSAGE); 164 System.out.println(LanguageTraslator.traslate("364")); 165 System.exit(0); 166 } 167 } 168 169 private void checkLicence(IReportManager service){ 170 try{ 171 if (!service.isAcceptedLicence()){ 172 boolean accept = LicenceFrame.accept(); 173 if (accept){ 174 service.acceptedLicence(true); 175 } 176 else{ 177 System.exit(0); 178 } 179 } 180 } 181 catch(Exception e){ 182 JOptionPane.showMessageDialog(null, e.getMessage(),LanguageTraslator.traslate("582"),JOptionPane.ERROR_MESSAGE); 183 System.exit(0); 184 } 185 } 186 } 187 | Popular Tags |