1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.userinterface.ReportViewer; 4 import com.calipso.reportgenerator.common.IReportManager; 5 import com.calipso.reportgenerator.common.ReportGeneratorConfiguration; 6 import com.calipso.reportgenerator.client.ReportManagerService; 7 8 import javax.swing.*; 9 import java.awt.*; 10 11 import java.awt.event.*; 12 import java.io.*; 13 import java.rmi.RemoteException ; 14 import java.util.Map ; 15 import java.util.HashMap ; 16 import java.util.StringTokenizer ; 17 19 import org.apache.commons.configuration.PropertiesConfiguration; 20 import com.calipso.reportgenerator.common.InfoException; 21 22 23 26 public class ReportApplet extends JApplet implements ActionListener{ 27 private IReportManager reportManager; 28 private Container contentpane; 29 private JPanel jTreeSelectorPanel; 30 private PropertiesConfiguration configuration; 31 32 public void init(){ 33 try{ 34 contentpane = getContentPane(); 35 initReportManager(); 36 contentpane.add(jTreeSelectorPanel); 37 }catch (Exception e){ 38 e.printStackTrace(); 39 } 40 41 } 42 43 public void actionPerformed (ActionEvent e){ 44 45 } 46 47 public void initReportManager() throws RemoteException { 48 try { 49 String userId = getParameter("UserId") != null ? getParameter("UserId") : "" ; 50 String reportDefinitionId = getParameter("ReportDefinitionId") != null ? getParameter("ReportDefinitionId") : ""; 51 String reportViewId = getParameter("ReportViewId") != null ? getParameter("ReportViewId") : ""; 52 String propertiesPath = getParameter("PropertiesPath") != null ? getParameter("PropertiesPath") : ""; 53 boolean visibleActions = true; 54 if ( getParameter("VisibleActions") != null ){ 55 visibleActions = Boolean.valueOf(getParameter("VisibleActions")).booleanValue(); 56 } 57 Map params = getFilterParameters(); 58 59 ReportViewer reportViewer = new ReportViewer(userId, reportDefinitionId, reportViewId, propertiesPath, getReportManager(), new ReportGeneratorConfiguration(configuration), visibleActions, params); 60 jTreeSelectorPanel = reportViewer.getMainPanel(); 61 } catch (Exception e) { 62 e.printStackTrace(); 63 } 64 } 65 66 private Map getFilterParameters() { 67 if(getParameter("FilterParamNames") == null || getParameter("FilterParamValues") == null) { 68 return new HashMap (); 69 } else { 70 return getFilterParameters(getParameter("FilterParamNames"), getParameter("FilterParamValues")); 71 } 72 } 73 74 private Map getFilterParameters(String paramNames, String paramValues) { 75 StringTokenizer namesTokenizer = new StringTokenizer (paramNames, ","); 76 String [] names = new String [namesTokenizer.countTokens()]; 77 for(int i = 0 ; namesTokenizer.hasMoreTokens() ; i++) { 78 names [i] = namesTokenizer.nextToken(); 79 } 80 81 StringTokenizer valuesTokenizer = new StringTokenizer (paramValues, ","); 82 String [] values = new String [valuesTokenizer.countTokens()]; 83 for(int i = 0 ; valuesTokenizer.hasMoreTokens() ; i++) { 84 values [i] = valuesTokenizer.nextToken(); 85 } 86 87 return fillMapFrom(names, values); 88 } 89 90 private Map fillMapFrom(String [] names, String [] values) { 91 Map params = new HashMap (); 92 for(int i = 0 ; i < names.length ; i++) { 93 params.put(names [i], values [i]); 94 } 95 return params; 96 } 97 98 public IReportManager getReportManager() throws InfoException { 99 if (reportManager == null) { 100 try { 101 ReportManagerService reportManagerService = new ReportManagerService(); 102 ClassLoader loader = this.getClass().getClassLoader(); 103 System.out.println("loader resource"); 104 InputStream inputStream = loader.getResourceAsStream("ReportGeneratorConfiguration.properties"); 105 System.out.println("new properties"); 106 107 configuration= new PropertiesConfiguration(); 108 System.out.println("stream"); 109 System.out.println(inputStream.toString()); 110 System.out.println("load"); 111 configuration.load(inputStream); 112 System.out.println("init"); 113 reportManagerService.init(configuration, ""); 114 System.out.println(configuration.getString("ReportDefinitionRepositoryPath")); 115 reportManager = reportManagerService; 116 } 117 catch (Exception e) { 118 System.out.println("Error instanciando ReportManager"+e.getMessage()); 119 System.exit(1); 120 } 121 } 122 return reportManager; 123 } 124 125 } 126 | Popular Tags |