Issue 291 in xdocreport: xdocreport: odt/Freemarker report generator and its config file to OO plugin

252 views
Skip to first unread message

xdocr...@googlecode.com

unread,
Sep 2, 2013, 5:36:41 AM9/2/13
to xdocr...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 291 by matteo.l...@gmail.com: xdocreport: odt/Freemarker report
generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Hi guys, first I would like to pay tribute to the project! Cpongratulation.

Now I'll explain my problem :

I created the report with a java class "JreportGenerator.java", odt
template "Templatepratica.odt" and xml data file "datipratica.xml" in
attached. Everything works fine.

Now I would like to create the configuration file for Openoffice plugin.
To facilitate the configuration of the report to the operator, I wish the
file already contains the correct values to be substituted properly by
data. The operator must only include the selected items from the plugin and
they will be insert with proper syntax and with all necessary xml levels.

The only solution I've found is that you can see in the attached
file "persona.fields.xml".

Any ideas?
I have done something wrong in my analysis?
There is another best way? What?

Now I'm using version 1.0.2 of the product on AS400 server and Windows Xp/7
clients some under on Windows 2008 terminal server

Matteo



Attachments:
datipratica.xml 605 bytes
Templatepratica.odt 12.8 KB
JReportGenerator.java 12.8 KB
persona.fields.xml 628 bytes

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

xdocr...@googlecode.com

unread,
Sep 2, 2013, 5:51:44 AM9/2/13
to xdocr...@googlegroups.com
Updates:
Status: Accepted
Owner: angelo.z...@gmail.com

Comment #1 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Hi Matteo,

It's really hard for me to understand what you wish to do. It seems, that
you use fields metadata although you have not ODT Table? Perhaps you wish
to manage loop (without ODT Table), if it that you must set the start/end
lopp with #list.

If I'm wrong, please attach a simple Java main which works with your case.
Many thank's

Regards Angelo

xdocr...@googlecode.com

unread,
Sep 2, 2013, 5:57:37 AM9/2/13
to xdocr...@googlegroups.com

Comment #2 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Hi Angelo, I'm interested how to generate the file for openoffice plugin.
From what I understand I must necessarily include "doc.Practice" in front
of each element used in template.
It's correct?

xdocr...@googlecode.com

unread,
Sep 2, 2013, 5:59:38 AM9/2/13
to xdocr...@googlegroups.com

Comment #3 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

What do you mean with "openoffice plugin."? Perhaps you want update some
xml entries of your odt (some setting or other?)

xdocr...@googlecode.com

unread,
Sep 2, 2013, 6:03:59 AM9/2/13
to xdocr...@googlegroups.com

Comment #4 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

I'm talking about this macro plugin for easy report modeling:
http://code.google.com/p/xdocreport/downloads/detail?name=fr.opensagres.xdocreport.document.tools-1.0.2-distribution.zip&can=2&q=

xdocr...@googlecode.com

unread,
Sep 2, 2013, 8:19:50 AM9/2/13
to xdocr...@googlegroups.com

Comment #5 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Ok, your problem is about the OOO macro with XML fields.

Your xml data is datipratica.xml :

-----------------------------------------------
<Pratica>
<Cliente>8</Cliente>
<Protocollo NumeroProtocollo="" DataProtocollo="01.01.0001" />
<Azienda TelefonoAzienda="Tel. 123456 Cell. 215155145 Cell.">XXXXX
S.p.a.</Azienda>
<TestoUtenza>Utenza</TestoUtenza>
<IndirizzoSpedizione RagioneSociale="ZUBIANI ANNITA" Via="VIA CHIOCCIOLA
N. 18" Localita="25065 LUMEZZANE" />
<OggettoPratica>Richiesta Reclamo</OggettoPratica>
<RiferimentoPratica>Pratica 1124 Del 27.08.2013 (REC) Stampata il
27.08.2013</RiferimentoPratica>
<Qualificatore>RLReclamo</Qualificatore>
</Pratica>
-----------------------------------------------

And your XML fields are persona.fields.xml :

------------------------------------------------------------
<fields templateEngineKind="Freemarker" >
<description><![CDATA[]]></description>
<field name="doc.Patica.aziends.Nome" list="false">
</field>
<field name="doc.Pratica.persona.@Nome" list="true">
<description><![CDATA[]]></description>
</field>
<field name="doc.Pratica.persona.@Cognome" list="true">
<description><![CDATA[]]></description>
</field>
<field name="doc.Pratica.persona.@Mail" list="true">
<description><![CDATA[]]></description>
</field>
</fields>
------------------------------------------------------------

