zkh152 / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

Calling an Objects Method via Velocity that will return an IImageProvider does not work for ODT Templates #214

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a class which contains a method that returns an IImageProvider, eg:

public class MyImageLoader {
    public IImageProvider getImage(int width, int height) {
        return ...;
    }
}

2. Create a template which contains a dynamic image. Instead of getting it as 
an object, put a method-call in velocity like
"myImageLoaderObject.getImage(640, 480)"

3. Announce the field in metadata: 
metadata.addFieldAsImage("myImageLoaderObject.getImage");

4. Add the object to the context and launch the ODT-Filling-Process.

What is the expected output? What do you see instead?
The template's image placeholder will not be replaced with the 
IImageProvider-Object from the Java-Context.

What version of the product are you using? On what operating system?
Xdocreport 1.0.0 on openjdk-7-jre-7u9-2.3.3

Please provide any additional information below.
If the method is set as dynamic image in the ODT Template, it won't run at all.
If the method is set as a normal input field, it will be run and the Object is 
returned, which can be seen as it's toString()-method's return value is shown 
in the document: 
fr.opensagres.xdocreport.document.images.ByteArrayImageProvider@1dee400
It is also possible to run it's methods.

The documentation is very unclear on how to set method calls for dynamic image 
replacement, it seems that only static access is allowed.

Original issue reported on code.google.com by heyder.r...@gmail.com on 8 Jan 2013 at 9:15

GoogleCodeExporter commented 9 years ago
Hi,

Have you played with dynamic image samples that you can find on 
"odtandvelocity-1.0.0-sample.zip" at 
http://code.google.com/p/xdocreport/downloads/list?

It seems that you wish call directly "myImageLoaderObject.getImage(640, 480)" 
instead use "myImageLoaderObject" ? Why?

If you do that, it will not work, you must write more complex velocity 
directive with  ImageRegistry (see on debug mode the velocity directive which 
is generated).

I suggest you to attach your odt+java code to understand more your need.

Regards Angelo

Original comment by angelo.z...@gmail.com on 8 Jan 2013 at 9:23

GoogleCodeExporter commented 9 years ago
Hi,
unfortunately i cannot attach my code, but I will provide you with samples 
where necessary. The idea behind all this is basically that I want to allow the 
ODT-template to pass it's requirements to Java, which itself will then create 
an image according to the requirements, putting it into an IImageProvider and 
then pushing that back to the ODT document. 

To be more precisely, I want to be able to fetch OpenStreetMap tiles with size, 
zoom and latitude/longitude from inside the ODT. 
What I could and have done as an alternative is the following: I downloaded 
multiple tiles with preset Sizes like 640x640, 640x320, 320x640 etc and put 
them into the Context. While this basically works out well, I would prefer to 
change it to a more dynamic way as this will create a huge amount of traffic 
and really increases the time that is required to process ODT templates.

I also brainstormed the following idea: I could use a velocity-method-call in 
the ODT header to set width/height, which would then start to download those 
tiles and put them in the context. But this might not work as the context 
probably needs to persist when processing has started, also, it would increase 
the difficulty for creating ODT templates.

Original comment by heyder.r...@gmail.com on 8 Jan 2013 at 9:55

GoogleCodeExporter commented 9 years ago
I'm really sorry, but it's very hard for me to understand your need.

I think if you attach a basic sample (without OpenStreetMap), but just a simple 
example, I could understand your need.

I don't understand why you cannot uses IIMageProvider to set height, with like 
explained at 
http://code.google.com/p/xdocreport/wiki/ODTReportingJavaMainDynamicImage

Original comment by angelo.z...@gmail.com on 8 Jan 2013 at 10:13

GoogleCodeExporter commented 9 years ago
Okay, I have attached a little Test Class which basically does the same that I 
am trying to achieve, although a lot more simpler. It will download some tiles 
from Google Maps.

You might want to check the stdout to see what actually has happend in terms of 
download: It will do 2 Downloads, one for the Velocity-call from the Input 
field in the top, and one for the image in the context which is placed at the 
bottom.

Original comment by heyder.r...@gmail.com on 8 Jan 2013 at 11:32

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Heyder,

Many thank's to have attached your sample.

Your first problem is that you must do that:

------------------------------------------
metadata.addFieldAsImage("myImageLoaderObject.getImage(640,320)");
------------------------------------------

and not : 

------------------------------------------
metadata.addFieldAsImage("myImageLoaderObject.getImage");
------------------------------------------

your second problem is that you must name your image in the ODT with the same 
content : 

------------------------------------------
myImageLoaderObject.getImage(640,320)
------------------------------------------

and not with 

------------------------------------------
myImageLoaderObject.getImage(640x320)
------------------------------------------

But I agree with you, it's not very easy to use, because you must declare the 
whole size in fields metadata

------------------------------------------
metadata.addFieldAsImage("myImageLoaderObject.getImage(640,320)");
metadata.addFieldAsImage("myImageLoaderObject.getImage(640,640)");
------------------------------------------

I had an idea (not only for image) to declare fields metadata with pattern. In 
your case you could write : 

------------------------------------------
metadata.addFieldAsImage("myImageLoaderObject.getImage*");
------------------------------------------

But this feature doesn't exists. I will see if it's easy to develop my idea.

If you other idea, don't hesitate to tell me.

But IMHO, I think it's bad idea to load image with ODT. I think it's better to 
prepare data and generate your report. It's the same idea as JEE Web 
Application like Struts2, Play! etc : 

 - you have a controller which load your data (for XDocReport, you populate your context).
 - once data is loaded, JSP view is called to use it and generate HTML (for XDocReport view is ODT).

This mean gives you the capability to manage error correctly and it's not the 
view which throws error (in this case it's not good because the JSP generate an 
HTML fragment and throws error).

Regards Angelo

Original comment by angelo.z...@gmail.com on 9 Jan 2013 at 8:12

GoogleCodeExporter commented 9 years ago
None answer. I close this issue.

Original comment by angelo.z...@gmail.com on 7 Aug 2014 at 9:17

GoogleCodeExporter commented 9 years ago
cleanup

Original comment by pascal.leclercq on 10 Oct 2014 at 7:37