Skip to main content
Windward

Appendices

Overview

Implementing the interface and more.

Appendix A: Implementing the Bean Provider Interface

This code illustrates how to implement the Bean Provider interface. This code is in the BeanProviderImpl.java file, located in the WindwardReports.jar file. This is a do-nothing bean. If you set this as a bean in a tag, it would be identical to not having the bean there.

/*

* Copyright (c) 2004 by Windward Studios, Inc. All rights reserved.

*

* This software is the confidential and proprietary information of

* Windward Studios ("Confidential Information"). You shall not

* disclose such Confidential Information and shall use it only in

* accordance with the terms of the license agreement you entered into

* with Windward Studios, Inc.

*/

package net.windward.bean;

import net.windward.tags.*;

import java.util.Locale;

/**

* This implements a do nothing implementation of BeanProvider. It is equivalent to

* not having a bean. To implement a bean you can override this class and then

* implement all methods that need to perform non-default actions.

* Note: you do not need to inherit from this class to create a bean. You only need

* to implement the BeanProvider interface. This class exists as a convenience for

* developers who wish to use it.

*

* @version 1.0 Jun 18, 2004

*/

public abstract class BeanProviderImpl implements BeanProvider {

/**

* Process a <wr:function ... /> tag. Return the string and formatting

* to display.

*

* @param tag The tag that is being printed.

* @param value The final string value for the tag.

* @param locale The locale in effect for the document.

* @return The string and formatting to write at this point in the report.

*/

public BeanResult functionTag (FunctionTag tag, String value, Locale locale) throws BeanProviderException {

return new BeanResult(value);

}

/**

* Process a <wr:out ... /> tag. Return the string and formatting to

* display.

*

* @param tag The tag that is being printed.

* @param value The final string value for the tag.

* @param locale The locale in effect for the document.

* @return The string and formatting to write at this point in the report.

*/

public BeanResult outTag (OutTag tag, String value, Locale locale) throws BeanProviderException {

return new BeanResult(value);

}

/**

* Process a <wr:forEach ... /> tag. This is called before each iteration

* of a forEach loop. This provides the ability to end a loop early. Return true

* to continue in the loop and false to end the loop.

*

* @param tag The tag that is being iterated.

* @return true to continue in the loop and false to end the loop.

*/

public boolean forEachTag (ForEachTag tag) {

return true;

}

/**

* Process a <wr:if ... /> tag. This provides the ability to set the value

* of the if. Return true to include the text inside the if and false to skip the

* if (or process the else if there is one).

*

* @param tag The tag that is being evaluted.

* @param value The evaluated value of the tag.

* @return true true to include the text inside the if and false to skip the if

* (or process the else if there is one).

*/

public boolean ifTag (IfTag tag, boolean value) {

return value;

}

}

Appendix B: Using a Bean in a Template

This example illustrates how to use a bean in a template, and may be found in Sample 14.

A simple bean sample – list sales

This sample does not use the field format for the tags so they are easier to read.

 

<wr:forEach select=’/order/item’><wr:out select=’./quantity’/>

<wr:out select=’./description’/>

<wr:out select=’./unit’ type=’CURRENCY’ bean=”RedNegative”/>

<wr:out select=’./total’ type=’CURRENCY’ bean=’RunningTotal’/>

</wr:forEach>

 

total

<wr:out select=’’ type=’CURRENCY’ bean=’RunningTotal’ total=’display’/>

 

Please note that the final total has a select=’’. This is because the select attribute is required but because there is a bean, it can have an empty value (and should in this case). You can only do select=’’ for the out and function tags.

Appendix C: Using Beans when Calling WR Directly

This code illustrates how to use beans when calling WR directly. This code is located in Sample 14.

/*

* Copyright (c) 2002 - 2004 by Windward Studios, Inc. All rights reserved.

*

* This software is the confidential and proprietary information of

* Windward Studios ("Confidential Information"). You shall not

* disclose such Confidential Information and shall use it only in

* accordance with the terms of the license agreement you entered into

* with Windward Studios, Inc.

*/

 

import java.io.*;

import java.util.*;

 

import net.windward.xmlreport.*;

import net.windward.format.htm.*;

 

/** Process a xml and rtf file into a report. This is a sample program that runs a report

* from the command line. The usage is:<br>

* java net.windward.xmlreport.RunReport order.xml template.rtf report.htm<br>

* The three filenames can be anything you want. They are:<ul>

* <li>order.xml - the xml data to use for the report.</li>

* <li>template.rtf - the report template which must be a rtf file.</li>

* <li>report.htm which is the report created. This file can have an extension of rtf, htm,

* html, xhtml, pdf, sml(SpreadsheetML), xml(WordML), or txt and will create a report in the appropiate format.</li>

* </ul>

*

* @author David Thielen

* @version 1.0

*/

 

public class RunReportBeans {

 

/**

* Process a xml and rtf file into a report. This is a sample program that runs a report

* from the command line.

*

* @param args Must be three filenames like order.xml template.rtf report.htm where:<ul>

* <li>order.xml - the xml data to use for the report.</li>

* <li>template.rtf - the report template which must be a rtf file.</li>

* <li>report.htm which is the report created. This file can have an extension of rtf, htm(no css),

* html(with css), xhtml, pdf, sml(SpreadsheetML), xml(WordML), or txt and will create a report in the appropiate format.</li>

* </ul>

*/

public static void main(String[] args) {

 

ProcessReport.init();

 

if (args.length != 3) {

System.out.println("RunReportBeans xmlFile, rtfFile, outFilename");

return;

}

System.out.println("Processing xml file " + new File(args[0]).getAbsolutePath() + "\n" +

"\ttemplate file " + new File(args[1]).getAbsolutePath() + "\n" +

"\treport file " + new File(args[2]).getAbsolutePath());

File fil = null;

 

try {

 

fil = new File(args[0]);

FileInputStream xml = new FileInputStream(args[0]);

fil = new File(args[1]);

FileInputStream rtf = new FileInputStream(args[1]);

fil = new File(args[2]);

FileOutputStream out = new FileOutputStream(args[2]);

 

// pick the output type

ProcessReportAPI report;

if (args[2].endsWith(".rtf")) {

report = new ProcessRtf(xml, rtf, out);

} else if (args[2].endsWith(".pdf")) {

report = new ProcessPdf(xml, rtf, out);

} else if (args[2].endsWith(".xls")) {

report = new ProcessXls(xml, rtf, out);

report.setTitle(fil.getName());

} else if (args[2].endsWith(".sml")) {

report = new ProcessExcelML(xml, rtf, out);

report.setTitle(fil.getName());

} else if (args[2].endsWith(".xml")) {

report = new ProcessWordML(xml, rtf, out);

} else if (args[2].endsWith(".txt"))

report = new ProcessTxt(xml, rtf, out);

else if (args[2].endsWith(".htm")) {

// base html report

report = new ProcessHtml(xml, rtf, out);

((ProcessHtmlAPI) report).setCss(ProcessHtmlAPI.CSS_NO, null, null);

} else if (args[2].endsWith(".html")) {

// html 4.01 with css report

report = new ProcessHtml(xml, rtf, out);

((ProcessHtmlAPI) report).setCss(ProcessHtmlAPI.CSS_INCLUDE, null, null);

} else if (args[2].endsWith(".xhtml")) {

// xhtml

report = new ProcessHtml(xml, rtf, out);

((ProcessHtmlAPI) report).setCss(ProcessHtmlAPI.CSS_INCLUDE, null, null);

((ProcessHtmlAPI) report).setSpec(ProcessHtmlAPI.XHTML);

} else {

System.err.println("output file must end with rtf, pdf, xls, eml, xml, txt, htm, or html");

return;

}

 

// add the beans

report.addBean("RedNegative", new net.windward.bean.impl.RedNegative());

report.addBean("RunningTotal", new net.windward.bean.impl.RunningTotal());

 

report.process();

 

// images?

if (report.getReportType() == ProcessReport.TYP_HTML) {

ArrayList images = ((ProcessHtmlAPI) report).getImageNames();

for (int ind = 0; ind < images.size(); ind++) {

HtmlImage img = (HtmlImage) images.get(ind);

System.out.println(WindwardReports.getResource("report.run.image", img.getName()));

FileOutputStream file = new FileOutputStream(img.getName());

((ByteArrayOutputStream) img.getStream()).writeTo(file);

file.close();

}

}

 

xml.close();

rtf.close();

out.close();

 

System.out.println(args[2] + " built, " + Integer.toString(report.getNumPages()) + " pages long");

 

} catch (FileNotFoundException fnf) {

System.err.println("File not found: " + fil.getAbsolutePath());

fnf.printStackTrace();

} catch (Throwable t) {

System.err.println("Exception occurred: " + t.getMessage());

t.printStackTrace();

}

}

 

}

Appendix D: Using Beans when Running WR as a Server

Windward Reports has a TCP server incorporated into it. This server is accessed by clients over the network. This can include a Java client (typically running on Java 1.1 or 1.2), a .NET client (the .NET client code is included with Windward Reports), and AutoTag (which uses it to create sample reports).

The Windward Reports server is composed of two parts:

§ net.windward.xmlreport.server.ReportServer has a main function and runs the server. It responds to requests for running reports and generates the reports. This class is in WindwardReports.jar.

§ net.windward.xmlreport.server.ShutdownServer has a main function that stops the server. This class is in WindwardReports.jar. This method must be called to provide teardown for stateless beans loaded by the server.

§ The client software which is presently available for Java (1.1.8 and later) and .NET.

For additional details, refer to the System Administrator’s Guide, Windward Reports Server chapter.

Coding Examples

These following examples are located in Sample 14:

Start Server Example Batch File

java -cp "..\..\WindwardReports.jar;..\..\lib\log4j.jar;..\..\lib\dom4j.jar;..\..\lib\jaxen.jar;..\..\lib\iText.jar;..\..\lib\iTextAsian.jar;..\..\lib\commons-codec.jar;..\..\lib\poi.jar" -DWindwardReports.properties.filename=../../WindwardReports.properties -Djava.security.manager -Djava.security.policy=server.policy net.windward.xmlreport.server.ReportServer bean-props.xml

Stop Server Example Batch File

java -cp "..\..\WindwardReports.jar;..\..\lib\log4j.jar;..\..\lib\dom4j.jar;..\..\lib\iText.jar;..\..\lib\iTextAsian.jar;..\..\lib\commons-codec.jar" -DWindwardReports.properties.filename=../../WindwardReports.properties -Djava.security.manager -Djava.security.policy=server.policy net.windward.xmlreport.server.ShutdownServer

Sample Beans Properties File

<windward>

<server>

<beans>

<bean name='dave' class='net.windward.bean.impl.RedNegative'>

<parameters>

<param key='abc' value='123'/>

<param key='def' value='789'/>

</parameters>

</bean>

<bean name='shirley' class='net.windward.bean.impl.RunningTotal'/>

</beans>

</server>

</windward>

When the server is started, any beans referenced in the properties file must be in the class path so the server can load them.

  • Was this article helpful?