import java.util.*;
import java.io.*;
import com.gestalt.scribe.*;
public class Test3
{
/*
** Demo of the app using Scribe API to produce a report and save it in a PDF file.
*/
public static void main(String args[])
{
new Test3();
}
public Test3()
{
/*
** Connect to Scribe Server
*/
System.out.println("Connecting...");
Connector conn = null;
try
{
conn = new Connector("localhost", 6541, "heidi", "hello");
}
catch (ServerConnectionException e)
{
System.out.println(e);
System.exit(1);
}
System.out.println("DONE");
/*
** Run report
*/
String reportName = "Query/Customer";
try
{
/*
** The report "Query/Customer" takes one parameter - customer ID.
** We run this report for the customer "VINET". The parameter is
** passed to the server as a Parameter object (part of the API library)
** stored in a Vector.
*/
Vector parameterList = conn.getReportParameters(reportName);
Parameter packet = (Parameter) parameterList.elementAt(0);
packet.setValue("VINET");
byte[] data = conn.getReportAsPDF(reportName, parameterList);
/*
** getReportAsPDF() method of Connector returns a byte array
** with the content of PDF-formatted report that is saved in a file.
*/
try
{
String fileName = "C:\\Customer.pdf";
FileOutputStream f = new FileOutputStream(fileName);
f.write(data);
f.flush();
f.close();
}
catch (IOException e) { System.out.println(e); }
}
catch (Exception e)
{
System.out.println(e);
}
conn.disconnect();
System.exit(0);
}
}