/*
  i-net software provides programming examples for illustration only, without warranty
  either expressed or implied, including, but not limited to, the implied warranties
  of merchantability and/or fitness for a particular purpose. This programming example
  assumes that you are familiar with the programming language being demonstrated and
  the tools used to create and debug procedures. i-net software support professionals
  can help explain the functionality of a particular procedure, but they will not modify
  these examples to provide added functionality or construct procedures to meet your
  specific needs.
  © i-net software 1998-2010
*/

package samples.servlet;

import java.util.Properties;

import com.inet.report.*;

/**
  This sample class extends the ReportServlet.
  It demonstrates you how to read, change or add a parameter of/to the report properties. 
  You only need to overwrite the method checkProperties to read, change or add the value(s)
  of the report properties like datasource, password, prompt# etc.

  Please refer to the i-net Clear Reports documentation for the list of all parameters 
  that you can read, change or add in/to the report properties. You can install 
  the i-net Clear Reports documentation using the setup tool or you can read it online:
  http://www.inetsoftware.de/documentation/crystal-clear/online-help/features/report-url-parameters.html.

  To use this servlet instead of the ReportServlet you need to (sample for Tomcat):
   - copy this file in: "<TOMCAT-HOME>/webapps/<SERVLET-CONTEXT>/WEB-INF/classes/" 
     ( <SERVLET-CONTEXT> is the context that you have specified in the i-net Clear Reports setup )
   - compile this class
   - replace the servlet-class "com.inet.report.ReportServlet" in the file: "TOMCAT-HOME>/webapps/<SERVLET-CONTEXT>/WEB-INF/web.xml"
     with the name of your servlet class: <servlet-class>ReportServletWithMyReportProperties</servlet-class>
   - call this servlet with: 
     http://<serverName>:8080/<servlet-context>/sample.rpt
      or
     http://<serverName>:8080/<servlet-context>/<url-pattern>?report=file:c:/reports/myReport.rpt
     ( <url-pattern> is configured in the file: "TOMCAT-HOME>/webapps/<SERVLET-CONTEXT>/WEB-INF/web.xml", 
     default <url-pattern>: ReportServlet ):
     http://<serverName>:8080/<servlet-context>/ReportServlet?report=file:c:/reports/myReport.rpt
*/

public class ReportServletWithMyReportProperties extends ReportServlet {
    
    /** 
     * This method from the ReportServlet you need to overwrite to read, set and/or modify the parameter values.
     * This method is empty in the class com.inet.report.ReportServlet.
     * 
     * @param reportProperties The user properties.
	 * @param servletRequest   The HTTP servlet request
	 * 
	 * @throws ReportException If an error occurred during checking the 
     * supplied properties with the current PropertiesChecker. 
     * The ReportException will be send to the client and displayed in the Java viewer.
     **/
    public void checkProperties(Properties reportProperties, Object servletRequest) throws ReportException {
        String currentReportName;
                
        currentReportName = ((String)reportProperties.get("report")).toLowerCase();
        // Check report name
        if (currentReportName.indexOf("report1.rpt") != -1) {
            // Change report parameter values
            // for Report1 we change the password and the RecordSelectionFormular
            reportProperties.put("password", "Password");
            reportProperties.put("sf",       "{List.UserID} = 404");
        } else if (currentReportName.indexOf("report2.rpt") != -1) {
            // Change report parameter values
            // here we set a date in a parameter field
            reportProperties.put("prompt0",  "Date(2000,05,18)");
        } else if (currentReportName.indexOf("report3.rpt") != -1) {
            // Change report parameter values
            // for this report we change the database
            // Example: Report3 was designed with the ODBC driver
            // Now we will use this report with the MS SQL Server
            reportProperties.put("datasource", "<Data Source Configuration Name>" ); // name of the Data Source Configuration
                                                                                     // that should be used for connection to SQL Server);         
            reportProperties.put("password",   "Password");
            reportProperties.put("prompt0",    "Date(2005,05,18)");  // a date in a parameter field
        } else if (currentReportName.indexOf("report4.rpt") != -1) {
            // Change report parameter values
            // for this report we change the database
            // Example: Report4 was designed with the ODBC driver
            // Now we will use this report with the Oracle Database
            reportProperties.put("datasource", "<Data Source Configuration Name>" ); // name of the Data Source Configuration 
                                                                                     // that should be used for connection to Oracle);
            reportProperties.put("password",   "Password");
            reportProperties.put("prompt0",    "Date(2008,01,15)");  // a date in a parameter field
            reportProperties.put("prompt1",    "2518");              // a number in the second parameter field
        }
        super.checkProperties(reportProperties, servletRequest);
    }
}
