Kogie / xdocreport

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

Using Fremarker in servlet #210

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. implement 
fr.opensagres.xdocreport.document.web.AbstractProcessXDocReportServlet with 2 
methods like it described 
http://code.google.com/p/xdocreport/wiki/DocxReportingWEBApplicationServlet but 
I want to use Fremarker template engine

What is the expected output? What do you see instead?
Null template engine. Set template engine with IXDocReport#setTemplateEngine.
fr.opensagres.xdocreport.core.XDocReportException: Null template engine. Set 
template engine with IXDocReport#setTemplateEngine.
    at fr.opensagres.xdocreport.document.AbstractXDocReport.internalGetTemplateEngine(AbstractXDocReport.java:863)
    at fr.opensagres.xdocreport.document.AbstractXDocReport.createContext(AbstractXDocReport.java:459)
    at fr.opensagres.xdocreport.document.web.AbstractProcessXDocReportServlet.doProcessReport(AbstractProcessXDocReportServlet.java:274)
    at fr.opensagres.xdocreport.document.web.AbstractProcessXDocReportServlet.doGenerateReport(AbstractProcessXDocReportServlet.java:241)
    at fr.opensagres.xdocreport.document.web.AbstractProcessXDocReportServlet.processRequest(AbstractProcessXDocReportServlet.java:110)
    at fr.opensagres.xdocreport.document.web.BaseXDocReportServlet.doGet(BaseXDocReportServlet.java:78)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
...

What version of the product are you using? On what operating system?
- latest
- win7

Please provide any additional information below.
I've read "Issue 54" and leave in classpath only 
- fr.opensagres.xdocreport.template.freemarker-1.0.0.jar
- freemarker-2.3.19.jar
But the error still appears.
How to set Fremarker template engine?

Original issue reported on code.google.com by MrSo...@gmail.com on 25 Dec 2012 at 10:36

GoogleCodeExporter commented 9 years ago
Hi,

In the web demo template engine kind is  setted in the request. I tell me if 
default template engine works always?

---------------------------------------------
TemplateEngineRegistry.getRegistry().getDefaultTemplateEngine();
---------------------------------------------

returns perhaps null  and it's your problem. This code is used 
in the getTemplateEngine( HttpServletRequest request ) of 
http://code.google.com/p/xdocreport/source/browse/document/fr.opensagres.xdocrep
ort.document/src/main/java/fr/opensagres/xdocreport/document/web/BaseXDocReportS
ervlet.java

---------------------------------------------------------------------------
@Override
 protected ITemplateEngine getTemplateEngine( HttpServletRequest request )
    {
        String templateEngineId = getTemplateEngineId( request );
        if ( StringUtils.isNotEmpty( templateEngineId ) )
        {
            return TemplateEngineInitializerRegistry.getRegistry().getTemplateEngine( templateEngineId );
        }
        return TemplateEngineRegistry.getRegistry().getDefaultTemplateEngine();
    }
---------------------------------------------------------------------------

So I suggest you to force template engine kind in your servlet like this :

---------------------------------------------------------------------------
@Override
protected String getTemplateEngineKind( HttpServletRequest request )
  return TemplateEngineKind.Freemarker.name();
}
---------------------------------------------------------------------------

Regards Angelo

Original comment by angelo.z...@gmail.com on 25 Dec 2012 at 11:36

GoogleCodeExporter commented 9 years ago
-----------
TemplateEngineRegistry.getRegistry().getDefaultTemplateEngine();
-----------
returns 'null'
What I did wrong to get this problem? Why it returns null?

Original comment by MrSo...@gmail.com on 25 Dec 2012 at 12:14

GoogleCodeExporter commented 9 years ago
Sorry i was wrong. 'null' was returned when there was no parameters in GET, but 
when I type parameters, servlet give me docx output. Now How can I convert it 
to pdf. I didn't found it for servlets.

Original comment by MrSo...@gmail.com on 25 Dec 2012 at 12:41

GoogleCodeExporter commented 9 years ago
---------------
@Override
protected String getTemplateEngineKind( HttpServletRequest request )
  return TemplateEngineKind.Freemarker.name();
}
--------------
This helped to override template, thx.
But now I'm wondering about pdf converting.

Original comment by MrSo...@gmail.com on 25 Dec 2012 at 12:44

GoogleCodeExporter commented 9 years ago
Sorry I already found PDF converting parameters for servlet, now I have to find 
method to parse template and read source of all input tags.

Original comment by MrSo...@gmail.com on 25 Dec 2012 at 12:53

GoogleCodeExporter commented 9 years ago
-----------
TemplateEngineRegistry.getRegistry().getDefaultTemplateEngine();
-----------
>returns 'null'
>What I did wrong to get this problem? Why it returns null?
Nothing, this smethod should be removed, I think.

> Sorry I already found PDF converting parameters for servlet, now I have to 
find >method to parse template and read source of all input tags.
I don't understand. Can you convert your report to PDF?

What do you mean with parse template and read source of all input tags?
Extract fields name of your docx? If it's that, see FieldsExtractor.

Regards Angelo

Original comment by angelo.z...@gmail.com on 25 Dec 2012 at 2:45

