001: package com.calipso.reportgenerator.userinterface;
002:
003: import com.calipso.reportgenerator.userinterface.ReportViewer;
004: import com.calipso.reportgenerator.common.IReportManager;
005: import com.calipso.reportgenerator.common.ReportGeneratorConfiguration;
006: import com.calipso.reportgenerator.client.ReportManagerService;
007:
008: import javax.swing.*;
009: import java.awt.*;
010:
011: import java.awt.event.*;
012: import java.io.*;
013: import java.rmi.RemoteException;
014: import java.util.Map;
015: import java.util.HashMap;
016: import java.util.StringTokenizer; //import java.util.regex.Matcher;
017:
018: import org.apache.commons.configuration.PropertiesConfiguration;
019: import com.calipso.reportgenerator.common.InfoException;
020:
021: /**
022:
023: */
024: public class ReportApplet extends JApplet implements ActionListener {
025: private IReportManager reportManager;
026: private Container contentpane;
027: private JPanel jTreeSelectorPanel;
028: private PropertiesConfiguration configuration;
029:
030: public void init() {
031: try {
032: contentpane = getContentPane();
033: initReportManager();
034: contentpane.add(jTreeSelectorPanel);
035: } catch (Exception e) {
036: e.printStackTrace();
037: }
038:
039: }
040:
041: public void actionPerformed(ActionEvent e) {
042:
043: }
044:
045: public void initReportManager() throws RemoteException {
046: try {
047: String userId = getParameter("UserId") != null ? getParameter("UserId")
048: : "";
049: String reportDefinitionId = getParameter("ReportDefinitionId") != null ? getParameter("ReportDefinitionId")
050: : "";
051: String reportViewId = getParameter("ReportViewId") != null ? getParameter("ReportViewId")
052: : "";
053: String propertiesPath = getParameter("PropertiesPath") != null ? getParameter("PropertiesPath")
054: : "";
055: boolean visibleActions = true;
056: if (getParameter("VisibleActions") != null) {
057: visibleActions = Boolean.valueOf(
058: getParameter("VisibleActions")).booleanValue();
059: }
060: Map params = getFilterParameters();
061:
062: ReportViewer reportViewer = new ReportViewer(userId,
063: reportDefinitionId, reportViewId, propertiesPath,
064: getReportManager(),
065: new ReportGeneratorConfiguration(configuration),
066: visibleActions, params);
067: jTreeSelectorPanel = reportViewer.getMainPanel();
068: } catch (Exception e) {
069: e.printStackTrace();
070: }
071: }
072:
073: private Map getFilterParameters() {
074: if (getParameter("FilterParamNames") == null
075: || getParameter("FilterParamValues") == null) {
076: return new HashMap();
077: } else {
078: return getFilterParameters(
079: getParameter("FilterParamNames"),
080: getParameter("FilterParamValues"));
081: }
082: }
083:
084: private Map getFilterParameters(String paramNames,
085: String paramValues) {
086: StringTokenizer namesTokenizer = new StringTokenizer(
087: paramNames, ",");
088: String[] names = new String[namesTokenizer.countTokens()];
089: for (int i = 0; namesTokenizer.hasMoreTokens(); i++) {
090: names[i] = namesTokenizer.nextToken();
091: }
092:
093: StringTokenizer valuesTokenizer = new StringTokenizer(
094: paramValues, ",");
095: String[] values = new String[valuesTokenizer.countTokens()];
096: for (int i = 0; valuesTokenizer.hasMoreTokens(); i++) {
097: values[i] = valuesTokenizer.nextToken();
098: }
099:
100: return fillMapFrom(names, values);
101: }
102:
103: private Map fillMapFrom(String[] names, String[] values) {
104: Map params = new HashMap();
105: for (int i = 0; i < names.length; i++) {
106: params.put(names[i], values[i]);
107: }
108: return params;
109: }
110:
111: public IReportManager getReportManager() throws InfoException {
112: if (reportManager == null) {
113: try {
114: ReportManagerService reportManagerService = new ReportManagerService();
115: ClassLoader loader = this .getClass().getClassLoader();
116: System.out.println("loader resource");
117: InputStream inputStream = loader
118: .getResourceAsStream("ReportGeneratorConfiguration.properties");
119: System.out.println("new properties");
120:
121: configuration = new PropertiesConfiguration();
122: System.out.println("stream");
123: System.out.println(inputStream.toString());
124: System.out.println("load");
125: configuration.load(inputStream);
126: System.out.println("init");
127: reportManagerService.init(configuration, "");
128: System.out.println(configuration
129: .getString("ReportDefinitionRepositoryPath"));
130: reportManager = reportManagerService;
131: } catch (Exception e) {
132: System.out.println("Error instanciando ReportManager"
133: + e.getMessage());
134: System.exit(1);
135: }
136: }
137: return reportManager;
138: }
139:
140: }
|