001: package com.calipso.reportgenerator.userinterface;
002:
003: import com.calipso.reportgenerator.common.InfoException;
004: import com.calipso.reportgenerator.common.IReportManager;
005: import com.calipso.reportgenerator.common.LanguageTraslator;
006: import com.calipso.reportgenerator.client.ReportManagerService;
007:
008: import javax.swing.*;
009: import java.awt.event.WindowAdapter;
010: import java.awt.event.WindowEvent;
011: import java.util.Map;
012: import java.util.HashMap;
013:
014: /**
015: * Aplicación para ejecutar el ReportViewer
016: */
017: public class ReportViewerApp {
018:
019: private String callingProgramId = "";
020: private String configPath;
021: private String userId;
022: private String reportDefinitionId;
023: private String reportViewId = "";
024: private String distributedHost = "";
025: private boolean visibleActions = true;
026: private Map params;
027: private String microReportFileName = "";
028: private boolean serverLocation = true;
029:
030: public ReportViewerApp(String configPath, String args[]) {
031: this .configPath = configPath;
032: this .userId = getArg("UserId", args);
033: this .reportDefinitionId = getArg("ReportDefinitionId", args);
034: this .reportViewId = getArg("ReportViewId", args);
035: this .callingProgramId = getArg("ProgramId", args);
036: this .microReportFileName = getArg("MicroReportFileName", args);
037: this .distributedHost = getArg("DistributedHost", args);
038: if (getArg("Location", args).equalsIgnoreCase("local")) {
039: serverLocation = false;
040: }
041: if (getArg("VisibleActions", args).equalsIgnoreCase("false")) {
042: this .visibleActions = false;
043: }
044: initSystemParams();
045: fillReportParams(args);
046: }
047:
048: /**
049: * Si algun parametro es "" y esta especificado en las System.getProperties (no null ni ""), entonces setea el argumento
050: */
051: private void initSystemParams() {
052: if (configPath.equalsIgnoreCase("")
053: && System.getProperty("ConfigPath") != null
054: && !System.getProperty("ConfigPath").equalsIgnoreCase(
055: "")) {
056: this .configPath = System.getProperty("ConfigPath");
057: }
058: if (userId.equalsIgnoreCase("")
059: && System.getProperty("UserId") != null
060: && !System.getProperty("UserId").equalsIgnoreCase("")) {
061: this .userId = System.getProperty("UserId");
062: }
063: if (reportDefinitionId.equalsIgnoreCase("")
064: && System.getProperty("ReportDefinitionId") != null
065: && !System.getProperty("ReportDefinitionId")
066: .equalsIgnoreCase("")) {
067: this .reportDefinitionId = System
068: .getProperty("ReportDefinitionId");
069: }
070: if (distributedHost.equalsIgnoreCase("")
071: && System.getProperty("DistributedHost") != null
072: && !System.getProperty("DistributedHost")
073: .equalsIgnoreCase("")) {
074: this .distributedHost = System
075: .getProperty("DistributedHost");
076: }
077: if (reportViewId.equalsIgnoreCase("")
078: && System.getProperty("ReportViewId") != null
079: && !System.getProperty("ReportViewId")
080: .equalsIgnoreCase("")) {
081: this .reportViewId = System.getProperty("ReportViewId");
082: }
083: if (callingProgramId.equalsIgnoreCase("")
084: && System.getProperty("CallingProgramId") != null
085: && !System.getProperty("CallingProgramId")
086: .equalsIgnoreCase("")) {
087: this .callingProgramId = System
088: .getProperty("CallingProgramId");
089: }
090: if (microReportFileName.equalsIgnoreCase("")
091: && System.getProperty("MicroReportFileName") != null
092: && !System.getProperty("MicroReportFileName")
093: .equalsIgnoreCase("")) {
094: this .microReportFileName = System
095: .getProperty("MicroReportFileName");
096: }
097: if (serverLocation && System.getProperty("Location") != null
098: && !System.getProperty("Location").equalsIgnoreCase("")) {
099: if (System.getProperty("Location")
100: .equalsIgnoreCase("local")) {
101: this .serverLocation = false;
102: }
103: }
104: if (visibleActions
105: && System.getProperty("VisibleActions") != null
106: && !System.getProperty("VisibleActions")
107: .equalsIgnoreCase("")) {
108: if (System.getProperty("VisibleActions").equalsIgnoreCase(
109: "false")) {
110: this .visibleActions = false;
111: }
112: }
113: }
114:
115: /**
116: * Llena los parámetros del reporte
117: */
118: private void fillReportParams(String args[]) {
119: String paramName;
120: String paramValue;
121: if (!this .reportDefinitionId.equals("")) {
122: if (args != null) {
123: int indexParam;
124: int indexValue;
125: for (int i = 0; i < args.length; i++) {
126: indexParam = args[i].indexOf("Param-");
127: indexValue = args[i].indexOf("=");
128: if ((indexParam >= 0) && (indexValue >= 0)) {
129: paramName = args[i].substring(("Param-")
130: .length()
131: + indexParam, indexValue);
132: paramValue = args[i].substring(indexValue + 1,
133: args[i].length());
134: getParams().put(paramName, paramValue);
135: }
136: }
137: }
138: }
139: }
140:
141: private Map getParams() {
142: if (params == null) {
143: params = new HashMap();
144: }
145: return params;
146: }
147:
148: private String getArg(String s, String args[]) {
149: String returnValue = "";
150: if (args != null) {
151: int index;
152: for (int i = 0; (i < args.length) && returnValue.equals(""); i++) {
153: index = args[i].indexOf(s);
154: if (index >= 0) {
155: returnValue = args[i].substring(s.length() + index
156: + 1, args[i].length());
157: }
158: }
159: }
160: return returnValue;
161: }
162:
163: public static void main(String args[]) throws InfoException {
164:
165: ReportViewerApp reportViewerApp = new ReportViewerApp("", args);
166: reportViewerApp.show();
167: }
168:
169: public void show() throws InfoException {
170: //setLookAndFeel();
171: IReportManager service = ReportManagerService
172: .getReportManagerService(configPath, null,
173: distributedHost);
174: checkLicence(service);
175: boolean validate = false;
176: try {
177: validate = LoginValidation.validate("", "Login", service,
178: callingProgramId);
179: } catch (Exception e) {
180: e.printStackTrace();
181: JOptionPane.showMessageDialog(null, e.getMessage(),
182: LanguageTraslator.traslate("231"),
183: JOptionPane.ERROR_MESSAGE);
184: }
185: if (validate) { //UserLoginFrame.login("root", "Login", service)) {
186: ReportViewer reportViewer;
187: /*if(LoginValidation.getUserName().equalsIgnoreCase("root")){
188: JOptionPane.showMessageDialog(null, LanguageTraslator.traslate("402"), "", JOptionPane.WARNING_MESSAGE);
189: } */
190: if (microReportFileName.equals("")) {
191: reportViewer = new ReportViewer(LoginValidation
192: .getUserName(), reportDefinitionId,
193: reportViewId, "", service, visibleActions,
194: params);
195: } else {
196: reportViewer = new ReportViewer(LoginValidation
197: .getUserName(), microReportFileName,
198: serverLocation, "", service, visibleActions,
199: params);
200: }
201: reportViewer.addWindowListener(new WindowAdapter() {
202: public void windowClosing(WindowEvent e) {
203: System.exit(0);
204: }
205: });
206: reportViewer.setVisible(true);
207: } else {
208: JOptionPane.showMessageDialog(null, LanguageTraslator
209: .traslate("364"),
210: LanguageTraslator.traslate("231"),
211: JOptionPane.ERROR_MESSAGE);
212: System.out.println(LanguageTraslator.traslate("364"));
213: System.exit(0);
214: }
215: }
216:
217: private void checkLicence(IReportManager service) {
218: try {
219: if (!service.isAcceptedLicence()) {
220: boolean accept = LicenceFrame.accept();
221: if (accept) {
222: service.acceptedLicence(true);
223: } else {
224: System.exit(0);
225: }
226: }
227: } catch (Exception e) {
228: JOptionPane.showMessageDialog(null, e.getMessage(),
229: LanguageTraslator.traslate("582"),
230: JOptionPane.ERROR_MESSAGE);
231: System.exit(0);
232: }
233: }
234: }
|