DZone Forums
Go Back   DZone Forums > Community > Tools & IDEs > Eclipse
Reload this Page Quite new to Eclipse and confused when integrating FOP with Eclipse Plugin
Notices
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: May 2009
Question Quite new to Eclipse and confused when integrating FOP with Eclipse Plugin - 05-12-2009, 03:48 AM

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
Reply With Quote
  (#2 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: May 2009
Default 05-12-2009, 07:56 AM

I got it running with explicitly setting a base URL for FOP's user agent:

Code:
 
foUserAgent.setBaseURL(baseDir.getPath());
Still i would appreciate it, if somebody has some background information about this behaviour.

Cheers,

GLA
Reply With Quote
Reply

Tags
eclipse rcp, file path, fop, xsl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to sign in - Confused!! julia1 Feedback 5 03-19-2009 07:00 AM
new plugin for Eclipse slover Eclipse 0 01-24-2009 03:31 AM
Integrating GMF editor with a custom Eclipse Forms editor llednicki Eclipse 0 12-21-2008 03:43 AM
runing plugin writen in eclipse 3.3 under eclipse 3.2 eladfein@yahoo.com Eclipse 0 07-27-2008 02:37 AM
eclipse plugin baltazar Eclipse 0 03-11-2008 11:48 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com