MohamedSaeed / xdocreport

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

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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

Original issue reported on code.google.com by matteo.l...@gmail.com on 2 Sep 2013 at 9:36

Attachments:

GoogleCodeExporter commented 9 years ago
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

Original comment by angelo.z...@gmail.com on 2 Sep 2013 at 9:51

GoogleCodeExporter commented 9 years ago
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?

Original comment by matteo.l...@gmail.com on 2 Sep 2013 at 9:57

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

Original comment by angelo.z...@gmail.com on 2 Sep 2013 at 9:59

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

Original comment by matteo.l...@gmail.com on 2 Sep 2013 at 10:03

GoogleCodeExporter commented 9 years ago
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).

Original comment by angelo.z...@gmail.com on 2 Sep 2013 at 12:19

GoogleCodeExporter commented 9 years ago
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?

Original comment by matteo.l...@gmail.com on 2 Sep 2013 at 1:45

GoogleCodeExporter commented 9 years ago
> 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.

Original comment by angelo.z...@gmail.com on 2 Sep 2013 at 3:10

GoogleCodeExporter commented 9 years ago
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

Original comment by matteo.l...@gmail.com on 2 Sep 2013 at 3:58

GoogleCodeExporter commented 9 years ago
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?

Original comment by matteo.l...@gmail.com on 2 Sep 2013 at 4:03

GoogleCodeExporter commented 9 years ago
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).

Original comment by angelo.z...@gmail.com on 2 Sep 2013 at 7:08

GoogleCodeExporter commented 9 years ago
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?

Original comment by matteo.l...@gmail.com on 7 Oct 2013 at 7:08

GoogleCodeExporter commented 9 years ago
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

Original comment by angelo.z...@gmail.com on 7 Oct 2013 at 7:13

GoogleCodeExporter commented 9 years ago
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 .

Original comment by matteo.l...@gmail.com on 7 Oct 2013 at 7:31

GoogleCodeExporter commented 9 years ago
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.

Original comment by angelo.z...@gmail.com on 7 Oct 2013 at 7:54

GoogleCodeExporter commented 9 years ago
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!

Original comment by matteo.l...@gmail.com on 7 Oct 2013 at 7:55

GoogleCodeExporter commented 9 years ago
Please try with simple Freemarker template and tell me if it works with simple 
template Freemarker.

Original comment by angelo.z...@gmail.com on 7 Oct 2013 at 8:27

GoogleCodeExporter commented 9 years ago
In previous mail I sent you the simple file of simple template Freemarker
but the result is the same.

Original comment by matteo.l...@gmail.com on 7 Oct 2013 at 8:31

GoogleCodeExporter commented 9 years ago
So it's a problem with Freemarker, not with XDocReport, please post your 
question on Freemarker forum.

Thank's.

Original comment by angelo.z...@gmail.com on 7 Oct 2013 at 8:42

GoogleCodeExporter commented 9 years ago
ok thanks

Original comment by matteo.l...@gmail.com on 7 Oct 2013 at 8:43

GoogleCodeExporter commented 9 years ago
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.

Original comment by matteo.l...@gmail.com on 7 Oct 2013 at 12:15

GoogleCodeExporter commented 9 years ago
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?

Original comment by angelo.z...@gmail.com on 7 Oct 2013 at 12:39

GoogleCodeExporter commented 9 years ago
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?

Original comment by matteo.l...@gmail.com on 7 Oct 2013 at 2:06

GoogleCodeExporter commented 9 years ago
Ok read that https://code.google.com/p/xdocreport/wiki/FreemarkerTemplate

Original comment by angelo.z...@gmail.com on 7 Oct 2013 at 2:47

GoogleCodeExporter commented 9 years ago
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..

Original comment by matteo.l...@gmail.com on 8 Oct 2013 at 7:26

GoogleCodeExporter commented 9 years ago
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.ITemplateEngineIni
tializerDiscovery (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). 

Original comment by angelo.z...@gmail.com on 8 Oct 2013 at 7:35

GoogleCodeExporter commented 9 years ago

Original comment by angelo.z...@gmail.com on 18 Feb 2014 at 2:47