https://bz.apache.org/bugzilla/show_bug.cgi?id=57593

--- Comment #18 from Vasili <[email protected]> ---

I think, the most sense for us will be maximum backward compatibility, i.e. the
old factory methods should remain in-place working as before with 
additional functionality for the default password (the issue described) in the
catch block of EncryptedDocumentException .
Exactly what your have proposed in your overloaded implementation.
WorkbookFactory.create(fis, password) might be a separate method.
I'm working on something else right now and will move to the wrapper for this
issue later, and I might comment with my wrapper 
implementation later - if you will not implement it earlier. Also, I haven't
looked deeply into the differences between HSSF and XSSF, so may be mistaken in
something. 
I guess, the input stream might be reopened in the catch block while the first
stream should be closed (depending on the buffer, it's resetting and how the
first call uses the stream).
So, the usage which gives the least number of headaches (at least for us) is
something like the following (not tested completely!), backward compatible:


Workbook wb;
try{
   wb = WorkbookFactory.create(fis);
}catch (EncryptedDocumentException e) {
   POIFSFileSystem fs = new POIFSFileSystem(fis);
   EncryptionInfo info = new EncryptionInfo(fs);
   Decryptor d = Decryptor.getInstance(info);
   if(!d.verifyPassword("VelvetSweatshop"))
    throw new Exception("Please use WorkbookFactory.create(file, password)
method and supply password"); 
   InputStream decryptedDataStream = d.getDataStream(fs);

   OPCPackage pkg = OPCPackage.open(decryptedDataStream);
   wb = new XSSFWorkbook(pkg);
}

An additional method is to be implemented:
org.apache.poi.ss.usermodel.WorkbookFactory.create(InputStream is, String
password) - to supply additional password
(it will not break the old code since it is additional functionality that had
not been assumed before - to supply the password other from the default)

This is my current understanding (before looking into this more deeply)

Thanks!

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to