public class DocxTemplateGenerator extends AbstractTemplateGenerator
| Modifier and Type | Field and Description |
|---|---|
static String |
CLOSE_PLACEHOLDER |
static String |
OPEN_PLACEHOLDER |
protected boolean |
showTemplate |
createLabelsInTemplate, dateFormat, DEBUG, numberFormat| Constructor and Description |
|---|
DocxTemplateGenerator() |
| Modifier and Type | Method and Description |
|---|---|
protected static void |
addBorders(org.docx4j.wml.Tbl table)
Add single borders to the table.
|
protected static void |
addTableCell(org.docx4j.wml.Tr tableRow,
String content,
org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocument)
Add content to a cell, and then add it to the row
|
protected static Vector<String> |
createFieldString(Hashtable fieldHashtable)
Build a Vector of single
String with all of the fields data in the
Hahstable fieldHashtable. |
protected static Vector<org.docx4j.wml.Tbl> |
createImagesField(Hashtable valuesImages,
org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocument)
Return a
Vector of Tbl to store the image placeholder |
protected static org.docx4j.wml.Tbl |
createSingleTable(String tableObjectKey,
Hashtable valuesSingleTable,
org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocument)
Create a single table with two rows.
|
protected static Vector<org.docx4j.wml.Tbl> |
createTablesObject(Hashtable valuesTable,
org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocument)
Create a Vector of single
Tbl table, which the data stored in
valuesTable. |
File |
createTemplate(Hashtable fieldValues,
Hashtable valuesTable,
Hashtable valuesImages)
The
DocxTemplateGenerator adds the possibility to put the fields
in the template in a specified order. |
protected static String |
entityAsPlaceholder(String entity)
Return the entity name of a table as placeholder
|
File |
fillDocument(InputStream input,
String nameFile,
Hashtable fieldValues,
Hashtable valuesTable,
Hashtable valuesImages,
Hashtable valuesPivotTable)
Populate the templates with the information given in the
Hashtables. |
protected static void |
findAndReplaceDocument(File templateFilled,
Hashtable fieldValues,
Hashtable valuesTable,
Hashtable valuesImages,
Hashtable valuesPivotTable)
Find and replace the placeholders of the template with the data given in
the
Hashtable |
static void |
findAndReplaceFields(org.docx4j.openpackaging.packages.WordprocessingMLPackage doc,
Hashtable fieldValues)
Find and replace the placeholder of an field in template.
|
protected static void |
findAndReplaceImages(org.docx4j.openpackaging.packages.WordprocessingMLPackage mlp,
Hashtable valuesImages)
Find and replace the placeholder of an image in template.
|
protected static void |
findAndReplaceTables(org.docx4j.openpackaging.packages.WordprocessingMLPackage mlp,
Hashtable valuesTable)
Find and replace the tables in template which have reference an entity.
|
protected static void |
generateDocxTemplate(File template,
Hashtable fieldValues,
Hashtable valuesTable,
Hashtable valuesImages)
Create a *.docx document template
|
static List<Object> |
getElements(Object obj,
Class<?> classFinder)
Get a
List of elements of the class specified by classFinder,
inside the obj. |
protected static org.docx4j.dml.wordprocessingDrawing.Inline |
inlineImage(byte[] ba,
org.docx4j.openpackaging.packages.WordprocessingMLPackage mlp,
String filenameHint)
Creates an
Inline image. |
protected static org.docx4j.wml.P |
paragraphContentImage(org.docx4j.dml.wordprocessingDrawing.Inline createInlineImage)
Create a
P with the Inline image received by parameter. |
protected static void |
populateTbl(org.docx4j.wml.Tbl entityTables,
EntityResult actualValues,
int indexRowEntityPlaceholder,
org.docx4j.openpackaging.packages.WordprocessingMLPackage mlp)
Populate the table which references a
Table in the Ontimize form. |
List |
queryTemplateFields(File template)
Creates a list with all data fields included in the template
|
List |
queryTemplateFields(String template)
Creates a list with all data fields included in the template
|
void |
setShowTemplate(boolean show)
Set if the template will be open after its creation
|
protected Hashtable |
translateDotFields(Hashtable values)
Change dot character "." on keys with "ç" character
|
static Hashtable |
translateToPatternFields(Hashtable values)
Change the form attributes keys for placeholder keys pattern
|
calculateRecordCount, containsHashtableValue, createFileFieldData, createImageDataFile, createTableDataDefinition, createTableDataDefinition, createTableDataFile, createTableDataFile, exportFieldData, exportFieldData, exportTableData, fillDocument, fillDocument, fillDocument, getKeysOrder, getScreenPoints, parseNumber, savePngImageFile, setCreateLabelsInTemplate, setDateFormat, setNumberFormat, transformFieldData, transformFieldDatapublic static final String OPEN_PLACEHOLDER
public static final String CLOSE_PLACEHOLDER
protected boolean showTemplate
public File fillDocument(InputStream input, String nameFile, Hashtable fieldValues, Hashtable valuesTable, Hashtable valuesImages, Hashtable valuesPivotTable) throws Exception
Hashtables.input - : An InputStream from the original template, which
will remain. unalterednameFile - : The name of the new *.docx document, with extension
included.fieldValues - : A Hashtable with the data used in the fields of the
form. As key, the attribute to replace and as value, their
replace.valuesTable - : A Hashtable with the data used in the tables of the
form. As key, the entity name of the table, as value, the
EntityResult will all table data.valuesImages - : A Hashtable with the images in the form. As key, the
attribute to replace and as value, their image replace (like a
BytesBlock or a BufferedImage)valuesPivotTable - : A Hashtable of pivots table (NOT USED)Exceptionprotected static void findAndReplaceDocument(File templateFilled, Hashtable fieldValues, Hashtable valuesTable, Hashtable valuesImages, Hashtable valuesPivotTable) throws Exception
HashtabletemplateFilled - : The File of template to fill.fieldValues - : A Hashtable with the data used in the fields of the
form. As key, the placeholder to replace and as value, their
replace.valuesTable - : A Hashtable with the data used in the tables of the
form. As key, the entity name of the table, as value, the
EntityResult will all table data.valuesImages - : A Hashtable with the images in the form. As key, the
placeholder to replace and as value, their image replace (like
a BytesBlock or a BufferedImage)valuesPivotTable - : A Hashtable of pivots table (NOT USED)Exceptionprotected static void findAndReplaceTables(org.docx4j.openpackaging.packages.WordprocessingMLPackage mlp,
Hashtable valuesTable)
mlp - : The WordprocessingMLPackage obtained from load the
template file.valuesTable - : A Hashtable with the data used in the tables of the
form. As key, the entity name of the table, as value, the
EntityResult will all table data.protected static void populateTbl(org.docx4j.wml.Tbl entityTables,
EntityResult actualValues,
int indexRowEntityPlaceholder,
org.docx4j.openpackaging.packages.WordprocessingMLPackage mlp)
Table in the Ontimize form.entityTables - : The Tbl WITHOUT the row that indicates its entity.actualValues - : The EntityResult of table data.indexRowEntityPlaceholder - : The index of row entity placeholder BEFORE its removalmlp - : The WordprocessingMLPackage obtained from load the
template file.protected static String entityAsPlaceholder(String entity)
entity - : The entity name Stringprotected static void findAndReplaceImages(org.docx4j.openpackaging.packages.WordprocessingMLPackage mlp,
Hashtable valuesImages)
throws Exception
mlp - : The WordprocessingMLPackage obtained from load the
template file.valuesTable - : A Hashtable with the images in the form. As key, the
placeholder to replace and as value, their image replace (like
a BytesBlock or a BufferedImage)Exceptionprotected static org.docx4j.wml.P paragraphContentImage(org.docx4j.dml.wordprocessingDrawing.Inline createInlineImage)
P with the Inline image received by parameter.createInlineImage - : An Inline image to be sorrounded with a PP paragraph with the imageprotected static org.docx4j.dml.wordprocessingDrawing.Inline inlineImage(byte[] ba,
org.docx4j.openpackaging.packages.WordprocessingMLPackage mlp,
String filenameHint)
throws Exception
Inline image.public static List<Object> getElements(Object obj, Class<?> classFinder)
List of elements of the class specified by classFinder,
inside the obj.public static void findAndReplaceFields(org.docx4j.openpackaging.packages.WordprocessingMLPackage doc,
Hashtable fieldValues)
doc - : The WordprocessingMLPackage obtained from load the
template file.fieldValues - : A Hashtable with the images in the form. As key, the
placeholder to replace and as value, their replace.public void setShowTemplate(boolean show)
show - Boolean that indicates if the template will be open after its
creation or not.public File createTemplate(Hashtable fieldValues, Hashtable valuesTable, Hashtable valuesImages) throws Exception
DocxTemplateGenerator adds the possibility to put the fields
in the template in a specified order.fieldValues can be a EntityResult
object, and use the EntityResult.setColumnOrder(List) method to
specified the order of the fields in the template.fieldValues - : This object contains the data fields attributes and labels
to show in the templatevaluesTable - : The object contains the table information to insert in the
template. This map must have the table entity name as key and
the value must be other Hashtable with the columns attributes
and names to show (column name - column label)valuesImages - : The object contains information about the image fields which
owns the form. This map contains the name of the image field
(value) and its attribute (key)Exceptionpublic List queryTemplateFields(File template) throws Exception
TemplateGeneratortemplate - Template to queryExceptionpublic List queryTemplateFields(String template) throws Exception
TemplateGeneratortemplate - Template to queryExceptionprotected Hashtable translateDotFields(Hashtable values)
values - : Original Hashtablepublic static Hashtable translateToPatternFields(Hashtable values)
values - protected static void generateDocxTemplate(File template, Hashtable fieldValues, Hashtable valuesTable, Hashtable valuesImages) throws Exception
template - The file templatefieldValues - This object contains the data fields attributes and labels to
show in the templatevaluesTable - The object contains the table information to insert in the
template. This map must have the table entity name as key and
the value must be other Hashtable with the columns attributes
and names to show (column name - column label)valuesImages - The object contains information about the image fields which
owns the form. This map contains the name of the image field
(value) and its attribute (key)Exceptionprotected static Vector<org.docx4j.wml.Tbl> createImagesField(Hashtable valuesImages, org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocument)
Vector of Tbl to store the image placeholdervaluesImages - : A Hashtable with the images in the form. As key, the
placeholder to replace and as value, their image replace (like
a BytesBlock or a BufferedImage)mainDocument - : A MainDocumentPart of the template file.Vector of Tbl which contents the placeholder of
the image.protected static Vector<String> createFieldString(Hashtable fieldHashtable)
String with all of the fields data in the
Hahstable fieldHashtable. This map stored the label of the
field as value and the attribute of the field as
keyfieldHashtable - : The field value dataString with all of the field data stored in
the fieldHashtableprotected static org.docx4j.wml.Tbl createSingleTable(String tableObjectKey, Hashtable valuesSingleTable, org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocument)
tableObjectKey - valuesSingleTable - : A hashtable which has the name of the columns ad its
respective attributes.mainDocument - : The MainDocumentPart of the template, where the
table will be in.valuesSingleTable dataprotected static Vector<org.docx4j.wml.Tbl> createTablesObject(Hashtable valuesTable, org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocument)
Tbl table, which the data stored in
valuesTable. See
#createSingleTable(Hashtable, MainDocumentPart)valuesTable - : The object contains the table information to insert in the
template. This map must have the table entity name as key and
the value must be other Hashtable with the columns attributes
and names to show (column name - column label)mainDocument - : The MainDocumentPart of the template, where the
table will be in.Tbl tables.protected static void addTableCell(org.docx4j.wml.Tr tableRow,
String content,
org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart mainDocument)
tableRow - The table row where the cell will be addedcontent - The content of the cellmainDocument - : The MainDocumentPart of the template, where the cell
will be in.protected static void addBorders(org.docx4j.wml.Tbl table)
table - : The source tableCopyright © 2016 Imatia Innovation S.L.. All rights reserved.