public class DocWordWriter extends AbstractWordWriter<com.jacob.com.Dispatch>
DocWordWriter
! Most of it
TTD-ed.
Because jacob has no API for constants, when we have to provide constants as arguments to VBA methods, we found the values for those constants with ObjectType browser in VBA (macro) editor.
In general, we split the processing into two steps:
WordHelper.PostProcessor
Modifier and Type | Field and Description |
---|---|
static java.util.List<java.lang.String> |
FILE_EXTENSIONS |
protected static boolean |
OLD_CAPT |
static boolean |
ORIG_CREATE_TABLE |
static java.lang.String |
SEP_AFTER_CAPTION_NUM |
TOOL_CUSTOM_DOC_PROP, UML_CUSTOM_DOC_PROP
PAGE_WIDTH, POINTS_FOR_1CM
Constructor and Description |
---|
DocWordWriter(WordWriterInput input)
Constructs this instance and copies input file into output directory; this writer will write
into that copy to produce the final document, by replacing placeholders found in it.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
appendHtmlTextInNewParagraphWithStyle(Range<com.jacob.com.Dispatch> range,
java.lang.String newMarkup,
Style style) |
void |
appendNewLine(Range<com.jacob.com.Dispatch> range) |
java.lang.String |
appendRawTextInNewParagraphWithStyle(Range<com.jacob.com.Dispatch> range,
java.lang.String newText,
Style style) |
java.lang.String |
appendText(Range<com.jacob.com.Dispatch> range,
java.lang.String newText) |
java.lang.String |
appendTextInNewParagraph(Range<com.jacob.com.Dispatch> range,
java.lang.String newText) |
java.lang.String |
appendTextWithStyle(Range<com.jacob.com.Dispatch> range,
java.lang.String newText,
Style style) |
boolean |
applyCloseReopen()
Returns whether to apply close/reopen hack (may be needed for performance reasons).
|
static java.lang.String |
asCsv(PropertiesDoc doc,
java.lang.String cellSep) |
void |
clearUndoCache()
When you have large documents and you use a binary (COM) API, you will want to call this one
regularly (e.g., for each class doc), so you don't get Word pop-up windows "memory
insufficient.
|
Cursor<com.jacob.com.Dispatch> |
closeAndReopenDoc(CursorList<com.jacob.com.Dispatch> cursors,
Cursor<com.jacob.com.Dispatch> currentCursor) |
void |
closeDoc()
Closes and saves the MS Word document.
|
void |
collapseRangeToEnd(Range<com.jacob.com.Dispatch> range) |
void |
collapseRangeToStart(Range<com.jacob.com.Dispatch> range) |
java.util.Map<CaptionKind,java.util.List<Caption<com.jacob.com.Dispatch>>> |
collectCaptionParagraphsAndFixLabelsAlsoInTOCs()
Expected to be called after styles and caption labels get properly initialised from the
current open document.
|
WordPatternFinder<com.jacob.com.Dispatch> |
createPatternFinder(java.lang.String msPattern) |
Range<com.jacob.com.Dispatch> |
createRange(com.jacob.com.Dispatch object) |
void |
createWordApp()
Where applicable, launches (and caches) the MS Word application.
|
Range<com.jacob.com.Dispatch> |
duplicateRange(Range<com.jacob.com.Dispatch> range)
FIXME: could go to Range?
|
void |
exitAppAndSaveDocument()
Saves MS Word document (and where applicable, exits MS Word application).
|
java.util.Map<java.lang.String,java.lang.String> |
getCustomDocProperties() |
Range<com.jacob.com.Dispatch> |
getDocumentAsRange() |
java.util.Map<java.lang.String,ExistingStyle> |
getExistingStyles()
Returns non-empty map of non-null styles read from an open document, with style name as key.
|
int |
getRangeParagraphCount(Range<com.jacob.com.Dispatch> range) |
int |
getRangeParagraphOutlineLevel(Range<com.jacob.com.Dispatch> range,
int paraIdx) |
java.lang.String |
getRangeParagraphStyleName(Range<com.jacob.com.Dispatch> range,
int paraIdx) |
java.util.Set<java.lang.String> |
getSupportedFormats()
Returns the set of supported formats, as file extensions; e.g., ".doc", ".xml".
|
java.lang.String |
getWordAppName()
Returns the MS Word application name.
|
java.lang.String |
getWordAppVersion()
Returns the MS Word application version.
|
void |
initDocgenOptimisationOptions()
Where applicable, initialises and stores MS Word application options (speed of doc
generation) to original values.
|
void |
insertBookmark(Range<com.jacob.com.Dispatch> range,
java.lang.String label) |
void |
insertCaptionRef(Range<com.jacob.com.Dispatch> range,
CaptionKind kind,
int idx,
boolean introBeforeCaption)
Inserts reference to the caption
tabNumber at the start of
insertPointRange . |
void |
insertFigure(Range<com.jacob.com.Dispatch> range,
java.io.File pic)
Input
range includes any potential text within a paragraph. |
com.jacob.com.Dispatch |
insertFigureCaption(Range<com.jacob.com.Dispatch> range,
int expectedSeqNum,
java.lang.String text) |
void |
insertHyperlink(Range<com.jacob.com.Dispatch> range,
java.lang.String textToDisplay,
java.lang.String url) |
int |
insertTable(Range<com.jacob.com.Dispatch> range,
PropertiesDoc doc,
Style tabhead,
boolean addBookmarks) |
void |
insertTableCaption(Range<com.jacob.com.Dispatch> range,
int expectedSeqNum,
java.lang.String text) |
boolean |
isRangeWithTable(com.jacob.com.Dispatch range) |
void |
moveStartChar(Range<com.jacob.com.Dispatch> range,
int count) |
void |
openDoc()
Creates (and caches) the MS Word document.
|
void |
prependNewLine(Range<com.jacob.com.Dispatch> range) |
void |
prependText(Range<com.jacob.com.Dispatch> range,
java.lang.String newText)
Prepends text; prepended paragraph will have the same style as the one in range.
|
void |
setCustomDocProperties(java.util.Map<java.lang.String,java.lang.String> newCustomProps) |
void |
setDocgenOptimisationOptions()
Where applicable, sets MS Word application options to speed performance of doc generation.
|
void |
unsetDocgenOptimisationOptions()
Where applicable, brings back the original MS Word application options to values stored with
the call to
WordHelper.initDocgenOptimisationOptions() . |
void |
updateFields() |
void |
updateTablesOf(java.lang.String what) |
appendTextInNewParagraphWithStyle, createCaption, createCursor, getCursors, getInput, getInputFileNames, getOutputFileNames, isInTOC, pointForPerc, scanHyperlinkPlaceholderRanges, scanPlaceholderRanges, toString, write, writeAbbrTable, writeByTest, writeClassFromPackage, writeDataIndex, writeDiagram, writeExplicitClass, writeFcTable, writeLnMapPackage, writePackage, writePresCondTable, writeProperties, writeSclEnum, writeTrgOpTable
getDocumentMetadata
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDocumentMetadata
public static final boolean ORIG_CREATE_TABLE
protected static final boolean OLD_CAPT
public static final java.lang.String SEP_AFTER_CAPTION_NUM
public static final java.util.List<java.lang.String> FILE_EXTENSIONS
public DocWordWriter(WordWriterInput input) throws UnsupportedInputFormatException, UnsupportedOutputFormatException, java.io.IOException
UnsupportedInputFormatException
- if configured with template in unsupported formatUnsupportedOutputFormatException
- if configured with output in unsupported formatjava.io.IOException
- if fails to copy input template into output directory.public static java.lang.String asCsv(PropertiesDoc doc, java.lang.String cellSep)
public void createWordApp()
AbstractWordWriter
This default implementation does nothing.
createWordApp
in interface WordHelper<com.jacob.com.Dispatch>
createWordApp
in class AbstractWordWriter<com.jacob.com.Dispatch>
public java.lang.String getWordAppName()
AbstractWordWriter
This default implementation returns empty string.
getWordAppName
in interface WordHelper<com.jacob.com.Dispatch>
getWordAppName
in class AbstractWordWriter<com.jacob.com.Dispatch>
public java.lang.String getWordAppVersion()
AbstractWordWriter
This default implementation returns empty string.
getWordAppVersion
in interface WordHelper<com.jacob.com.Dispatch>
getWordAppVersion
in class AbstractWordWriter<com.jacob.com.Dispatch>
public void openDoc()
WordHelper
public void closeDoc()
WordHelper
public void exitAppAndSaveDocument()
AbstractWordWriter
This default implementation does nothing.
exitAppAndSaveDocument
in interface WordHelper<com.jacob.com.Dispatch>
exitAppAndSaveDocument
in class AbstractWordWriter<com.jacob.com.Dispatch>
public void initDocgenOptimisationOptions()
AbstractWordWriter
This default implementation does nothing.
initDocgenOptimisationOptions
in interface WordHelper<com.jacob.com.Dispatch>
initDocgenOptimisationOptions
in class AbstractWordWriter<com.jacob.com.Dispatch>
public void setDocgenOptimisationOptions()
AbstractWordWriter
This default implementation does nothing.
setDocgenOptimisationOptions
in interface WordHelper<com.jacob.com.Dispatch>
setDocgenOptimisationOptions
in class AbstractWordWriter<com.jacob.com.Dispatch>
public void unsetDocgenOptimisationOptions()
AbstractWordWriter
WordHelper.initDocgenOptimisationOptions()
.
This default implementation does nothing.
unsetDocgenOptimisationOptions
in interface WordHelper<com.jacob.com.Dispatch>
unsetDocgenOptimisationOptions
in class AbstractWordWriter<com.jacob.com.Dispatch>
public void insertBookmark(Range<com.jacob.com.Dispatch> range, java.lang.String label)
public void insertHyperlink(Range<com.jacob.com.Dispatch> range, java.lang.String textToDisplay, java.lang.String url)
public java.util.Map<java.lang.String,ExistingStyle> getExistingStyles()
It will create all custom styles, and only those built-in styles we are interested in.
public void updateFields()
public void updateTablesOf(java.lang.String what)
public java.util.Map<java.lang.String,java.lang.String> getCustomDocProperties()
public void setCustomDocProperties(java.util.Map<java.lang.String,java.lang.String> newCustomProps)
public Cursor<com.jacob.com.Dispatch> closeAndReopenDoc(CursorList<com.jacob.com.Dispatch> cursors, Cursor<com.jacob.com.Dispatch> currentCursor)
This default implementation just returns currentCursor
, without any
closing/reopening. If you need to actually close/reopen the document (as a means of
optimising performance), override this method.
Implementation of closing/reopening the MS Word document.
closeAndReopenDoc
in interface WordHelper<com.jacob.com.Dispatch>
closeAndReopenDoc
in class AbstractWordWriter<com.jacob.com.Dispatch>
public java.util.Map<CaptionKind,java.util.List<Caption<com.jacob.com.Dispatch>>> collectCaptionParagraphsAndFixLabelsAlsoInTOCs()
Implementation note: In earlier versions, tried with GetCrossReferenceItems on document, but that was not reliable, so now doing manual house-keeping to achieve predictable results.
public Range<com.jacob.com.Dispatch> createRange(com.jacob.com.Dispatch object)
public final WordPatternFinder<com.jacob.com.Dispatch> createPatternFinder(java.lang.String msPattern)
public void clearUndoCache()
AbstractWordWriter
This default implementation does nothing.
clearUndoCache
in interface WordHelper<com.jacob.com.Dispatch>
clearUndoCache
in class AbstractWordWriter<com.jacob.com.Dispatch>
public Range<com.jacob.com.Dispatch> getDocumentAsRange()
public Range<com.jacob.com.Dispatch> duplicateRange(Range<com.jacob.com.Dispatch> range)
WordHelper
public void prependText(Range<com.jacob.com.Dispatch> range, java.lang.String newText)
WordHelper
public int getRangeParagraphOutlineLevel(Range<com.jacob.com.Dispatch> range, int paraIdx)
public java.lang.String appendRawTextInNewParagraphWithStyle(Range<com.jacob.com.Dispatch> range, java.lang.String newText, Style style)
public java.lang.String appendHtmlTextInNewParagraphWithStyle(Range<com.jacob.com.Dispatch> range, java.lang.String newMarkup, Style style)
public java.lang.String appendTextWithStyle(Range<com.jacob.com.Dispatch> range, java.lang.String newText, Style style)
public com.jacob.com.Dispatch insertFigureCaption(Range<com.jacob.com.Dispatch> range, int expectedSeqNum, java.lang.String text)
public void insertTableCaption(Range<com.jacob.com.Dispatch> range, int expectedSeqNum, java.lang.String text)
public void insertCaptionRef(Range<com.jacob.com.Dispatch> range, CaptionKind kind, int idx, boolean introBeforeCaption)
tabNumber
at the start of
insertPointRange
.
This will fail with exception if caption not found.
introBeforeCaption
- TODOpublic void insertFigure(Range<com.jacob.com.Dispatch> range, java.io.File pic)
WordHelper
range
includes any potential text within a paragraph. The method will
overwrite that text with the figure from pic
, and resulting range spans to the
start of the paragraph following the inserted pic
.public int insertTable(Range<com.jacob.com.Dispatch> range, PropertiesDoc doc, Style tabhead, boolean addBookmarks)
Returns expanded range to the end of the table. We do not collapse original range here, as we assume the caption will need to be inserted before the table.
public java.lang.String getRangeParagraphStyleName(Range<com.jacob.com.Dispatch> range, int paraIdx)
public int getRangeParagraphCount(Range<com.jacob.com.Dispatch> range)
public void prependNewLine(Range<com.jacob.com.Dispatch> range)
public void appendNewLine(Range<com.jacob.com.Dispatch> range)
public java.lang.String appendText(Range<com.jacob.com.Dispatch> range, java.lang.String newText)
public java.lang.String appendTextInNewParagraph(Range<com.jacob.com.Dispatch> range, java.lang.String newText)
public boolean isRangeWithTable(com.jacob.com.Dispatch range)
public void collapseRangeToEnd(Range<com.jacob.com.Dispatch> range)
public void collapseRangeToStart(Range<com.jacob.com.Dispatch> range)
public void moveStartChar(Range<com.jacob.com.Dispatch> range, int count)
public boolean applyCloseReopen()
WordWriter
public java.util.Set<java.lang.String> getSupportedFormats()
Writer
Copyright 2009-2016 Tatjana (Tanja) Kostic