[jboss-svn-commits] JBL Code SVN: r7769 - in labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting: . client

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 22 04:35:00 EST 2006


Author: noel.rocher at jboss.com
Date: 2006-11-22 04:34:59 -0500 (Wed, 22 Nov 2006)
New Revision: 7769

Added:
   labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/
   labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/SendPDFByMail.java
   labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/SimpleClient.java
   labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/jfreereport/
Log:


Added: labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/SendPDFByMail.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/SendPDFByMail.java	2006-11-22 09:34:45 UTC (rev 7768)
+++ labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/SendPDFByMail.java	2006-11-22 09:34:59 UTC (rev 7769)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.reporting.client;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+
+import org.jboss.reporting.api.Report;
+import org.jboss.reporting.api.ReportTask;
+import org.jboss.reporting.api.distribute.DistributeByMail;
+import org.jboss.reporting.api.impl.ReportTaskFactory;
+
+/**
+ * A simple example that is sending the report result by mail
+ * Default are used for PDF output and the mail subject.
+ * No CC/BCC for the mail and no lists either
+ * 
+ * @author noel
+ */
+public class SendPDFByMail
+{
+
+    /**
+     * arg[0] = report name to launch (the name used by reporting-services. For ex: /reports/MyReport) 
+     * arg[1] = email address for sent from 
+     * arg[2] = email address for send to 
+     * @param args
+     */
+    public static void main(String[] args)
+    {
+	if (args.length != 3)
+	{
+	    System.out.println("usage : java SendPDFByMail arg0 arg1 arg2 \n" +
+		    "\twith:\n" +
+		    "\targ0 = report name to launch (the name used by reporting-services. For ex: /reports/MyReport)\n" + 
+		    "\targ1 = email address for sent from\n" + 
+		    "\targ2 = email address for send to" +
+		    "\n\n Note : Don't forget to set up the mail server in your JBoss AS.");
+	}
+	else
+	{
+	    send(args[0], args[1], args[2]);
+	}
+
+    }
+
+
+
+    public static void send(String in_reportName, String in_sentFrom, String in_sendTo)
+    {
+	try
+	{
+	    ReportTask rt = ReportTaskFactory.getInstance();
+	    Report r = new Report(in_reportName);
+	    rt.setReport( r );
+
+	    DistributeByMail dist = new DistributeByMail(in_sentFrom, in_sendTo);
+	    rt.setDistribute( dist );
+
+	    rt.submit();
+
+	} catch (Exception e)
+	{
+	    // TODO Auto-generated catch block
+	    e.printStackTrace();
+	}
+    }
+
+}

Added: labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/SimpleClient.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/SimpleClient.java	2006-11-22 09:34:45 UTC (rev 7768)
+++ labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/client/SimpleClient.java	2006-11-22 09:34:59 UTC (rev 7769)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.reporting.client;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+
+import org.jboss.reporting.api.Report;
+import org.jboss.reporting.api.ReportData;
+import org.jboss.reporting.api.ReportTask;
+import org.jboss.reporting.api.impl.ReportTaskFactory;
+import org.jboss.reporting.client.jfreereport.SampleData3;
+
+/**
+ * @author noel
+ *
+ */
+public class SimpleClient
+{
+
+	/**
+	 * arg[0] = directory name where result files will be written
+	 * @param args
+	 */
+	public static void main(String[] args)
+	{
+		byte[] result = null;
+		String directoryName="";
+		Report r=null;
+		ReportTask rt=null;
+		
+		if (args.length == 1)
+		{
+			directoryName=args[0];
+		}
+		
+		try
+		{
+			// a simple jasperreports example
+			result = ReportTaskFactory.getInstance().executeToByteArray("reports/test1.era/test1/RotationReport1");
+			System.out.println("result size = " + result.length);
+			SimpleClient.writeToFile("", "test1Rotation.pdf", result);
+
+			// a simple jfreereport example
+			r = new Report("reports/test2.era/test2/test2_2/report3");
+			r = new Report("reports/report3");
+			r.setData( new ReportData( new SampleData3() ) );
+			rt = ReportTaskFactory.getInstance();
+			rt.setReport( r );
+			
+			result = rt.executeToByteArray();
+			System.out.println("result size = " + result.length);
+			SimpleClient.writeToFile(directoryName, "report3.pdf", result);
+			
+//		
+//			// a simple jasperreport example scheduled in three minutes by file copy
+//			r = new Report("reports/test1.era/RotationReport1");
+//			rt = ReportTaskFactory.getInstance();
+//			rt.setReport( r );
+//			rt.setDistribute(new DistributeByFileCopy());
+//			Calendar inThreeMin = Calendar.getInstance();
+//			inThreeMin.add(Calendar.MINUTE, 3);
+//			rt.setSchedule(new ScheduleOnce( inThreeMin   ));
+////			rt.setSchedule(new ScheduleNow());
+//			rt.submit();
+//			
+//			rt.setSchedule(new SchedulePeriodic(Calendar.getInstance(),1, SchedulePeriodic.PERIODE_UNIT_MINUTE));
+//			rt.submit();
+			
+		} catch (Exception e)
+		{
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	
+	public static void writeToFile(String in_directoryName, String in_fileName, byte[] in_content)
+	{
+		File file=null;
+		try
+		{
+			file=new File(in_fileName);
+			if (file.exists()) file.delete();
+			BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
+			out.write(in_content);
+			out.close();
+		} catch (Exception e)
+		{
+			e.printStackTrace();
+		}
+	}
+	
+}




More information about the jboss-svn-commits mailing list