My Pages

Sunday, September 11, 2011

Building a Common Navigator Framework Viewer

Follow the below link for CNF Framework article.

CNF Framework article

Wednesday, June 29, 2011

CustomFile Filter for JFileChooser

class ExtensionFileFilter extends FileFilter {

private java.util.List extensions;
private String description;


public ExtensionFileFilter(String[] exts, String desc) {
if(exts != null) {
extensions = new java.util.ArrayList();

for(String ext : exts) {
extensions.add(ext.replace(".", "").trim().toLowerCase());
}
}
description = (desc != null) ? desc.trim() : "Some description";
}


@Override
public boolean accept(File f) {
if(extensions == null) return false;
if(f.isDirectory()) return true;

for(String ext : extensions) {
if(f.getName().toLowerCase().endsWith("." + ext)) return true;
}
return false;
}


@Override
public String getDescription() {
return description;
}
}

Friday, March 25, 2011

PDF Generation using Apache FOP !!!

The user can generate a pdf file using Apache FOP.(http://xmlgraphics.apache.org/fop/)
FOP (Formatting Objects Processor) is from the apache group.It is said to be the worlds first print formatter driven by XSL formatting objects (XSL-FO) and the world's first output independent formatter. Actually it isn’t a tool specifically meant for PDF conversion or creation.FOP can be downloaded here.

FOP converts the XSL files (*.fo) to PDF format.

Following is a sample for generating a pdf.

Create a Driver instance and set the necessary inputs.
Driver driver = new Driver();
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
MessageHandler.setScreenLogger(logger);

driver.setLogger(logger);
driver.setRenderer(Driver.RENDER_PDF);// Output type
driver.setInputSource(new InputSource(new java.io.StringReader(fo)));
// fo is the xsl-fo format string which is generated after transforming the xml with xsl.
driver.setOutputStream(new FileOutputStream(outputFile));
driver.run();
driver.reset();

Using the above snippet you can generate a PDF file.:-)