GoogleCodeExporter commented 9 years ago
1. I can convert report to PDF.
2. Yes, I think FieldsExtractor will help me to know all fields names
I read Issue 91 about usage.
Is this working for Freemarker?

    final public static Collection<String> getFields(IXDocReport report) throws XDocReportExcep
tion{
        Collection<String> names = new TreeSet<String>();
        FieldsExtractor<FieldExtractor> extractor = new FieldsExtractor<FieldExtractor>();
        report.extractFields(extractor);
        List<FieldExtractor> fields = extractor.getFields();
        for(FieldExtractor field : fields) names.add(field.getName());
        return names;
    }

Original comment by MrSo...@gmail.com on 25 Dec 2012 at 6:48

GoogleCodeExporter commented 9 years ago
Yes it's working for Freemarker, but it manages basic cases. FieldsExtractor 
exists but I think it's a bad idea to use it. I think you must define fields 
(with FieldsMetadata) and create report and not create report to define fields 
(FieldsExtractor).

But perhaps you wish manage a web application with generic report like our demo 
at http://xdocreport.opensagres.cloudbees.net/

So I suggest you to study (to see the parameter used to generete, convert 
report at http://xdocreport.opensagres.cloudbees.net/processReport.jsp

When you load report at 
http://xdocreport.opensagres.cloudbees.net/loadReport.jsp, it uses 
FieldsExtractor, so you can study how it's used.

Source of this webapp are on Git at 
http://code.google.com/p/xdocreport/source/browse/?repo=samples#git%2Fdemo-webap
p

Good luck.

Regards Angelo

Original comment by angelo.z...@gmail.com on 25 Dec 2012 at 7:14

GoogleCodeExporter commented 9 years ago
Looks like FieldsExtractor can't help me with file "полис 
(шаблон).docx" (remove it from server plz, some problems with encoding). 
It didn't extract any files at all =(

Original comment by MrSo...@gmail.com on 26 Dec 2012 at 6:53

GoogleCodeExporter commented 9 years ago
"It didn't extract any fields at all"*

Original comment by MrSo...@gmail.com on 26 Dec 2012 at 7:02

GoogleCodeExporter commented 9 years ago
Sorry I don't understand your problem.
I suggest you to ssee sources of the webapp demo to see how to use 
FieldsExtractor.
But as I told you, I think it's bad idea to use it.

Regards Angelo

Original comment by angelo.z...@gmail.com on 26 Dec 2012 at 11:53

GoogleCodeExporter commented 9 years ago
1) please delete file "полис (шаблон).docx" from test server, it 
shows on the bottom of "Choose a report" 
http://xdocreport.opensagres.cloudbees.net/processReport.jsp
I uploaded it, but now can't delete because of problems with encoding.
2) I used http://xdocreport.opensagres.cloudbees.net/loadReport.jsp to load 
report above and FieldsExtractor didn't find any fields. This means that it 
can't help to solve my problem.
3) Can you give me the source of this FieldsExtractor class, maybe I'll 
understand how to extract fields from reports.

Original comment by MrSo...@gmail.com on 26 Dec 2012 at 1:59

GoogleCodeExporter commented 9 years ago
For 1) you can do yourself at 
http://xdocreport.opensagres.cloudbees.net/admin.jsp (click on remove link of 
your report).

2) Perhaps you have complex fields. The basic idea is that your field starts 
with $

3) see extractFields at 
http://code.google.com/p/xdocreport/source/browse/template/fr.opensagres.xdocrep
ort.template.freemarker/src/main/java/fr/opensagres/xdocreport/template/freemark
er/FreemarkerTemplateEngine.java

see Junit at 
http://code.google.com/p/xdocreport/source/browse/template/fr.opensagres.xdocrep
ort.template.freemarker/src/test/java/fr/opensagres/xdocreport/template/freemark
er/FreemarkerTemplateEngineExtractVariablesTestCase.java

Regards Angelo

Original comment by angelo.z...@gmail.com on 26 Dec 2012 at 3:29

GoogleCodeExporter commented 9 years ago
1) no, I can't do it by myself because of _encoding problems_. It displays like 
"????? (??????).docx" and remove not working =(
2) Fields created by MS Word in my report, and I can't change it, because I 
have to use this templates anyway. So I guess I have to make my own parser.

Original comment by MrSo...@gmail.com on 26 Dec 2012 at 5:45

GoogleCodeExporter commented 9 years ago
Ok,

For 1) I have restarted the webapp, your docx is removed. It's a bug with demo 
webapp, but as it's a demo, it's not urgent, I will see that when I will have 
time.

for 2), plase attach your docx.

Regards Angelo

Original comment by angelo.z...@gmail.com on 26 Dec 2012 at 6:46

GoogleCodeExporter commented 9 years ago
1) Thanks
2) Looks like I have other syntax of Fields: { MACROBUTTON ##611100825271## 
Name } and I have to extract this number 611100825271

Original comment by MrSo...@gmail.com on 27 Dec 2012 at 7:05

GoogleCodeExporter commented 9 years ago
I close this bug, because your current problem is not aboutFreemarker+Servlet.

If you have some problem, please create a new isuse by explaining more your 
problem and attach your docx.

Thank's

Regards Angelo

Original comment by angelo.z...@gmail.com on 27 Dec 2012 at 9:51