Hi everybody,
I am quite new to Eclipse RCP. As i got assigned to a long-term eclipse project i became a member of this forum and i hope to find support, when struggling with it (at the first glance it seems to be a quite complex issue).
Currently, i am trying to integrate a simple FOP code into Plugin and i have obviously some problems with the file access. The standalone code for generating the pdf looks like this:
Code:
File baseDir = new File(".");
File outDir = new File(baseDir, "out");
outDir.mkdirs();
File xmlfile = new File(baseDir, "input.xml");
File xsltfile = new File(baseDir, "layout.xsl");
File pdffile = new File(outDir, "ouput.pdf");
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
OutputStream out = new java.io.FileOutputStream(pdffile);
out = new java.io.BufferedOutputStream(out);
try {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
transformer.setParameter("versionParam", "2.0");
Source src = new StreamSource(xmlfile);
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
} finally {
out.close();
}
This code was working fine as a standalone java app. When integrating into an eclipse plugin the "."-notation for relative paths doesn't work anymore - apparantly instead of pointing to the project directory "." is interpreted as a path that looks like "homedirectory/."
Now i made up a solution for eclipse with setting the baseDir instance differently:
Code:
URL baseUrl = Platform.getBundle("myPlugin").getEntry("");
String base = FileLocator.toFileURL(baseUrl).getPath();
File baseDir = new File(base);
The rest of the code is untouched. It works for opening the xml, xsl and pdf, but when the fop-processor tries to resolve the <import>-tags of the xsl-file, it is not able to find the referenced xsl-files. I assume, that fop running inside a plugin using also the "."-notation and fails with that.
Does anybody know a solution to this?
Thanks for any help!
Cheers,
GLA