fragkopoulos / jodconverter

Automatically exported from code.google.com/p/jodconverter
0 stars 0 forks source link

Raise specific exception for password protected documents #51

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
The document being password protected is one of the most frequent causes of
conversion failures. And it can be a recoverable condition, because you
could ask the user to enter the password.

However the error message is currently a generic "could not load document"
one raised whenever loadComponentFromURL returns null.

It should be possible to identify the specific password protected case
using an InteractionHandler

http://api.openoffice.org/docs/common/ref/com/sun/star/task/XInteractionHandler.
html

Original issue reported on code.google.com by mirko.na...@gmail.com on 24 Jul 2009 at 10:04

GoogleCodeExporter commented 8 years ago
It is /possible/ to do this without changing JodConverter, but it's rather 
inconvenient to do so.
This gets an interaction handler used:
            String inputExtension = FilenameUtils.getExtension( inputFile.getName() );
            DocumentFormat outputFormat = converter.getFormatRegistry().getFormatByExtension( destinationFormat );
            StandardConversionTask conversionTask = new StandardConversionTask( inputFile, outputFile, outputFormat );

            Map<String, Object> loadProperties = new HashMap<String, Object>();
            loadProperties.put( "Hidden", true );
            loadProperties.put( "ReadOnly", true );
            // loadProperties.put("UpdateDocMode", UpdateDocMode.QUIET_UPDATE);
            InteractionHandler handler = new InteractionHandler();
            loadProperties.put( "InteractionHandler", handler );

            conversionTask.setDefaultLoadProperties( loadProperties );
            DocumentFormat inputFormat = converter.getFormatRegistry().getFormatByExtension( inputExtension );
            conversionTask.setInputFormat( inputFormat );

            ConversionResult result = new ConversionResult();
            result.setCorrelationId( parameters.getCorrelationId() );
            result.setDocumentID( parameters.getDocumentID() );
            result.setSucceeded( true );

            try {
                webappContext.getOfficeManager().execute( conversionTask );
                // converter.convert(inputFile, outputFile );
            }

And I've attached the InteractionHandler I'm using.

Original comment by jim.tal...@groupgti.com on 8 Nov 2011 at 10:22

Attachments: