KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > userinterface > ReportViewerApp


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 JavaDoc;
10 import java.awt.event.WindowEvent JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.HashMap JavaDoc;
13
14 /**
15  * Aplicación para ejecutar el ReportViewer
16  */

17 public class ReportViewerApp {
18
19   private String JavaDoc callingProgramId = "";
20   private String JavaDoc configPath;
21   private String JavaDoc userId;
22   private String JavaDoc reportDefinitionId;
23   private String JavaDoc reportViewId="";
24   private String JavaDoc distributedHost="";
25   private boolean visibleActions=true;
26   private Map JavaDoc params;
27   private String JavaDoc microReportFileName = "";
28   private boolean serverLocation = true;
29
30   public ReportViewerApp(String JavaDoc configPath, String JavaDoc 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   /**
49    * Si algun parametro es "" y esta especificado en las System.getProperties (no null ni ""), entonces setea el argumento
50    */

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   /**
86    * Llena los parámetros del reporte
87    */

88   private void fillReportParams(String JavaDoc args[]) {
89     String JavaDoc paramName;
90     String JavaDoc 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 JavaDoc getParams(){
109     if (params==null){
110       params = new HashMap JavaDoc();
111     }
112     return params;
113   }
114
115   private String JavaDoc getArg(String JavaDoc s, String JavaDoc args[]) {
116     String JavaDoc 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 JavaDoc args[]) throws InfoException {
130
131     ReportViewerApp reportViewerApp = new ReportViewerApp("", args);
132     reportViewerApp.show();
133   }
134
135   public void show() throws InfoException {
136     //setLookAndFeel();
137
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 JavaDoc e){
143       e.printStackTrace();
144       JOptionPane.showMessageDialog(null, e.getMessage(),LanguageTraslator.traslate("231"),JOptionPane.ERROR_MESSAGE);
145     }
146     if(validate){ //UserLoginFrame.login("root", "Login", service)) {
147
ReportViewer reportViewer;
148       /*if(LoginValidation.getUserName().equalsIgnoreCase("root")){
149         JOptionPane.showMessageDialog(null, LanguageTraslator.traslate("402"), "", JOptionPane.WARNING_MESSAGE);
150       } */

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 JavaDoc() {
157         public void windowClosing(WindowEvent JavaDoc 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 JavaDoc e){
182       JOptionPane.showMessageDialog(null, e.getMessage(),LanguageTraslator.traslate("582"),JOptionPane.ERROR_MESSAGE);
183       System.exit(0);
184     }
185   }
186 }
187
Popular Tags