@OpenApiAll public class DOCXEngine extends DefaultTemplateEngine implements StyledDocument
Modifier and Type | Class and Description |
---|---|
static class |
DOCXEngine.ContentTypeProcess
Handle content type
|
static class |
DOCXEngine.DocumentRelationshipProcess
Handle document relationship
|
static class |
DOCXEngine.NumberingProcess
Handle numbering File
|
static class |
DOCXEngine.NumberingUpdateProcess
Handle numbering for child document
This abstractNumId and numId in this file should be updated
|
static class |
DOCXEngine.StyleProcess
Handle style File
|
static class |
DOCXEngine.StyleUpdateProcess
Handle style for child document
This id and name in this file may be updated
|
velocityContext
context, isAborted, preProcessFile, processFile, properties
Constructor and Description |
---|
DOCXEngine()
A class constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
addColor(java.awt.Color color)
Add color for HTML to DOCX.
|
int |
addFont(java.awt.Font font)
Add font for HTML to DOCX.
|
void |
addHyperLink(java.lang.String rId,
java.lang.String url)
Add rId for hyper link.
|
void |
addImage(java.lang.String rId,
java.lang.String url,
java.lang.String imageType)
Add rId for hyper link.
|
int |
addList(List list)
Add list for HTML to DOCX.
|
int |
addObject(java.lang.Object object)
Appends object content into the document.
|
void |
addRowSpanID(java.lang.String id,
int value)
Add rowspan id and its value to map
|
int |
addStyle(javax.swing.text.Style style)
Add style for HTML to DOCX.
|
java.lang.String |
createComment(java.lang.String message)
Return a formatted comment from given message.
|
protected ParseErrorException |
createParseErrorWrapper(ParseErrorException parseError,
java.io.Reader source)
Create a ParseErrorException from the message.
|
Template |
createTemplate()
Creates a new
Template object for generating report by this engine. |
Template |
createTemplate(java.io.File input,
java.io.File output)
Creates a new
Template object. |
Template |
createTemplate(java.io.File input,
java.io.File output,
boolean ignoreLocation)
Creates a new
Template object. |
Template |
createTemplate(java.io.File input,
java.io.File output,
boolean ignoreDocInfo,
boolean ignoreLocation)
Creates a new
Template object. |
void |
destroy()
Called by the application or
TemplateEngineFactory to inform this engine
that it should destroy any resources that it has allocated. |
void |
evaluate(Template template)
Merge a template with current context and rendered stream into the writer.
|
int |
getAbStractId() |
java.util.Map<java.lang.String,java.util.List<java.lang.String[]>> |
getAbstractNumbering() |
java.util.Set<java.lang.String> |
getBookmarkList() |
java.util.Map<java.lang.String,com.nomagic.magicreport.engine.velocity.DOCXEngine.Bookmark> |
getBookmarkListMap() |
int |
getBookmarkN() |
java.lang.String |
getCharsetName() |
DocumentInfo |
getDocInfo() |
java.util.List<java.lang.String> |
getDocProp() |
java.util.List<java.lang.String> |
getDocPropList() |
org.w3c.dom.Document |
getDocument() |
void |
getDocumentSubFileInfo(Template template,
java.lang.String name,
org.xml.sax.helpers.DefaultHandler handler)
Get content of sub file before evaluate
|
void |
getEntryContent(Template template,
java.lang.String entryName)
Get entry from input file and entryName.
|
java.util.Map<java.lang.String,java.io.File> |
getEntryMap() |
java.lang.String |
getEntryName() |
java.util.Set<java.lang.String> |
getEntryNameSet() |
java.util.Set<java.lang.String> |
getEntrySet()
Return DOCX entry set.
|
IEvaluatedDocument |
getEvaluatedDocument() |
java.lang.StringBuffer |
getEvaluatedDocumentBuffer() |
java.util.Map<java.lang.String,java.lang.String> |
getHyperLinkMap() |
java.util.List<java.lang.String> |
getImageFormat() |
java.util.Map<java.lang.String,java.lang.String> |
getImageMap() |
DocumentInfo |
getMainDocInfo() |
java.util.Map<java.lang.String,java.lang.String> |
getNumberingDef() |
int |
getNumId() |
OOXMLTemplate |
getOoxmlTemplate() |
java.util.Set<java.lang.String> |
getStyleIds() |
java.util.Map<java.lang.String,java.lang.String> |
getStyleNameMap() |
Template |
getTemplate()
Return template.
|
protected void |
handleContentType(java.util.Set<DocumentContentType> contentTypes,
java.util.Set<DocumentContentType> sectionContentTypes,
java.lang.StringBuilder contentTypeContentBuilder,
java.util.Map<java.lang.String,java.util.List<java.lang.String>> newFilesInZip)
Handle [Content_Type].xml after evaluate.
|
protected void |
handleForColumn(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #forcol directive.
|
protected void |
handleForPage(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #forpage directive.
|
protected void |
handleForRow(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #forrow directive.
|
protected void |
handleGridCol(Template template,
java.lang.StringBuffer inProcessBuffer)
Add id to w:gridCol tag.
|
protected void |
handleIncludeSection(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #includeSection directive.
|
protected void |
handleIncludeSection(Template template,
java.lang.StringBuffer inProcessBuffer,
DocumentInfo child)
Handle the #includeSection directive.
|
protected void |
handleMergeColumns(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle $tableprop.mergeColumns directive
|
protected void |
handleMergeRows(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle $tableprop.mergeRows directive
|
protected org.w3c.dom.Document |
handleNumbering(javax.xml.parsers.DocumentBuilder docBuilder,
org.w3c.dom.Document baseNumberingDocument,
java.io.File sectionZipFile,
java.lang.StringBuffer numberingContent,
java.util.List<java.lang.String> abstractNumIds,
java.util.List<java.lang.String> numIds,
java.util.Map<java.lang.String,java.lang.String> numberingNamespaceMap)
Handle numbering.xml.
|
protected void |
handleRelationship(OOXMLStreamWriter ooxmlWriter,
java.io.File sectionZipFile,
java.util.Map<java.lang.String,? extends DocumentRelationship> relationshipMap,
java.lang.String relationshipPrefix,
java.util.Map<java.lang.String,java.util.List<java.lang.String>> newFilesInZip,
java.lang.StringBuilder relationContentBuilder)
Handle relationship file after evaluate.
|
protected void |
handleSectionBegin(Template template,
java.lang.StringBuffer inProcessBuffer)
Handle the #sectionBegin directive.
|
protected void |
handleSharedFiles()
Handle document.xml.rels, [Content_Types].xml, styles.xml, and numbering.xml
|
protected org.w3c.dom.Document |
handleStyle(javax.xml.parsers.DocumentBuilder docBuilder,
org.w3c.dom.Document baseStyleDocument,
java.io.File sectionZipFile,
java.lang.StringBuffer styleContent,
java.util.List<java.lang.String> styleIds,
java.util.List<java.lang.String> styleLatents,
java.util.Map<java.lang.String,java.lang.String> namespaceMap)
Handle styles.xml after evaluate.
|
void |
intenalEvaluate(Template template) |
boolean |
isHasNumbering() |
boolean |
isInMultipleLineComment() |
boolean |
isMemoryMode(Template template)
Tests if this template should process in memory mode.
This method is similar to code: |
int |
lineCount(java.lang.String content)
Count number of line from given content string.
|
protected void |
postProcess(Template template)
Perform a post-processing after the template has been evaluated.
|
protected TemplateException |
processVelocityException(Template template,
org.apache.velocity.exception.ParseErrorException e)
Call this method to process an Velocity exception and return in new format.
|
void |
setAbStractId(int abStractId) |
void |
setAbstractNumbering(java.util.Map<java.lang.String,java.util.List<java.lang.String[]>> abstractNumbering) |
void |
setBookmarkList(java.util.Set<java.lang.String> bookmarkList) |
void |
setBookmarkListMap(java.util.Map<java.lang.String,com.nomagic.magicreport.engine.velocity.DOCXEngine.Bookmark> bookmarkListMap) |
void |
setBookmarkN(int bookmarkN) |
void |
setCharsetName(java.lang.String charsetName) |
void |
setDocInfo(DocumentInfo docInfo) |
void |
setDocProp(java.util.List<java.lang.String> docProp) |
void |
setDocPropList(java.util.List<java.lang.String> docPropList) |
void |
setDocument(org.w3c.dom.Document document) |
void |
setEntryMap(java.util.Map<java.lang.String,java.io.File> entryMap) |
void |
setEntryName(java.lang.String entryName) |
void |
setEntryNameSet(java.util.Set<java.lang.String> entryNameSet) |
void |
setEvaluatedDocument(IEvaluatedDocument evaluatedDocument) |
void |
setHasNumbering(boolean hasNumbering) |
void |
setHyperLinkMap(java.util.Map<java.lang.String,java.lang.String> hyperLinkMap) |
void |
setImageFormat(java.util.List<java.lang.String> imageFormat) |
void |
setImageMap(java.util.Map<java.lang.String,java.lang.String> imageMap) |
void |
setInMultipleLineComment(boolean inMultipleLineComment) |
void |
setNumberingDef(java.util.Map<java.lang.String,java.lang.String> numberingDef) |
void |
setNumId(int numId) |
void |
setOoxmlTemplate(OOXMLTemplate ooxmlTemplate) |
void |
setStyleIds(java.util.Set<java.lang.String> styleIds) |
void |
setStyleNameMap(java.util.Map<java.lang.String,java.lang.String> styleNameMap) |
void |
translate(Template template,
java.lang.StringBuffer inProcessBuffer)
Process the template in
inProcessBuffer into valid format. |
void |
translate(Template template,
java.lang.StringBuffer inProcessBuffer,
DocumentInfo child)
Process the template in
inProcessBuffer into valid format. |
void |
translate(Template template,
java.lang.StringBuffer inProcessBuffer,
java.lang.String entryName,
DocumentInfo child)
Process the template in
inProcessBuffer into valid format. |
void |
updateStyleIds(java.lang.String styleId) |
void |
updateStyleNameMap(java.lang.String name,
java.lang.String id) |
abort, checkFileNotFoundException, getClassLoader, getFormatter, handleImport, isNoSpaceException, preProcess, process, process, processException, processVelocityException, setClassLoader, setFormatter, setLatestLocation, setLocation, setProperty, trimTrailSpace
addContext, addInvalidReferenceHandler, addObserver, addReferenceInsertionHandler, evaluate, getConcurrentToolException, getContext, getCurrentRuntimeInstance, getInvalidReferenceHandler, getProcessSize, getProperties, getProperty, getReferenceInsertionHandler, notifyObservers, observers, setConcurrentToolException, setContext, setCurrentRuntimeInstance
public boolean isInMultipleLineComment()
public void setInMultipleLineComment(boolean inMultipleLineComment)
public boolean isHasNumbering()
public void setHasNumbering(boolean hasNumbering)
public int getAbStractId()
public void setAbStractId(int abStractId)
public int getNumId()
public void setNumId(int numId)
public int getBookmarkN()
public void setBookmarkN(int bookmarkN)
public org.w3c.dom.Document getDocument()
public void setDocument(org.w3c.dom.Document document)
public java.util.List<java.lang.String> getImageFormat()
public void setImageFormat(java.util.List<java.lang.String> imageFormat)
public java.util.Map<java.lang.String,java.lang.String> getHyperLinkMap()
public void setHyperLinkMap(java.util.Map<java.lang.String,java.lang.String> hyperLinkMap)
public java.util.Map<java.lang.String,java.lang.String> getImageMap()
public void setImageMap(java.util.Map<java.lang.String,java.lang.String> imageMap)
public java.util.Set<java.lang.String> getEntryNameSet()
public void setEntryNameSet(java.util.Set<java.lang.String> entryNameSet)
public java.util.Map<java.lang.String,java.io.File> getEntryMap()
public void setEntryMap(java.util.Map<java.lang.String,java.io.File> entryMap)
public java.util.Set<java.lang.String> getBookmarkList()
public void setBookmarkList(java.util.Set<java.lang.String> bookmarkList)
public java.util.Map<java.lang.String,com.nomagic.magicreport.engine.velocity.DOCXEngine.Bookmark> getBookmarkListMap()
public void setBookmarkListMap(java.util.Map<java.lang.String,com.nomagic.magicreport.engine.velocity.DOCXEngine.Bookmark> bookmarkListMap)
public java.util.Map<java.lang.String,java.lang.String> getNumberingDef()
public void setNumberingDef(java.util.Map<java.lang.String,java.lang.String> numberingDef)
public java.util.Map<java.lang.String,java.util.List<java.lang.String[]>> getAbstractNumbering()
public void setAbstractNumbering(java.util.Map<java.lang.String,java.util.List<java.lang.String[]>> abstractNumbering)
public java.util.List<java.lang.String> getDocProp()
public void setDocProp(java.util.List<java.lang.String> docProp)
public java.lang.String getEntryName()
public void setEntryName(java.lang.String entryName)
public java.lang.String getCharsetName()
public void setCharsetName(java.lang.String charsetName)
public OOXMLTemplate getOoxmlTemplate()
public void setOoxmlTemplate(OOXMLTemplate ooxmlTemplate)
public java.util.List<java.lang.String> getDocPropList()
public void setDocPropList(java.util.List<java.lang.String> docPropList)
public java.util.Map<java.lang.String,java.lang.String> getStyleNameMap()
public void setStyleNameMap(java.util.Map<java.lang.String,java.lang.String> styleNameMap)
public void updateStyleNameMap(java.lang.String name, java.lang.String id)
public java.util.Set<java.lang.String> getStyleIds()
public void setStyleIds(java.util.Set<java.lang.String> styleIds)
public void updateStyleIds(java.lang.String styleId)
public Template createTemplate()
Template
object for generating report by this engine.createTemplate
in interface ITemplateEngine
createTemplate
in class DefaultTemplateEngine
Template
DefaultTemplateEngine.createTemplate(File, File)
public Template createTemplate(java.io.File input, java.io.File output) throws java.io.IOException
Template
object.createTemplate
in interface ITemplateEngine
createTemplate
in class DefaultTemplateEngine
input
- template file.output
- output file.Template
java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file,
or for some other reason cannot be opened.java.io.IOException
- If an I/O error occurspublic Template createTemplate(java.io.File input, java.io.File output, boolean ignoreLocation) throws java.io.IOException
Template
object.createTemplate
in class DefaultTemplateEngine
input
- template file.output
- output file.ignoreLocation
- true to ignore location property for child documentTemplate
java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file,
or for some other reason cannot be opened.java.io.IOException
- If an I/O error occurspublic Template createTemplate(java.io.File input, java.io.File output, boolean ignoreDocInfo, boolean ignoreLocation) throws java.io.IOException
Template
object.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 documentTemplate
java.io.FileNotFoundException
- if the file does not exist, is a directory rather than a regular file,
or for some other reason cannot be opened.java.io.IOException
- If an I/O error occurspublic void evaluate(Template template) throws TemplateException
evaluate
in interface ITemplateEngine
evaluate
in class AbstractTemplateEngine
template
- Template being evaluatedParseErrorException
- if a syntax or other error which prevents it from being
parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateITemplateEngine.evaluate(Template)
protected void handleSharedFiles()
protected void handleRelationship(OOXMLStreamWriter ooxmlWriter, java.io.File sectionZipFile, java.util.Map<java.lang.String,? extends DocumentRelationship> relationshipMap, java.lang.String relationshipPrefix, java.util.Map<java.lang.String,java.util.List<java.lang.String>> newFilesInZip, java.lang.StringBuilder relationContentBuilder)
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 contentprotected void handleContentType(java.util.Set<DocumentContentType> contentTypes, java.util.Set<DocumentContentType> sectionContentTypes, java.lang.StringBuilder contentTypeContentBuilder, java.util.Map<java.lang.String,java.util.List<java.lang.String>> newFilesInZip)
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 pathprotected org.w3c.dom.Document handleStyle(javax.xml.parsers.DocumentBuilder docBuilder, org.w3c.dom.Document baseStyleDocument, java.io.File sectionZipFile, java.lang.StringBuffer styleContent, java.util.List<java.lang.String> styleIds, java.util.List<java.lang.String> styleLatents, java.util.Map<java.lang.String,java.lang.String> namespaceMap)
docBuilder
- DocumentBuilderbaseStyleDocument
- base documentsectionZipFile
- zip file to be addedstyleContent
- all content of stylestyleIds
- existing stylestyleLatents
- existing latentsnamespaceMap
- namespaces of styleprotected org.w3c.dom.Document handleNumbering(javax.xml.parsers.DocumentBuilder docBuilder, org.w3c.dom.Document baseNumberingDocument, java.io.File sectionZipFile, java.lang.StringBuffer numberingContent, java.util.List<java.lang.String> abstractNumIds, java.util.List<java.lang.String> numIds, java.util.Map<java.lang.String,java.lang.String> numberingNamespaceMap)
docBuilder
- DocumentBuilderbaseNumberingDocument
- base documentsectionZipFile
- zip filenumberingContent
- numbering contentabstractNumIds
- list of existing abstractNumIdnumIds
- list of existing numIdnumberingNamespaceMap
- namespaces of numberingpublic void getDocumentSubFileInfo(Template template, java.lang.String name, org.xml.sax.helpers.DefaultHandler handler)
template
- a templatename
- entry namehandler
- file handlerpublic void getEntryContent(Template template, java.lang.String entryName)
template
- OOXML templateentryName
- entry file namepublic void intenalEvaluate(Template template) throws TemplateException
TemplateException
public void translate(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException, java.io.IOException
inProcessBuffer
into valid format.translate
in class DefaultTemplateEngine
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.java.io.IOException
- if IO Error occurs while reading template.public void translate(Template template, java.lang.StringBuffer inProcessBuffer, DocumentInfo child) throws ParseErrorException, java.io.IOException
inProcessBuffer
into valid format.template
- Template source.inProcessBuffer
- in process buffer.child
- document information to update some value in templateParseErrorException
- when error while translation, or syntax not recognized.java.io.IOException
- if IO Error occurs while reading template.public void translate(Template template, java.lang.StringBuffer inProcessBuffer, java.lang.String entryName, DocumentInfo child) throws ParseErrorException, java.io.IOException
inProcessBuffer
into valid format.template
- Template source.inProcessBuffer
- in process buffer.entryName
- entry namechild
- document information to update some value in templateParseErrorException
- when error while translation, or syntax not recognized.java.io.IOException
- if IO Error occurs while reading template.protected ParseErrorException createParseErrorWrapper(ParseErrorException parseError, java.io.Reader source)
parseError
- root causesource
- source templateprotected TemplateException processVelocityException(Template template, org.apache.velocity.exception.ParseErrorException e)
DefaultTemplateEngine.processVelocityException(Template, org.apache.velocity.exception.ParseErrorException)
to return exception with valid ODF line count.processVelocityException
in class DefaultTemplateEngine
template
- Templatee
- Velocity exceptionpublic int lineCount(java.lang.String content)
lineCount
in class DefaultTemplateEngine
content
- the input stringpublic java.util.Set<java.lang.String> getEntrySet()
public Template getTemplate()
protected void handleForPage(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
handleForPage
in class DefaultTemplateEngine
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleForRow(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
handleForRow
in class DefaultTemplateEngine
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleGridCol(Template template, java.lang.StringBuffer inProcessBuffer)
template
- Template source.inProcessBuffer
- in process buffer.protected void handleForColumn(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleMergeColumns(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleMergeRows(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleIncludeSection(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
handleIncludeSection
in class DefaultTemplateEngine
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.protected void handleIncludeSection(Template template, java.lang.StringBuffer inProcessBuffer, DocumentInfo child) throws ParseErrorException
template
- Template source.inProcessBuffer
- in process buffer.child
- DocumentInfo of child templateParseErrorException
- when error while translation, or syntax not recognized.protected void handleSectionBegin(Template template, java.lang.StringBuffer inProcessBuffer) throws ParseErrorException
handleSectionBegin
in class DefaultTemplateEngine
template
- Template source.inProcessBuffer
- in process buffer.ParseErrorException
- when error while translation, or syntax not recognized.public java.lang.String createComment(java.lang.String message)
createComment
in class DefaultTemplateEngine
message
- message to put in document commentprotected void postProcess(Template template) throws TemplateException
postProcess
in class DefaultTemplateEngine
template
- template after evaluated.ParseErrorException
- if a syntax or other error which prevents it from being parsed.InitializationEngineException
- error while initializing engineTemplateException
- other error while processing the templateDefaultTemplateEngine.postProcess(com.nomagic.magicreport.Template)
public void destroy()
DefaultTemplateEngine
TemplateEngineFactory
to 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.
destroy
in interface ITemplateEngine
destroy
in class DefaultTemplateEngine
public int addFont(java.awt.Font font)
addFont
in interface StyledDocument
font
- fontpublic int addList(List list)
addList
in interface StyledDocument
list
- listpublic int addStyle(javax.swing.text.Style style)
addStyle
in interface StyledDocument
style
- stylepublic int addColor(java.awt.Color color)
addColor
in interface StyledDocument
color
- colorpublic void addHyperLink(java.lang.String rId, java.lang.String url)
rId
- rIdurl
- URLpublic void addImage(java.lang.String rId, java.lang.String url, java.lang.String imageType)
rId
- rIdurl
- URLimageType
- imageTypepublic void addRowSpanID(java.lang.String id, int value)
id
- rowspan idvalue
- number of rows to be mergedpublic int addObject(java.lang.Object object)
addObject
in interface StyledDocument
object
- adding objectpublic DocumentInfo getDocInfo()
public void setDocInfo(DocumentInfo docInfo)
public DocumentInfo getMainDocInfo()
public IEvaluatedDocument getEvaluatedDocument()
public void setEvaluatedDocument(IEvaluatedDocument evaluatedDocument)
public java.lang.StringBuffer getEvaluatedDocumentBuffer()
public boolean isMemoryMode(Template template)
AbstractTemplateEngine
template.getSize() > properties.getProperty(TemplateConstants.TEMPLATE_PROCESS_SIZE, "0")
isMemoryMode
in class AbstractTemplateEngine
template
- a test TemplateCopyright © 2010 - No Magic Asia