Class DOCXEngine
java.lang.Object
java.util.Observable
com.nomagic.magicreport.engine.AbstractTemplateEngine
com.nomagic.magicreport.engine.velocity.DefaultTemplateEngine
com.nomagic.magicreport.engine.velocity.DOCXEngine
- All Implemented Interfaces:
IExtensionTemplateEngine,com.nomagic.magicreport.engine.IRuntimeInstanceVelocityEngine,ITemplateEngine,StyledDocument
The Velocity engine for OpenXML Word Document (DOCX).
- Since:
- Oct 19, 2009
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHandle content typestatic classHandle document relationshipstatic classHandle numbering Filestatic classHandle numbering for child document This abstractNumId and numId in this file should be updatedstatic classHandle style Filestatic classHandle style for child document This id and name in this file may be updated -
Field Summary
Fields inherited from class com.nomagic.magicreport.engine.velocity.DefaultTemplateEngine
velocityContextFields inherited from class com.nomagic.magicreport.engine.AbstractTemplateEngine
context, isAborted, preProcessFile, processFile, properties -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChart()intAdd color for HTML to DOCX.intAdd font for HTML to DOCX.voidaddHyperLink(String rId, String url) Add rId for hyper link.voidAdd rId for hyper link.intAdd list for HTML to DOCX.intAppends object content into the document.intaddPageSections(String str) voidaddRowSpanID(String id, int value) Add rowspan id and its value to mapintAdd style for HTML to DOCX.createComment(String message) Return a formatted comment from given message.protected ParseErrorExceptioncreateParseErrorWrapper(ParseErrorException parseError, Reader source) Create a ParseErrorException from the message.Creates a newTemplateobject for generating report by this engine.createTemplate(File input, File output) Creates a newTemplateobject.createTemplate(File input, File output, boolean ignoreLocation) Creates a newTemplateobject.createTemplate(File input, File output, boolean ignoreDocInfo, boolean ignoreLocation) Creates a newTemplateobject.voiddestroy()Called by the application orTemplateEngineFactoryto inform this engine that it should destroy any resources that it has allocated.voidMerge a template with current context and rendered stream into the writer.intintvoidgetDocumentSubFileInfo(Template template, String name, DefaultHandler handler) Get content of sub file before evaluatevoidgetEntryContent(Template template, String entryName) Get entry from input file and entryName.Return DOCX entry set.com.nomagic.magicreport.engine.ooxml.child.docx.IEvaluatedDocumentintgetNumId()getPageSections(int index) Return template.protected voidhandleContentType(Set<com.nomagic.magicreport.engine.ooxml.child.docx.DocumentContentType> contentTypes, Set<com.nomagic.magicreport.engine.ooxml.child.docx.DocumentContentType> sectionContentTypes, StringBuilder contentTypeContentBuilder, Map<String, List<String>> newFilesInZip) Handle [Content_Type].xml after evaluate.protected voidhandleForColumn(Template template, StringBuilder inProcessBuffer) Handle the #forcol directive.protected voidhandleForPage(Template template, StringBuilder inProcessBuffer) Handle the #forpage directive.protected voidhandleForRow(Template template, StringBuilder inProcessBuffer) Handle the #forrow directive.protected voidhandleGridCol(Template template, StringBuilder inProcessBuffer) Add id to w:gridCol tag.protected voidhandleIncludeSection(Template template, StringBuilder inProcessBuffer) Handle the #includeSection directive.protected voidhandleIncludeSection(Template template, StringBuilder inProcessBuffer, DocumentInfo child) Handle the #includeSection directive.protected voidhandleMergeColumns(Template template, StringBuilder inProcessBuffer) Handle $tableprop.mergeColumns directiveprotected voidhandleMergeRows(Template template, StringBuilder inProcessBuffer) Handle $tableprop.mergeRows directiveprotected DocumenthandleNumbering(DocumentBuilder docBuilder, Document baseNumberingDocument, File sectionZipFile, StringBuilder numberingContent, List<String> abstractNumIds, List<String> numIds, Map<String, String> numberingNamespaceMap) Handle numbering.xml.protected voidhandleRelationship(OOXMLStreamWriter ooxmlWriter, File sectionZipFile, Map<String, ? extends com.nomagic.magicreport.engine.ooxml.child.docx.DocumentRelationship> relationshipMap, String relationshipPrefix, Map<String, List<String>> newFilesInZip, StringBuilder relationContentBuilder) Handle relationship file after evaluate.protected voidhandleSectionBegin(Template template, StringBuilder inProcessBuffer) Handle the #sectionBegin directive.protected voidHandle document.xml.rels, [Content_Types].xml, styles.xml, and numbering.xmlprotected DocumenthandleStyle(DocumentBuilder docBuilder, Document baseStyleDocument, File sectionZipFile, StringBuilder styleContent, List<String> styleIds, List<String> styleLatents, Map<String, String> namespaceMap) Handle styles.xml after evaluate.voidintenalEvaluate(Template template) booleanbooleanbooleanisMemoryMode(Template template) Tests if this template should process in memory mode.
This method is similar to code:intCount number of line from given content string.protected voidpostProcess(Template template) Perform a post-processing after the template has been evaluated.protected TemplateExceptionprocessVelocityException(Template template, org.apache.velocity.exception.ParseErrorException e) Call this method to process an Velocity exception and return in new format.voidsetAbStractId(int abStractId) voidsetAbstractNumbering(Map<String, List<String[]>> abstractNumbering) voidsetBookmarkList(Set<String> bookmarkList) voidsetBookmarkListMap(Map<String, com.nomagic.magicreport.engine.velocity.DOCXEngine.Bookmark> bookmarkListMap) voidsetBookmarkN(int bookmarkN) voidsetCharsetName(String charsetName) voidsetCheckSize(boolean isCheckFileSize) voidsetDocInfo(DocumentInfo docInfo) voidsetDocProp(List<String> docProp) voidsetDocPropList(List<String> docPropList) voidsetDocument(Document document) voidsetEntryMap(Map<String, File> entryMap) voidsetEntryName(String entryName) voidsetEntryNameSet(Set<String> entryNameSet) voidsetEvaluatedDocument(com.nomagic.magicreport.engine.ooxml.child.docx.IEvaluatedDocument evaluatedDocument) voidsetHasNumbering(boolean hasNumbering) voidsetHyperLinkMap(Map<String, String> hyperLinkMap) voidsetImageFormat(List<String> imageFormat) voidsetImageMap(Map<String, String> imageMap) voidsetInMultipleLineComment(boolean inMultipleLineComment) voidsetNumberingDef(Map<String, String> numberingDef) voidsetNumId(int numId) voidsetOoxmlTemplate(OOXMLTemplate ooxmlTemplate) voidsetStyleIds(Set<String> styleIds) voidsetStyleNameMap(Map<String, String> styleNameMap) protected BufferedWritersetWriterForEvaluate(Template template) voidtranslate(Template template, StringBuilder inProcessBuffer) Process the template ininProcessBufferinto valid format.voidtranslate(Template template, StringBuilder inProcessBuffer, DocumentInfo child) Process the template ininProcessBufferinto valid format.voidtranslate(Template template, StringBuilder inProcessBuffer, String entryName, DocumentInfo child) Process the template ininProcessBufferinto valid format.voidupdateSize(long size) voidupdateStyleIds(String styleId) voidupdateStyleNameMap(String name, String id) Methods inherited from class com.nomagic.magicreport.engine.velocity.DefaultTemplateEngine
abort, checkFileNotFoundException, clearTools, getClassLoader, getFormatter, getResolvedSectionName, handleImport, isNoSpaceException, preProcess, process, process, processException, processVelocityException, setClassLoader, setFormatter, setLatestLocation, setLocation, setProperty, trimTrailSpaceMethods inherited from class com.nomagic.magicreport.engine.AbstractTemplateEngine
addContext, addInvalidReferenceHandler, addObserver, addReferenceInsertionHandler, evaluate, getConcurrentToolException, getContext, getCurrentRuntimeInstance, getInvalidReferenceHandler, getProcessSize, getProperties, getProperty, getReferenceInsertionHandler, notifyObservers, observers, setConcurrentToolException, setContext, setCurrentRuntimeInstanceMethods inherited from class java.util.Observable
clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, setChanged
-
Constructor Details
-
DOCXEngine
public DOCXEngine()A class constructor.
-
-
Method Details
-
isInMultipleLineComment
public boolean isInMultipleLineComment() -
setInMultipleLineComment
public void setInMultipleLineComment(boolean inMultipleLineComment) -
isHasNumbering
public boolean isHasNumbering() -
setHasNumbering
public void setHasNumbering(boolean hasNumbering) -
getAbStractId
public int getAbStractId() -
setAbStractId
public void setAbStractId(int abStractId) -
getNumId
public int getNumId() -
setNumId
public void setNumId(int numId) -
getBookmarkN
public int getBookmarkN() -
setBookmarkN
public void setBookmarkN(int bookmarkN) -
getDocument
-
setDocument
-
getImageFormat
-
setImageFormat
-
getHyperLinkMap
-
setHyperLinkMap
-
getImageMap
-
setImageMap
-
getEntryNameSet
-
setEntryNameSet
-
getEntryMap
-
setEntryMap
-
getBookmarkList
-
setBookmarkList
-
getBookmarkListMap
-
setBookmarkListMap
-
getNumberingDef
-
setNumberingDef
-
getAbstractNumbering
-
setAbstractNumbering
-
getDocProp
-
setDocProp
-
getEntryName
-
setEntryName
-
getCharsetName
-
setCharsetName
-
getOoxmlTemplate
-
setOoxmlTemplate
-
getDocPropList
-
setDocPropList
-
getStyleNameMap
-
setStyleNameMap
-
updateStyleNameMap
-
getStyleIds
-
setStyleIds
-
updateStyleIds
-
getPageSections
-
addPageSections
-
createTemplate
Creates a newTemplateobject for generating report by this engine.- Specified by:
createTemplatein interfaceITemplateEngine- Overrides:
createTemplatein classDefaultTemplateEngine- Returns:
- an instance of
Template - See Also:
-
createTemplate
Creates a newTemplateobject.- Specified by:
createTemplatein interfaceITemplateEngine- Overrides:
createTemplatein classDefaultTemplateEngine- Parameters:
input- template file.output- output file.- Returns:
- an instance of
Template - Throws:
FileNotFoundException- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened.IOException- If an I/O error occurs
-
createTemplate
Creates a newTemplateobject.- Overrides:
createTemplatein classDefaultTemplateEngine- Parameters:
input- template file.output- output file.ignoreLocation- true to ignore location property for child document- Returns:
- an instance of
Template - Throws:
FileNotFoundException- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened.IOException- If an I/O error occurs
-
createTemplate
public Template createTemplate(File input, File output, boolean ignoreDocInfo, boolean ignoreLocation) throws IOException Creates a newTemplateobject.- Parameters:
input- template file.output- output file.ignoreDocInfo- true to ignore create document info. this parameter should be true for creating template of child documentignoreLocation- true to ignore location property for child document- Returns:
- an instance of
Template - Throws:
FileNotFoundException- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened.IOException- If an I/O error occurs
-
evaluate
Merge a template with current context and rendered stream into the writer.- Specified by:
evaluatein interfaceITemplateEngine- Overrides:
evaluatein classAbstractTemplateEngine- Parameters:
template- Template being evaluated- Throws:
ParseErrorException- if a syntax or other error which prevents it from being parsed.InitializationEngineException- error while initializing engineTemplateException- other error while processing the template- See Also:
-
setWriterForEvaluate
- Overrides:
setWriterForEvaluatein classDefaultTemplateEngine
-
handleRelationship
protected void handleRelationship(OOXMLStreamWriter ooxmlWriter, File sectionZipFile, Map<String, ? extends com.nomagic.magicreport.engine.ooxml.child.docx.DocumentRelationship> relationshipMap, String relationshipPrefix, Map<String, List<String>> newFilesInZip, StringBuilder relationContentBuilder) Handle relationship file after evaluate.- Parameters:
ooxmlWriter- writersectionZipFile- zip file of child templaterelationshipMap- map of relationship and idrelationshipPrefix- prefix path for relationshipnewFilesInZip- map of new files that are created after generatedrelationContentBuilder- stringbuilder to keep relationship content
-
handleContentType
protected void handleContentType(Set<com.nomagic.magicreport.engine.ooxml.child.docx.DocumentContentType> contentTypes, Set<com.nomagic.magicreport.engine.ooxml.child.docx.DocumentContentType> sectionContentTypes, StringBuilder contentTypeContentBuilder, Map<String, List<String>> newFilesInZip) Handle [Content_Type].xml after evaluate.- Parameters:
contentTypes- content type in main documentsectionContentTypes- content type in child documentcontentTypeContentBuilder- Stringbuilder to create new content of [Content_Type].xmlnewFilesInZip- map of partname and new target path
-
handleStyle
protected Document handleStyle(DocumentBuilder docBuilder, Document baseStyleDocument, File sectionZipFile, StringBuilder styleContent, List<String> styleIds, List<String> styleLatents, Map<String, String> namespaceMap) Handle styles.xml after evaluate.- Parameters:
docBuilder- DocumentBuilderbaseStyleDocument- base documentsectionZipFile- zip file to be addedstyleContent- all content of stylestyleIds- existing stylestyleLatents- existing latentsnamespaceMap- namespaces of style- Returns:
- base document
-
handleNumbering
protected Document handleNumbering(DocumentBuilder docBuilder, Document baseNumberingDocument, File sectionZipFile, StringBuilder numberingContent, List<String> abstractNumIds, List<String> numIds, Map<String, String> numberingNamespaceMap) Handle numbering.xml.- Parameters:
docBuilder- DocumentBuilderbaseNumberingDocument- base documentsectionZipFile- zip filenumberingContent- numbering contentabstractNumIds- list of existing abstractNumIdnumIds- list of existing numIdnumberingNamespaceMap- namespaces of numbering- Returns:
- base document
-
getDocumentSubFileInfo
Get content of sub file before evaluate- Parameters:
template- a templatename- entry namehandler- file handler
-
getEntryContent
Get entry from input file and entryName. Then set reader to template.- Parameters:
template- OOXML templateentryName- entry file name
-
intenalEvaluate
- Throws:
TemplateException
-
translate
public void translate(Template template, StringBuilder inProcessBuffer) throws ParseErrorException, IOException Process the template ininProcessBufferinto valid format.- Overrides:
translatein classDefaultTemplateEngine- Parameters:
template- Template source.inProcessBuffer- in process buffer.- Throws:
ParseErrorException- when error while translation, or syntax not recognized.IOException- if IO Error occurs while reading template.
-
translate
public void translate(Template template, StringBuilder inProcessBuffer, DocumentInfo child) throws ParseErrorException, IOException Process the template ininProcessBufferinto valid format.- Parameters:
template- Template source.inProcessBuffer- in process buffer.child- document information to update some value in template- Throws:
ParseErrorException- when error while translation, or syntax not recognized.IOException- if IO Error occurs while reading template.
-
translate
public void translate(Template template, StringBuilder inProcessBuffer, String entryName, DocumentInfo child) throws ParseErrorException, IOException Process the template ininProcessBufferinto valid format.- Parameters:
template- Template source.inProcessBuffer- in process buffer.entryName- entry namechild- document information to update some value in template- Throws:
ParseErrorException- when error while translation, or syntax not recognized.IOException- if IO Error occurs while reading template.
-
createParseErrorWrapper
protected ParseErrorException createParseErrorWrapper(ParseErrorException parseError, Reader source) Create a ParseErrorException from the message.- Parameters:
parseError- root causesource- source template- Returns:
- instance of ParseErrorException
-
processVelocityException
protected TemplateException processVelocityException(Template template, org.apache.velocity.exception.ParseErrorException e) Call this method to process an Velocity exception and return in new format. OverrideDefaultTemplateEngine.processVelocityException(Template, org.apache.velocity.exception.ParseErrorException)to return exception with valid ODF line count.- Overrides:
processVelocityExceptionin classDefaultTemplateEngine- Parameters:
template- Templatee- Velocity exception- Returns:
- TemplateException
-
lineCount
Count number of line from given content string.- Overrides:
lineCountin classDefaultTemplateEngine- Parameters:
content- the input string- Returns:
- number of line
-
getEntrySet
Return DOCX entry set.- Returns:
- DOCX entry set.
-
getTemplate
Return template.- Returns:
- a DOCX template
-
handleForPage
protected void handleForPage(Template template, StringBuilder inProcessBuffer) throws ParseErrorException Handle the #forpage directive.- Overrides:
handleForPagein classDefaultTemplateEngine- Parameters:
template- Template source.inProcessBuffer- in process buffer.- Throws:
ParseErrorException- when error while translation, or syntax not recognized.
-
handleForRow
protected void handleForRow(Template template, StringBuilder inProcessBuffer) throws ParseErrorException Handle the #forrow directive.- Overrides:
handleForRowin classDefaultTemplateEngine- Parameters:
template- Template source.inProcessBuffer- in process buffer.- Throws:
ParseErrorException- when error while translation, or syntax not recognized.
-
handleGridCol
Add id to w:gridCol tag.- Parameters:
template- Template source.inProcessBuffer- in process buffer.
-
handleForColumn
protected void handleForColumn(Template template, StringBuilder inProcessBuffer) throws ParseErrorException Handle the #forcol directive.- Parameters:
template- Template source.inProcessBuffer- in process buffer.- Throws:
ParseErrorException- when error while translation, or syntax not recognized.
-
handleMergeColumns
protected void handleMergeColumns(Template template, StringBuilder inProcessBuffer) throws ParseErrorException Handle $tableprop.mergeColumns directive- Parameters:
template- Template source.inProcessBuffer- in process buffer.- Throws:
ParseErrorException- when error while translation, or syntax not recognized.
-
handleMergeRows
protected void handleMergeRows(Template template, StringBuilder inProcessBuffer) throws ParseErrorException Handle $tableprop.mergeRows directive- Parameters:
template- Template source.inProcessBuffer- in process buffer.- Throws:
ParseErrorException- when error while translation, or syntax not recognized.
-
handleIncludeSection
protected void handleIncludeSection(Template template, StringBuilder inProcessBuffer) throws ParseErrorException Handle the #includeSection directive.- Overrides:
handleIncludeSectionin classDefaultTemplateEngine- Parameters:
template- Template source.inProcessBuffer- in process buffer.- Throws:
ParseErrorException- when error while translation, or syntax not recognized.
-
handleIncludeSection
protected void handleIncludeSection(Template template, StringBuilder inProcessBuffer, DocumentInfo child) throws ParseErrorException Handle the #includeSection directive.- Parameters:
template- Template source.inProcessBuffer- in process buffer.child- DocumentInfo of child template- Throws:
ParseErrorException- when error while translation, or syntax not recognized.
-
handleSectionBegin
protected void handleSectionBegin(Template template, StringBuilder inProcessBuffer) throws ParseErrorException Handle the #sectionBegin directive.- Overrides:
handleSectionBeginin classDefaultTemplateEngine- Parameters:
template- Template source.inProcessBuffer- in process buffer.- Throws:
ParseErrorException- when error while translation, or syntax not recognized.
-
createComment
Return a formatted comment from given message. The default comment format return from this method is "" where {0} is message;- Overrides:
createCommentin classDefaultTemplateEngine- Parameters:
message- message to put in document comment- Returns:
- comment
-
postProcess
Perform a post-processing after the template has been evaluated.- Overrides:
postProcessin classDefaultTemplateEngine- Parameters:
template- template after evaluated.- Throws:
ParseErrorException- if a syntax or other error which prevents it from being parsed.InitializationEngineException- error while initializing engineTemplateException- other error while processing the template- See Also:
-
destroy
public void destroy()Description copied from class:DefaultTemplateEngineCalled by the application orTemplateEngineFactoryto inform this engine that it should destroy any resources that it has allocated.A subclass of engine should override this method if it has any operation that it wants to perform before it is destroyed.
- Specified by:
destroyin interfaceITemplateEngine- Overrides:
destroyin classDefaultTemplateEngine
-
addFont
Add font for HTML to DOCX.- Specified by:
addFontin interfaceStyledDocument- Parameters:
font- font- Returns:
- font id
-
addList
Add list for HTML to DOCX.- Specified by:
addListin interfaceStyledDocument- Parameters:
list- list- Returns:
- list id
-
addStyle
Add style for HTML to DOCX.- Specified by:
addStylein interfaceStyledDocument- Parameters:
style- style- Returns:
- style id
-
addColor
Add color for HTML to DOCX.- Specified by:
addColorin interfaceStyledDocument- Parameters:
color- color- Returns:
- color id
-
addHyperLink
Add rId for hyper link.- Parameters:
rId- rIdurl- URL
-
addImage
Add rId for hyper link.- Parameters:
rId- rIdurl- URLimageType- imageType
-
addRowSpanID
Add rowspan id and its value to map- Parameters:
id- rowspan idvalue- number of rows to be merged
-
addObject
Appends object content into the document.- Specified by:
addObjectin interfaceStyledDocument- Parameters:
object- adding object- Returns:
- index to object
-
getDocInfo
-
setDocInfo
-
getMainDocInfo
-
getEvaluatedDocument
public com.nomagic.magicreport.engine.ooxml.child.docx.IEvaluatedDocument getEvaluatedDocument() -
setEvaluatedDocument
public void setEvaluatedDocument(com.nomagic.magicreport.engine.ooxml.child.docx.IEvaluatedDocument evaluatedDocument) -
getEvaluatedDocumentBuffer
-
isMemoryMode
Description copied from class:AbstractTemplateEngineTests if this template should process in memory mode.
This method is similar to code:template.getSize() > properties.getProperty(TemplateConstants.TEMPLATE_PROCESS_SIZE, "0")- Overrides:
isMemoryModein classAbstractTemplateEngine- Parameters:
template- a test Template- Returns:
- true if template size is less than TEMPLATE_PROCESS_SIZE
-
updateSize
public void updateSize(long size) -
setCheckSize
public void setCheckSize(boolean isCheckFileSize) -
addChart
public void addChart()
-