I don't understand this file. "doc.Patica.aziends.Nome" doesn't exists?

Your XML fields should be like this :

------------------------------------------------------------
<fields templateEngineKind="Freemarker" >
<description><![CDATA[]]></description>
<field name="doc.Pratica.RiferimentoPratica" list="false">
...
------------------------------------------------------------

Is not working with that that?

I think it should be cool that XDocReport should provide a Java class utils
to generate XML fields from XML file (like Pojo).

I have never tested, but preview should not working with attribute. OO
macro should perhaps accept xml data too (today, only json is suported).

xdocr...@googlecode.com

unread,
Sep 2, 2013, 9:45:51 AM9/2/13
to xdocr...@googlegroups.com

Comment #6 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Excuse you're right, I haven't fixed the xml file of the fields before you
send it. :-(
I have to define ' doc. ' in front of each item?

("doc." because is the name that I used in the java file
...
context.put( "doc", project );
....)

How come this mismatch between xml data definition file and xml fields
definition file?

The description as CDDATA[] may be used in any way to assign a description
to the xml element for a better reading in the plugin? How?

xdocr...@googlecode.com

unread,
Sep 2, 2013, 11:10:16 AM9/2/13
to xdocr...@googlegroups.com

Comment #7 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

> I have to define ' doc. ' in front of each item?
Yes it's Freemarker syntax.

> How come this mismatch between xml data definition file and xml fields
> definition file?
XML fields definition are not required (just for lazy loop table and for OO
macro if you wish to use it). For Pojo, this xml fields can be generated
from Pojo with FieldsMetadata class (see
https://code.google.com/p/xdocreport/wiki/ODTReportingQuickStart)

Perhaps it could be interesting to do that for XML data too?

> The description as CDDATA[] may be used in any way to assign a description
> to the xml element for a better reading in the plugin? How?
I don't remember if the XDocRepport OO macro use this description field? I
know for MS Word (docx) it works not sure with the OO macro.

xdocr...@googlecode.com

unread,
Sep 2, 2013, 11:59:13 AM9/2/13
to xdocr...@googlegroups.com

Comment #8 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Ok so I must define doc in java file and in first level in xml field like
doc.Pratica.RiferimentoPratica?
I must define doc. in first level into xml field definition? This file do I
need for a quick and easy creation of template...
But whit this syntax the list function don't wotk because write [#list doc
as d]${d.Pratica.RiferimentoPratica}[/#list] then don't work!

How come this mismatch between xml data definition file and xml fields

XML fields definition are not required (just for lazy loop table and for OO

Ok for me this isn't important but It would have been convenient

xdocr...@googlecode.com

unread,
Sep 2, 2013, 12:03:13 PM9/2/13
to xdocr...@googlegroups.com

Comment #9 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

So the correct way for me is:
- Java file: define context.put( "doc", project )
- xml data file: define root element <Pratica>
- xml field definition for plugin: use syntax
${doc.Pratica.RiferimentoPratica}
It's ok?

xdocr...@googlecode.com

unread,
Sep 2, 2013, 3:09:00 PM9/2/13
to xdocr...@googlegroups.com

Comment #10 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Yes it that. If you wish to use XML as data source, you must use "doc"
prefix. I agree with you, it's not a simply syntax. Pojo as data is more
simply for the syntax. I have an idea here
https://code.google.com/p/xdocreport/issues/detail?id=41 to simplify the
syntax, but no time for the moment to implement it.

To manage list with xml doc, please read FM doc at
http://freemarker.org/docs/xgui_imperative_learn.html (except that syntax
you must to use is [#list and not <#list).

xdocr...@googlecode.com

unread,
Oct 7, 2013, 3:08:36 AM10/7/13
to xdocr...@googlegroups.com

Comment #11 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Hi Angel I still have a little problem.
I export in xml data file in the <conditions> tag some of his attributes
according to a certain calculation logic from the program.
------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<pratica>
...
<condizioni stampaContrattoDomesticiFix="S"></condizioni>
</pratica>
----------------------------------------------------------------------------------
In the template prints some sections depends on the presence of the
attribute in the <condizioni> tag and I test it with the directive #IF.
In the template using the following syntax (at that time I don't mind the
value that the attribute but I am interested if there is or not):
[#if (doc.pratica.condizioni.@stampaContrattoDomesticiFix)??] testo [/if]
Unfortunately this option does not work!
The only way I have is to test the value of the
@stampaContrattoDomesticiFix attribute if's =="S" or not but it's not the
way I would go.
Could you tell me how to risolvre?

xdocr...@googlecode.com

unread,
Oct 7, 2013, 3:13:47 AM10/7/13
to xdocr...@googlegroups.com

Comment #12 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Hi Matteo,

> Unfortunately this option does not work!
What do you mean with "does not work"?
More it should be [/#if] and not [if]

Regards Angelo

xdocr...@googlecode.com

unread,
Oct 7, 2013, 3:31:32 AM10/7/13
to xdocr...@googlegroups.com

Comment #13 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Yes it in fact is correct [/#if], sorry made a mistake typing.
Does not work because it does not evaluate the absence of the attribute.
If I writing:
[if(doc.pratica.condizioni.@stampaContrattoDomesticiFix)??] text A [else]
text B [/#if]
and in the xml data file there is no stampaContrattoDomesticiFix attribut,
the program always prints the text A!
I don't know how to test for the presence of the attribute and print the
text to him associated with .

xdocr...@googlecode.com

unread,
Oct 7, 2013, 3:54:36 AM10/7/13
to xdocr...@googlegroups.com

Comment #14 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

I suggest you to write a simple template Freemarker at hand with your case
to test if it works and post to Freemarker forum that you wish to do.

If it works with your simple Freemarker template and doesn't work with
XDocReport, I will see XDocReport.

xdocr...@googlecode.com

unread,
Oct 7, 2013, 3:55:36 AM10/7/13
to xdocr...@googlegroups.com

Comment #15 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

In this case, as you can see from the attached files, the program always
prints the text A even if the attribute does not exist in the xml data
file!

xdocr...@googlecode.com

unread,
Oct 7, 2013, 4:28:10 AM10/7/13
to xdocr...@googlegroups.com

Comment #16 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Please try with simple Freemarker template and tell me if it works with
simple template Freemarker.

xdocr...@googlecode.com

unread,
Oct 7, 2013, 4:32:01 AM10/7/13
to xdocr...@googlegroups.com

Comment #17 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

In previous mail I sent you the simple file of simple template Freemarker
but the result is the same.

xdocr...@googlecode.com

unread,
Oct 7, 2013, 4:42:33 AM10/7/13
to xdocr...@googlegroups.com

Comment #18 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

So it's a problem with Freemarker, not with XDocReport, please post your
question on Freemarker forum.

Thank's.

xdocr...@googlecode.com

unread,
Oct 7, 2013, 4:43:33 AM10/7/13
to xdocr...@googlegroups.com

Comment #19 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

ok thanks

xdocr...@googlecode.com

unread,
Oct 7, 2013, 8:15:57 AM10/7/13
to xdocr...@googlegroups.com

Comment #20 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Angelo excuse me for another two little questions.
1- when i try to print one field that does not exist in the xml data file
the freemarker.core generates an NonStringException error. Would it be
possible to somehow retrieve the name of the field that caused the
exception? Otherwise how can I understand it?
2- would it be possible to include a tooltip in the list of fields (on
mouse over filed) in the pluging OpenOffice? It would be very convenient
and complete
Regards.

xdocr...@googlecode.com

unread,
Oct 7, 2013, 8:39:13 AM10/7/13
to xdocr...@googlegroups.com

Comment #21 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

I suggest you to read Freemarker manual, it is very well done. For null
value in Freemarker, I suggets you that you read
http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_missing
and http://freemarker.org/docs/pgui_config_errorhandling.html

To configure Freemarker Configuration, I think you will have to use
ITemplateEngineInitializerDiscovery like explained for configure Velocity
logging at https://code.google.com/p/xdocreport/issues/detail?id=68#c2

> 2- would it be possible to include a tooltip in the list of fields (on
> mouse over filed)
any contribution are welcome for that.

But it seems that you use XML as data context (and not Pojo), it means that
you create at hand the XML fields files? Perhaps it should be better to
have a serializer (like Pojo) to generate this XML fields file from XML
file?

xdocr...@googlecode.com

unread,
Oct 7, 2013, 10:06:52 AM10/7/13
to xdocr...@googlegroups.com

Comment #22 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

ok, i create the class MyTemplateExceptionHandler implements
TemplateExceptionHandler in my project but I don't understand how to use it.

class MyTemplateExceptionHandler implements TemplateExceptionHandler {
public void handleTemplateException(TemplateException te, Environment
env, java.io.Writer out)
throws TemplateException {
try {
out.write("[ERROR: " + te.getMessage() + "]");
} catch (IOException e) {
throw new TemplateException("Failed to print error message.
Cause: " + e, env);
}
}
}

First I had only one java class that process template:

private final static String genera_Report (String nome_Template, String
nome_FileDatiXml, String numero_Richiesta) throws Exception {

String result3 = "Errore";
String nomeFileGenerato = "";

try{
// 1) Carica il file modello .odt by filling Freemarker
template engine and cache
// it to the registry
IXDocReport report = null;
OutputStream out = null;

try{

File file = new File("modelli/"+nome_Template);

FileInputStream fi = new
FileInputStream(file.getAbsolutePath());
report = XDocReportRegistry.getRegistry().loadReport( fi,
TemplateEngineKind.Freemarker );

}catch(FileNotFoundException e){
//File template non trovato
result3 = String.format("Errore generazione report: %s",
e.getMessage());
return result3;
}

// 2) Crea context Java model
IContext context = report.createContext();
try{
FileInputStream projectInputStream = null;
projectInputStream = new
FileInputStream("dati/"+nome_FileDatiXml.toLowerCase()+".xml");
InputSource projectInputSource = new
InputSource(projectInputStream);
freemarker.ext.dom.NodeModel project =
freemarker.ext.dom.NodeModel.parse( projectInputSource );
context.put( "doc", project );
}catch(FileNotFoundException e){
//File dati xml non trovato
result3 = String.format("Errore generazione report: %s",
e.getMessage());
return result3;
}

try{
// 3) Genera il report elaborato
nomeFileGenerato =
String.format("%s%s%s%s","report/",numero_Richiesta,nome_Template,"_out.odt");
out = new FileOutputStream(new File(nomeFileGenerato));

}catch(Exception e){
result3 = String.format("Errore generazione report:
FileOutputstream %s", e.getMessage());
return result3;
}

try{
report.process( context, out );
}catch(Exception e){
result3 = String.format("Errore generazione report:
processa report %s", e.getMessage());
return result3;
}

}catch ( IOException e ) {
result3 = String.format("Errore generazione report: %s",
e.getMessage());
return result3;
}catch ( XDocReportException e ) {
result3 = String.format("Errore generazione report: %s",
e.getMessage());
return result3;
}catch ( SAXException e ) {
result3 = String.format("Errore generazione report: %s",
e.getMessage());
return result3;
}catch ( ParserConfigurationException e ) {
result3 = String.format("Errore generazione report: %s",
e.getMessage());
return result3;
}catch(Exception e){
result3 = String.format("Errore generazione report: %s",
e.getMessage());
return result3;
}

//Tutto ok
File f = new File(nomeFileGenerato);
result3 = String.format("Report generato correttamente: [%s]",
f.getAbsolutePath().toString().trim());
return result3;

}

How work with new class for intercept a frequent error is when a template
refers to a variable which is not existing?

xdocr...@googlecode.com

unread,
Oct 7, 2013, 10:48:02 AM10/7/13
to xdocr...@googlegroups.com

Comment #23 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Ok read that https://code.google.com/p/xdocreport/wiki/FreemarkerTemplate

xdocr...@googlecode.com

unread,
Oct 8, 2013, 3:26:29 AM10/8/13
to xdocr...@googlegroups.com

Comment #24 on issue 291 by matteo.l...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

Hi Angelo excuse for my emails but in my project i don't have
META-INF/service folder and i don't know to create it.
I create public class JReportConfiguration that implements
ITemplateEngineInitializerDiscovery in same project but i don't understant
to connect this with my report generator class and How do I catch the error
of null value and export into string out of my class..

xdocr...@googlecode.com

unread,
Oct 8, 2013, 3:35:34 AM10/8/13
to xdocr...@googlegroups.com

Comment #25 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

As I have explained at
https://code.google.com/p/xdocreport/wiki/FreemarkerTemplate
you must create at hand in your project the
META-INF/services/fr.opensagres.xdocreport.document.discovery.ITemplateEngineInitializerDiscovery
(in the src folder for instance if you use Eclipse project).

This file should contains the name of your class (in your case
yourpackage.JReportConfiguration).

xdocr...@googlecode.com

unread,
Feb 18, 2014, 9:47:46 AM2/18/14
to xdocr...@googlegroups.com
Updates:
Status: Fixed

Comment #26 on issue 291 by angelo.z...@gmail.com: xdocreport:
odt/Freemarker report generator and its config file to OO plugin
http://code.google.com/p/xdocreport/issues/detail?id=291

(No comment was entered for this change.)
Reply all
Reply to author
Forward
0 new messages