StimVinsh / xdocreport

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

Check template variables #21

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,
before merging document ,I need to check that the template contains all 
varaiables passed in the java model context.
if ok : merge.
if not :throw exception.

it's possible ?

Original issue reported on code.google.com by berchane...@gmail.com on 20 Jul 2011 at 10:20

GoogleCodeExporter commented 8 years ago
Hi, 

In the WEB Application demo when you are uploading odt, docx, it displays you 
the fields that you have defined in the template (it works with simple case, 
not tested with complex case like if condition....). Please see code at 
https://xdocreport.googlecode.com/svn/trunk/xdocreport-webapp/src/main/java/fr/o
pensagres/xdocreport/webapp/LoadXDocReportServlet.java (doLoad method).

After loding the IXDocReport you can use IXDocReport 
#extractFields(FieldsExtractor extractor) like this : 

-------------------------------------
IXDocReport report = ...
FieldsExtractor<FieldExtractor> extractor = new 
FieldsExtractor<FieldExtractor>();
report.extractFields(extractor);
-------------------------------------

You can use after FieldsExtractor#getFields() to loop for FieldExtractor and 
check if IContext contains the key : 

-------------------------------------
IContext context = report.createContext();
// Populate context

// Check if fields exists
List<FieldExtractor> fields = extractor.getFields()
for(FieldExtractor field : fields) {
   Strint fieldName =  field.getName();
   if (context .get(fieldName)) {
     throw YourException();
   }
}
-------------------------------------

Hope this code will help you.

Regards Angelo

Original comment by angelo.z...@gmail.com on 20 Jul 2011 at 11:33

GoogleCodeExporter commented 8 years ago

Original comment by angelo.z...@gmail.com on 20 Jul 2011 at 11:33

GoogleCodeExporter commented 8 years ago

Original comment by angelo.z...@gmail.com on 19 Jan 2012 at 11:50