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.
We split the processing into two steps:
Modifier and Type | Class and Description |
---|---|
(package private) static class |
DocWordWriter.FillCellKind |
WordHelper.PostProcessor
Modifier and Type | Field and Description |
---|---|
private OptimOptions |
_initialOptions |
private static org.apache.log4j.Logger |
_logger |
private OptimOptions |
_optimisedOptions |
private com.jacob.com.Dispatch |
_wordApp |
private com.jacob.com.Dispatch |
_wordDoc |
static java.util.List<java.lang.String> |
FILE_EXTENSIONS |
(package private) static DocWordWriter.FillCellKind |
FILL_CELL_METHOD |
private static com.jacob.com.Variant |
msoPropertyTypeString |
static boolean |
ORIG_CREATE_TABLE |
private static com.jacob.com.Variant |
wdAutoFitFixed |
private static com.jacob.com.Variant |
wdCaptionFigure |
private static com.jacob.com.Variant |
wdCaptionPositionAbove |
private static com.jacob.com.Variant |
wdCaptionPositionBelow |
private static com.jacob.com.Variant |
wdCaptionTable |
private static com.jacob.com.Variant |
wdCollapseEnd |
private static com.jacob.com.Variant |
wdCollapseStart |
private static com.jacob.com.Variant |
wdFormatSurroundingFormattingWithEmphasis |
private static com.jacob.com.Variant |
wdLineStyleSingle |
private static com.jacob.com.Variant |
wdOnlyLabelAndNumber |
private static com.jacob.com.Variant |
wdParagraph |
private static com.jacob.com.Variant |
wdPreferredWidthPercent |
private static com.jacob.com.Variant |
wdPreferredWidthPoints |
private static com.jacob.com.Variant |
wdSeparateByCommas |
private static com.jacob.com.Variant |
wdTexture10Percent |
private static com.jacob.com.Variant |
wdTexture25Percent |
private static com.jacob.com.Variant |
wdWord8TableBehavior |
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).
|
private static void |
applyShaddingToRow(com.jacob.com.Dispatch row,
com.jacob.com.Variant shadingLevel) |
static java.lang.String |
asCsv(PropertiesDoc doc,
java.lang.String cellSep) |
private void |
backspaceLast(Range<com.jacob.com.Dispatch> range) |
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) |
private void |
collapseRangeToStart(Range<com.jacob.com.Dispatch> range) |
java.util.Map<Caption.CaptionKind,java.util.List<Caption<com.jacob.com.Dispatch>>> |
collectCaptions() |
WordPatternFinder<com.jacob.com.Dispatch> |
createPatternFinder() |
Range<com.jacob.com.Dispatch> |
createRange(com.jacob.com.Dispatch object) |
private Range<com.jacob.com.Dispatch> |
createRangeFromRangeOf(com.jacob.com.Dispatch obj)
Wraps
obj 's "Range" property into our Range. |
private static com.jacob.com.Dispatch |
createTable(Range<com.jacob.com.Dispatch> range,
int numColumns,
int numRows) |
private static com.jacob.com.Dispatch |
createTable(Range<com.jacob.com.Dispatch> range,
PropertiesDoc doc) |
void |
createWordApp()
Where applicable, launches (and caches) the MS Word application.
|
private int |
doInsertTable(Range<com.jacob.com.Dispatch> range,
PropertiesDoc doc,
Style tabhead) |
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).
|
(package private) void |
fillCellWithHtml(com.jacob.com.Dispatch table,
int i,
int j,
boolean isFormatted,
java.lang.String val,
Style style) |
private void |
fillValues(com.jacob.com.Dispatch table,
com.jacob.com.Dispatch app,
PropertiesDoc doc) |
private void |
formatTable(com.jacob.com.Dispatch table,
PropertiesDoc doc,
Style tabhead,
org.apache.log4j.Level level) |
java.util.Map<java.lang.String,java.lang.String> |
getCustomDocProperties() |
Range<com.jacob.com.Dispatch> |
getDocumentAsRange() |
private com.jacob.com.Dispatch |
getDocumentContent()
Returns Word range.
|
java.util.Map<java.lang.String,java.lang.String> |
getExistingStyleNames()
Returns names of existing styles.
|
private Range<com.jacob.com.Dispatch> |
getFirstTableAsRange(com.jacob.com.Dispatch container) |
private com.jacob.com.EnumVariant |
getIterator(com.jacob.com.Dispatch container,
java.lang.String collectionName) |
private com.jacob.com.Dispatch |
getParagraph(com.jacob.com.Dispatch range,
int paraIdx) |
private java.lang.String |
getParagraphStyleName(com.jacob.com.Dispatch paragraph) |
private com.jacob.com.Dispatch |
getRangeOf(com.jacob.com.Dispatch obj) |
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) |
private com.jacob.com.Dispatch |
getSelection(com.jacob.com.Dispatch app) |
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.
|
private static void |
insertCaption(Range<com.jacob.com.Dispatch> range,
com.jacob.com.Variant label,
com.jacob.com.Variant position,
java.lang.String text,
java.lang.String logMsg) |
private void |
insertCaptionRef(Range<com.jacob.com.Dispatch> range,
com.jacob.com.Variant refType,
int idx) |
void |
insertFigure(Range<com.jacob.com.Dispatch> range,
java.io.File pic) |
void |
insertFigureCaption(Range<com.jacob.com.Dispatch> range,
java.lang.String text,
java.lang.String logMsg) |
void |
insertFigureRef(Range<com.jacob.com.Dispatch> insertPointRange,
int figNumber) |
int |
insertTable(Range<com.jacob.com.Dispatch> range,
PropertiesDoc doc,
Style tabhead) |
void |
insertTableCaption(Range<com.jacob.com.Dispatch> range,
java.lang.String text,
java.lang.String logMsg) |
void |
insertTableRef(Range<com.jacob.com.Dispatch> insertPointRange,
int tabNumber) |
boolean |
isRangeWithTable(com.jacob.com.Dispatch range) |
private static void |
mergeCells(com.jacob.com.Dispatch row) |
void |
openDoc()
Creates (and caches) the MS Word document.
|
private static void |
pasteFromClipboard(com.jacob.com.Dispatch range) |
private static void |
pasteHtmlFromClipboard(com.jacob.com.Dispatch range) |
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.
|
private void |
select(com.jacob.com.Dispatch obj) |
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.
|
private void |
setRangeStyle(com.jacob.com.Dispatch range,
Style style) |
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, initCursorsFromPlaceholders, isInTOC, pointForPerc, scanAndPostprocess, toString, write, writeAbbrTable, writeClass, writeDataIndex, writeDiagram, writeFcTable, writeLnMapPackage, writePackage, writePresCondTable, writeProperties, writeSclEnum, writeTrgOpTable
getDocumentMetadata
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getDocumentMetadata
private static final org.apache.log4j.Logger _logger
private com.jacob.com.Dispatch _wordApp
private com.jacob.com.Dispatch _wordDoc
private static final com.jacob.com.Variant wdFormatSurroundingFormattingWithEmphasis
public static final boolean ORIG_CREATE_TABLE
private static final com.jacob.com.Variant wdWord8TableBehavior
private static final com.jacob.com.Variant wdAutoFitFixed
private static final com.jacob.com.Variant wdSeparateByCommas
static final DocWordWriter.FillCellKind FILL_CELL_METHOD
private static final com.jacob.com.Variant wdLineStyleSingle
private static final com.jacob.com.Variant wdPreferredWidthPercent
private static final com.jacob.com.Variant wdPreferredWidthPoints
private static final com.jacob.com.Variant wdTexture10Percent
private static final com.jacob.com.Variant wdTexture25Percent
private OptimOptions _initialOptions
private OptimOptions _optimisedOptions
private static final com.jacob.com.Variant msoPropertyTypeString
private static final com.jacob.com.Variant wdCaptionFigure
private static final com.jacob.com.Variant wdCaptionTable
private static final com.jacob.com.Variant wdCaptionPositionAbove
private static final com.jacob.com.Variant wdCaptionPositionBelow
private static final com.jacob.com.Variant wdParagraph
private static final com.jacob.com.Variant wdOnlyLabelAndNumber
private static final com.jacob.com.Variant wdCollapseStart
private static final com.jacob.com.Variant wdCollapseEnd
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.private com.jacob.com.EnumVariant getIterator(com.jacob.com.Dispatch container, java.lang.String collectionName)
private com.jacob.com.Dispatch getDocumentContent()
private Range<com.jacob.com.Dispatch> createRangeFromRangeOf(com.jacob.com.Dispatch obj)
obj
's "Range" property into our Range.private com.jacob.com.Dispatch getRangeOf(com.jacob.com.Dispatch obj)
private void select(com.jacob.com.Dispatch obj)
private static void pasteFromClipboard(com.jacob.com.Dispatch range) throws ApplicationException
ApplicationException
private static void pasteHtmlFromClipboard(com.jacob.com.Dispatch range) throws ApplicationException
ApplicationException
private void setRangeStyle(com.jacob.com.Dispatch range, Style style)
private int doInsertTable(Range<com.jacob.com.Dispatch> range, PropertiesDoc doc, Style tabhead)
private static com.jacob.com.Dispatch createTable(Range<com.jacob.com.Dispatch> range, int numColumns, int numRows)
private static com.jacob.com.Dispatch createTable(Range<com.jacob.com.Dispatch> range, PropertiesDoc doc)
public static java.lang.String asCsv(PropertiesDoc doc, java.lang.String cellSep)
private com.jacob.com.Dispatch getSelection(com.jacob.com.Dispatch app)
private void fillValues(com.jacob.com.Dispatch table, com.jacob.com.Dispatch app, PropertiesDoc doc)
private void formatTable(com.jacob.com.Dispatch table, PropertiesDoc doc, Style tabhead, org.apache.log4j.Level level)
private static void mergeCells(com.jacob.com.Dispatch row)
private static void applyShaddingToRow(com.jacob.com.Dispatch row, com.jacob.com.Variant shadingLevel)
void fillCellWithHtml(com.jacob.com.Dispatch table, int i, int j, boolean isFormatted, java.lang.String val, Style style)
private void backspaceLast(Range<com.jacob.com.Dispatch> range)
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()
WordHelper
public java.lang.String getWordAppVersion()
WordHelper
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 java.util.Map<java.lang.String,java.lang.String> getExistingStyleNames()
WordHelper
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<Caption.CaptionKind,java.util.List<Caption<com.jacob.com.Dispatch>>> collectCaptions()
We have tried with GetCrossReferenceItems on document, but that was not reliable.
public Range<com.jacob.com.Dispatch> createRange(com.jacob.com.Dispatch object)
public final WordPatternFinder<com.jacob.com.Dispatch> createPatternFinder()
public void clearUndoCache()
This default implementation does nothing.
Scans the whole document to search for placeholders, and records their ranges and captions counts for figures and tables.
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 void insertFigureCaption(Range<com.jacob.com.Dispatch> range, java.lang.String text, java.lang.String logMsg)
public void insertTableCaption(Range<com.jacob.com.Dispatch> range, java.lang.String text, java.lang.String logMsg)
private static void insertCaption(Range<com.jacob.com.Dispatch> range, com.jacob.com.Variant label, com.jacob.com.Variant position, java.lang.String text, java.lang.String logMsg)
public void insertFigureRef(Range<com.jacob.com.Dispatch> insertPointRange, int figNumber)
public void insertTableRef(Range<com.jacob.com.Dispatch> insertPointRange, int tabNumber)
private void insertCaptionRef(Range<com.jacob.com.Dispatch> range, com.jacob.com.Variant refType, int idx)
public void insertFigure(Range<com.jacob.com.Dispatch> range, java.io.File pic)
public int insertTable(Range<com.jacob.com.Dispatch> range, PropertiesDoc doc, Style tabhead)
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)
private com.jacob.com.Dispatch getParagraph(com.jacob.com.Dispatch range, int paraIdx)
private java.lang.String getParagraphStyleName(com.jacob.com.Dispatch paragraph)
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 appendTextInNewParagraph(Range<com.jacob.com.Dispatch> range, java.lang.String newText)
public java.lang.String appendText(Range<com.jacob.com.Dispatch> range, java.lang.String newText)
public boolean isRangeWithTable(com.jacob.com.Dispatch range)
private Range<com.jacob.com.Dispatch> getFirstTableAsRange(com.jacob.com.Dispatch container)
public void collapseRangeToEnd(Range<com.jacob.com.Dispatch> range)
private void collapseRangeToStart(Range<com.jacob.com.Dispatch> range)
public boolean applyCloseReopen()
WordWriter
public java.util.Set<java.lang.String> getSupportedFormats()
Writer
Copyright 2009-2015 Tatjana (Tanja) Kostic