/** Auslesen der verwendeten Felder im Dokument (in Verwendungsreihenfolge, nur einmal je SchlĂŒssel). Das geht leider
* nur ĂŒber Word (benutzt JCOM)
* @param inBT Die Datei
* @param convert Ersetzt die Eingabedatei durch ein PDF
* @param inOutImageBookmarks zu befĂŒllende Liste von Image-Bookmarks
* @param inOutNonImageBookmarks zu befĂŒllende Liste von Nicht-Image-Bookmarks
* @return Reihenfolgetreue Liste von Wertepaaren in Form von String-Arrays der LĂ€nge 2.
*/
private ArrayList<String[]> getWordDocPropertyFields( final BinaryTransfer inBT, boolean convert, ArrayList<String> mergeFields, ArrayList<String> inOutImageBookmarks, ArrayList<String> inOutNonImageBookmarks ) throws Exception
{
String LOG_PREFIX = ".getWordDocPropertyFields() ";
Log.log( getClass(), 6, LOG_PREFIX + "Reading Fields in Word Document!" );
final File docfile = inBT.getFile();
ArrayList<String[]> vpList = new ArrayList<String[]>();
HashMap<String, String> valueMap = new HashMap<String, String>();
// Word öffnen
boolean success = false;
File replacedDocfile = null;
// try
// {
ComApplication app = ComApplication.getInstance( properties, ComApplication.WORD_APPLICATION );
try
{
ComObject wdApp = app.getComObject(); //ComObject.getInstance( properties, "Word.Application" );
wdApp.put( "Visible", new Boolean( true ) ); // Word unsichtbar
ComObject wdDocuments = (ComObject) wdApp.get( "Documents" );
// Dokument öffnen
Object[] arglist1 = new Object[1];
arglist1[0] = docfile.getAbsolutePath();
ComObject wdDocument = (ComObject) wdDocuments.method( "Open", arglist1 );
// Neue Variante
ComObject wdSections = (ComObject) wdDocument.get( "Sections" );
Integer wdSectionCount = (Integer) wdSections.get( "Count" );
HashSet<Integer> doneShapeIDs = new HashSet<Integer>(); //Marker, ob bereits verarbeitet
for( int sec = 1; sec <= wdSectionCount; sec++ )
{
try
{
ComObject section = (ComObject) wdSections.method( "item", new Object[] { new Integer( sec ) } );
Log.log( getClass(), 7, LOG_PREFIX + "got Section: " + sec );
ComObject wdHeaders = (ComObject) section.get( "Headers" );
gotInfosFromHeadersFooters( wdHeaders, vpList, valueMap, mergeFields, inOutImageBookmarks, inOutNonImageBookmarks, "Section: " + sec + ", Header: ", doneShapeIDs );
ComObject wdFooters = (ComObject) section.get( "Footers" );
gotInfosFromHeadersFooters( wdFooters, vpList, valueMap, mergeFields, inOutImageBookmarks, inOutNonImageBookmarks, "Section: " + sec + ", Footer: ", doneShapeIDs );
}
catch( Exception e )
{
Log.log( getClass(), 7, LOG_PREFIX + "ERROR getting Section: " + sec, e );
}
}
ComObject storyranges = (ComObject) wdDocument.get( "StoryRanges" );
for( int i = 1; i <= 17; i++ )
{
String reference = "Story Range: " + getTextForStoryRangeNumber( i );
try
{
ComObject range = (ComObject) storyranges.method( "item", new Object[] { new Integer( i ) } ); // ggf. Exception = normal!
Log.log( getClass(), 7, LOG_PREFIX + "got " + reference );
int rangeCount = 1;
while( range != null )
{
getInfosFromRange( range, vpList, valueMap, mergeFields, inOutImageBookmarks, inOutNonImageBookmarks,
reference + ", Range: " + rangeCount++ );
range = (ComObject) range.get( "NextStoryRange" );//StoryRanges sind listenartig bei Autoformen (Checkboxen...), i = 5
}
}
catch( Exception e )
{
Log.log( getClass(), 7, LOG_PREFIX + "ERROR getting " + reference, e );
}
}
Log.log( getClass(), 6, LOG_PREFIX + "Felder gelesen!" );
success = true;
if( convert )
{
replacedDocfile = convertToPDF( docfile, wdDocument );
}
}
finally
{
final long timeout = Long.parseLong( this.properties.getProperty( PARAM_KILL_CLOSING_OFFICE_TIMEOUT, "10000" ) );
app.closeApplication( success, timeout );
}
if( replacedDocfile != null )
{
inBT.setFile( replacedDocfile, true );
inBT.isConverted = true;
}
// }
// catch( Throwable e )
// {
// // Log.error( getClass(), LOG_PREFIX + e.getClass().getName() + " while ... :" + e.toString() );
// Log.error( getClass(), LOG_PREFIX + "while ... : ", e );
// }
return vpList;
}